Test Post, Please ignore

This is just a test post.

Send Reddcoins

The Formatter:Off Command in PHPStorm 7.1

before and after auto formatting

The auto formatting breaks my nice alignment of parameters :(

I spent a fair bit of time trying to disable PHPStorm’s auto-formatter for small sections of my code. I finally managed, but it was a bit confusing, so I figured I’d do a quick how-to so that others can easily utilize PHPStorm’s awesome new formatter off command.

First, we’ll explain the problem. Auto-formatting is a great tool. It allows me to quickly format code to PSR-2 or whatever standard I have to use for a given project. I instinctively run the formatter every 20 minutes or so. This is great except for the cases where I need some custom formatting. In the depicted example, my type hinted parameters take up too much space and need to be broken into their own lines. Unfortunately, the formatter doesn’t let me keep the alignment by default.

Finally, we can rejoice!

Finally, we can rejoice!

A bit of searching led me to the jetbrains docs, which to my delight said you could skip a region when reformatting simply by adding a comment and then “manually type the marker specified in the Formatter off field of General page.” To my confusion and dismay, this option didn’t exist.

 Making it Work

First, you need to update to PHPStorm 7.1 or later. This finally occurred to me after trying everything at my disposal. As of this writing, 7.1 is an EAP release, but it should be public quite soon. After 7.1 downloaded, I opened up Settings->Code Style->General and was happy to see the formatter on/off commands present. From there you simply check the box to enable formatter commands, and add two comments. One to disable auto-formatting and another to re-enable it. It’s as simple as that, once you have the right version.

But Now My Code is Ugly!

So, the reason you were so eager to use these auto-formatting commands was to make your code cleaner and more readable. Now that you have to litter it with format commands it kind of defeats the purpose. Fear not, young grasshopper.

Live Templates, and Formatting the Format Commands


Did you even notice the formatting code? Its all the way on the right.

After noticing these comments were pretty ugly, I fiddled around a bit more and came up with a satisfactory solution. First, I tried tabbing the comments way over to the right. But, autoformat moved them back to the left. Since you can’t disable the formatter on the disable formatter comments themselves, you’ll need to use this little trick to get them out of the way. Luckily the command is quite flexible. So what I ended up doing is starting my comment on the far left, then tabbing over until the format commands were past my right margin. It may not be to everyone’s liking but it suits me quite nicely.

live templates

Here’s where you can create live templates, incase you didn’t know already.

But wouldn’t it be annoying to add 80-120 spaces every time you need to disable the formatter, you might be asking? Of course it would, and that’s where live templates come in. Open up the settings, search for live templates, click on the green plus, and add a live template for these guys. I aliased mine as `f:`.

Now, whenever I need some custom formatting, I just type f:, then TAB, and PHPStorm graciously generates the formatter commands for me, pre-formatted to my liking.

That’s it for today! Hope it helped.

Flewent 1.1.0 Released

Toward a Dictionary Based Flewent

Today Flewent got a much needed update. There were some issues with the translation service it uses, so I worked with them to arrive at a solution that meets everyone’s needs. The end result is a major change to the way Flewent works. Here is a brief overview of the changes:

Your Own Dictionary

Flewent will now automatically create a dictionary for you and use it for translations. Every time you view a new page, Flewent will translate up to 15 words using a translation service. We had to change the way it uses the translation service, so it will now take longer (about 15 seconds) to receive the translated words.

Once it gets them, it translates them in the page like normal, except now it will save them to your dictionary for later. If you don’t like the way a word got translated, you can fix it in your dictionary by clicking “edit”. You can also search your dictionary at any time and remove or edit existing words, as well as add your own words.

Fast and Slow Translations

With the new update, Flewent will first check your dictionary for all the words it plans to translate. It will translate the words it finds there almost immediately (50-200 milliseconds on my computer). That is much faster than before, since it doesn’t need to use the translation service at all.

The other translations will be slower, however. Since flewent was trying to translate the words as fast as possible before, it caused issues for the translation service. I have been working closely with them to slow down the translations a little bit so that they can continue to support us. Now, it will take about 15 seconds for the remaining translations to be applied. In the long-run your dictionary will grow and eventually it won’t need to use the translation service any more. Once that happens translations will be faster than ever and will work offline.

Turn Off Highlighting

As requested by a user, the ability to turn off highlighting was added. I know that having your beautiful web spotted with bright yellow can be annoying. That’s why I added an option to turn it off in the settings page. The default color was also made lighter so that it is easier to look at for everyone.

Fewer Bugs and Better Results

The old method of translating many words at once was more error prone than the new one. Now, the translation service should be more accurate since it is translating words one at a time. You have the ability to improve the results yourself by managing your dictionary.

That’s all most people will need to know about this update. If you’re interested in technical details or future plans, keep reading. Otherwise, enjoy flewent, and please let me know (via comments or email) about any issues you experience.

Future Plans

The most important plan for the future is to let you control the size of your dictionary. Right now, your dictionary will be automatically filled until it reaches 10,000 words. I would like to let you control this number, so that you can keep a smaller (or larger) dictionary if you like.

Next, I plan to let you choose how fast the dictionary fills up. Right now every page load adds 15 words to the dictionary. This is good if you want to fill up your dictionary quickly. But, if you want to keep a close eye on your dictionary the current implementation isn’t optimal. Soon, flewent will let you decide how fast to build your dictionary and once it’s perfect you can stop building it all together.

With these improvements, I will create dictionary only mode. This will allow you to translate all the words on a page that are found in your dictionary.

Default 404 Images with Apache’s mod_rewrite

My relationship with Apache config files is analogous to a woman in an abusive relationship. Sure, it beats me when I ask it to do me a favor, but for some incoherent reason I still love it. It works hard every day for me, and deep down I know it loves me too, it just doesn’t show it all the time.

Today’s task was getting it to serve up a default image when a non-existent one was requested. This happens a lot on my local server, since the development team (usually) uses a remote shared development database, but image uploads happen locally. I grew tired of having broken images on my dev server, and they look really bad in product demos. Additionally, although I hope it never comes up, its nice to have a fallback for end users.

Initially, I started with something like this:

#Warning: This didn't work at all for me.
<VirtualHost *:80>
  #[...] stuff
  RewriteEngine on
  RewriteCond %{REQUEST_URI} \.jpg$
  RewriteCond %{REQUEST_URI} !-f
  RewriteRule ^.*$ /404_image.jpg [L]
  #[...] other stuff, including <Directory>

Theoretically, that says “if it’s a jpg and the file doesn’t exist, rewrite the url to our default 404 image.” It didn’t work. The end result was every image got rewritten to the 404 image, even the ones that did exist. So, I looked into debugging url rewrites.

There’s a lot of good info in that link, but all I needed was to enable the rewrite log. So, I added

  #4-9 are equal in practice, but lets make it clear we want to see everything
  RewriteLogLevel 9 
  RewriteLog /tmp/rewrite.log

After a quick `cat` (dump) of the log file, I noticed this:

(4) RewriteCond: input='/logo.jpg' pattern='!-f' => matched

Although /logo.jpg did exist, apache was saying it didn’t exist. In the literal sense, the expression `not file exists` was returning true. Apache was being a jerk, and I didn’t like it. After wrestling with apache for a while, reading the docs, trying different things, and googling away, it eventually came to my attention that maybe apache was using ‘/logo.jpg’ as a literal full path, instead of a path relative to the virtual hosts’s document root. It appears that was indeed the problem. The solution was to run the `!-f` test against a concatentation of the document root and the requiest uri, like this: %{DOCUMENT_ROOT}%{REQUEST_URI}

Here is what I ended up using both locally and on the remote server:

<VirtualHost *:80>
  #[...] stuff
  RewriteEngine on
  RewriteCond %{REQUEST_URI} \.jpg$
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
  # You probably don't need this line, read the note below for more info
  RewriteCond %{DOCUMENT_ROOT}/..%{REQUEST_URI} !-f
  RewriteRule ^.*$ /404_image.jpg [L]
  #[...] other stuff, including <Directory>

Note: The commented line above there is a bit strange. I used it in my own case because we are storing and serving images from a directory above the document root. The purpose of this is to keep our user uploaded content separate from our code, and to also allow us to restrict content to logged in users. This is just a development set-up for now, we will probably get images on a completely separate server before launch, but I included it just to show that it does work for anyone doing something similar.

I should also note that for my co-worker, the initial attempt worked correctly. He’s using a mac and i use linux. I assume the difference comes from another configuration option, but I couldn’t find it. In any case, the final solution worked on my computer and on the server.

Hope this helps anyone doing something similar.

A Fun Video About What Many Schools Don’t Teach.

Today I stumbled upon a great video of programmers talking about programming.

Its not technical by any means. Instead it’s a light hearted, upbeat, short video intended to inspire people from all backgrounds to dig into the (sometimes) wonderful world of programming.

Check it out here:

How some guy (Omar) learned to like Javascript

At my day job, we’re getting ready to gear up and write a new web application from scratch. Writing a new application from the ground up is an exciting process, but it’s also a time to collect yourself, look at what you’ve been doing wrong in the past, spend some extra time reading blogs, and figure out the best way to approach this important phase of an important task.

Tonight I was browsing around some programming sites and found a very awesome blog post by “Omar Gonzales” titled “How I Ended Up Enjoying Javascript”.

In his post, Gonzales gives an eloquent and detailed overview of the Javascript tools and frameworks he ended up using to make his JS development more pleasant. I consider it an essential read for anyone who isn’t quite up to speed with the rapidly developing world of Javascript frameworks. Some of the tools he chose were ones I was aware of, like requirejs, which we wished we would have used at the beginning of a previous project.

Other things, like AngularJS were new to me. I have heard about Backbone.js and Knockout.js in the past, but haven’t gotten real experience with either. A real application framework was missing from my last project and near the end, I realized that was a big oversight. I was planning to dig into backbone and knockout in the next week or so, but am now leaning towards AngularJS based on this analysis.

Whatever your experience with Javascript tools and frameworks, I think you’ll find this post useful in choosing your own Javascript tool set.

The world’s first 3-d printed guitar?

I really like 3-D printing and guitars, and according to Business Week, the first 3-D printed guitar has been created.

Making it even cooler, it seems like the musical qualities of the guitar were pretty sound (okay, pun intended).

[...] chances were the guitar would break under the 200 pounds of string pressure that comes with tightening the strings via a tuning machine. [...] But, no. It worked, and it sounds pretty good.

I, for one, can’t wait to be able to custom print 3-D guitars, or possibly other new and strange instruments.

Head on over to the whole article to check out the photo and learn more about its production.

Google Releases Java to Objective C Code Translator for Mobile Apps

In September 2012, Google released “J2ObjC: A Java to iOS Objective-C translator,” which will enable mobile application developers to write a majority of their application’s code in java, and have the business logic and data access layers translated into objective-c.

While this isn’t exactly a one click solution to convert Andriod apps to iOS, I am sure that it’s a welcome development to java developers who are trying to port their apps to Apple’s platform.

Check out the whole post on google’s open source blog, or view the project page on code.google.com

RSA Animate on Productivity and Motivation

This is an old but great video on the cognitive psychology of work motivation and how mentally engaging work and autonomy result in the highest levels of productivity. Check it out.