This is what’s wrong with programming

In addition to built-in coding assistance, PhpStorm provides code style check through integration with the PHP Code Sniffer tool, which validates your code for consistence with a coding standard of your choice. You can appoint one of the predefined coding standards or use your own previously defined coding standard with the root directory outside the default PHP Code Sniffer’s Standards directory. Moreover, you can share your custom coding style with your team fellows.

To use PHP Code Sniffer right from PhpStorm instead of from a command line, you need to register it in PhpStorm and configure it as a PhpStorm code inspection. Once installed and enabled in PhpStorm, the tool is available in any opened PHP file, so no steps are required from your side to launch it. The on-the-fly code check is activated upon every update in the file thus making it extremely easy to get rid of problems reported by PHP Code Sniffer.

Errors and warnings reported by PHP Code Sniffer on-the-fly are displayed as pop-up messages. When the tool is run in the batch mode, the errors and warnings are displayed in the Inspection tool window. Anyway, each message has the phpcs prefix to distinguish it from PhpStorm internal inspections.

On this page:

Prerequisites

  1. The PEAR package manager is installed on your machine.
  2. PHP Code Sniffer is installed on your machine. To check it, switch to the directory with thepear.bat file and run the following command: phpcs –versionIf the tool is available, you will get a message in the following format: PHP_CodeSniffer version <version> (stable) by Squiz Pty Ltd. (http://www.squiz.net)
  3. To have code checked against your own custom coding standard, create it. Store the rules and the ruleset.xml file that points to them in the coding standard root directory.

To register PHP Code Sniffer in PhpStorm
  1. Open the project settings, and click Code Sniffer under the PHP node.
  2. In the PHP Code Sniffer path text box, specify the location of the Code Sniffer executablephpcs.bat. Type the path manually or click the Browse button browseButton.png and select the path in the dialog box, that opens.To check that the specified path to phpcs.bat ensures interaction between PhpStorm and Code Sniffer, that is, the tool can be launched from PhpStorm and PhpStorm will receive problem reports from it, click the Validate button. This validation is equal to running the phpcs –versioncommand. If validation passes successfully, PhpStorm displays the information on the detected Code Sniffer version.

To specify advanced PHP Code Sniffer options

PhpStorm provides the ability to specify advanced PHP Code Sniffer options and thus fine tune the PHP Code Sniffer process behavior depending on the configuration of your computer and the rule sets used.

  1. Open the project settings, and click Code Sniffer under the PHP node.
  2. In the Maximum number of messages per file text box, set the upper limit for the total number of messages to be reported for a file. All the messages above this limit will be rejected and PhpStorm will display the following warning right in the code:
  3. In the Tool process timeout text box, specify how long you want PhpStorm to wait for a result from PHP Code Sniffer, whereupon the process is killed to prevent excessive CPU and memory usage.

To configure PHP Code Sniffer as a PhpStorm inspection
  1. Open the project settings, and click Inspections.
  2. On the Inspections page that opens, select the PHP Code Sniffer validation check box under the PHP node.
  3. On the right-hand pane of the page, configure the PHP Code Sniffer tool using the controls in theOptions area:
    1. From the Severity drop-down list, choose the severity degree for the Code Sniffer inspection. The selected value determines how serious the detected discrepancies will be treated by PhpStorm and presented in the inspection results.
    2. In the Coding standard drop-down list, appoint the coding style to check your code against. The list contains all the coding standards installed inside the main PHP_CodeSniffer directory structure.Use one of the predefined coding standards or choose Custom to appoint your own standard.
    3. Optionally, select the Ignore warnings check box to have only errors reported and suppress reporting warnings. This option is equal to the -n command line argument.

To appoint a custom coding style to use

You can have code checked against your own previously defined coding standard with the root directory outside the default PHP Code Sniffer’s Standards directory. This root directory should contain the rules themselves and the ruleset.xml file that points to them.

  1. Open the project settings, click Inspections. The Inspections page opens. Select the PHP Code Sniffer validation check box under the PHP node.
  2. From the Coding standard drop-down list, choose Custom.
  3. Click the Browse button browseButton.png.
  4. In the Custom Coding Standard dialog box that opens, specify the path to the root directory of your own coding standard in the Root directory. Type the path manually or click the Browse buttonbrowseButton.png and choose the relevant folder in the dialog that opens.

    Note

    The selected root directory should contain the ruleset.xml file that points to the rules.

To share a custom coding style with the team
  1. Put the root directory of your coding standard under the project root.
  2. Configure Code Sniffer as a PhpStorm inspection.
  3. Appoint your coding standard.
  4. At the top of the Inspections page, select the Share Profile check box.
  5. On the Version Control page of the Settings dialog box, put the root directory of your coding standard under version control.

To run Code Sniffer in the batch mode
  1. To run the inspection, choose Code | Inspect code on the main menu. Specify the inspection scope and profile.
  2. View the inspection results in the Inspection tool window. Errors and warnings reported by PHP Code Sniffer have the phpcs prefix to distinguish them from PhpStorm internal inspections.

Excluding files from inspection

When waiting for Code Sniffer response exceeds the limit specified in the Tool process timeoutfield on Code Sniffer page, PhpStorm suggests adding the file to the ignore list. This list is shown on the Code Sniffer page in the Ignored files area. For each file, PhpStorm displays its name and location.

  • To delete a file from the list and have Code Sniffer process it again, select the file and click theRemove file button delete.png.
  • To remove all the files from the list, click the Clean the list button close.png.

AutoHotKey alternative for Mac: KeyRemap4MacBook

Complex but powerful.

Don’t use it unless you’re prepared to fiddle with XML and read the docs. 

However, if you’re prepared to put in an hour you’ll reap the benefits – very useful.

Download it from:

https://pqrs.org/macosx/keyremap4macbook/index.html.en

These are handy:

Examples:

https://pqrs.org/macosx/keyremap4macbook/xml.html.en#examples

The Google Group:

https://groups.google.com/forum/#!forum/keyremap4macbook

A sample of how to do a key sequence:

https://raw.github.com/tekezo/Files/master/KeyRemap4MacBook/private.control_d_to_kill_line/private.xml

List of KeyCodes:

https://github.com/tekezo/KeyRemap4MacBook/blob/version_8.3.0/src/bridge/generator/keycode/data/KeyCode.data

List of ModifierFlags:

https://github.com/tekezo/KeyRemap4MacBook/blob/version_8.3.0/src/bridge/generator/keycode/data/ModifierFlag.data

Less handy (unless you want to plough through issues):

https://github.com/tekezo/KeyRemap4MacBook/issues

AutoHotKey alternative for Mac: KeyRemap4MacBook

Complex but powerful.

Don’t use it unless you’re prepared to fiddle with XML and read the docs. 

However, if you’re prepared to put in an hour you’ll reap the benefits – very useful.

Download it from:

https://pqrs.org/macosx/keyremap4macbook/index.html.en

and edit the private.xml using:

Preferences > Misc & Uninstall > Open private.xml

These are handy:

Examples:

https://pqrs.org/macosx/keyremap4macbook/xml.html.en#examples

The Google Group:

https://groups.google.com/forum/#!forum/keyremap4macbook

A sample of how to do a key sequence:

https://raw.github.com/tekezo/Files/master/KeyRemap4MacBook/private.control_d_to_kill_line/private.xml

List of KeyCodes:

https://github.com/tekezo/KeyRemap4MacBook/blob/version_8.3.0/src/bridge/generator/keycode/data/KeyCode.data

List of ModifierFlags:

https://github.com/tekezo/KeyRemap4MacBook/blob/version_8.3.0/src/bridge/generator/keycode/data/ModifierFlag.data

Less handy (unless you want to plough through issues):

https://github.com/tekezo/KeyRemap4MacBook/issues

E.g. to nudge cell contents to the next cell to the right, I use this (replaces Command-X, right cursor, Command-V):

<?xml version=”1.0″?>

<root>

<item>

<name>Excel: Quick Cut and Paste</name>

<identifier>private.excel_cut_paste</identifier>

<autogen>

__KeyToKey__

KeyCode::CURSOR_RIGHT, ModifierFlag::OPTION_L | ModifierFlag::SHIFT_L, 

KeyCode::X, ModifierFlag::COMMAND_L,

KeyCode::CURSOR_RIGHT,

KeyCode::V, ModifierFlag::COMMAND_L,

</autogen>

</item>

</root>

Don’t forget to:

– select your custom shortcut in Preferences > Change Key

– and add it to your Login items

 

What are all those gems that are installed/used by Rails

Wonder what all those gems are that you find being installed/used when you do:

rails new app

Here’s a breakdown (all gems can be found doing a search on http://rubygems.org/)

Using rake (10.0.4)

Ruby Make

http://rubygems.org/gems/rake

Using i18n (0.6.4)

Internationalization for Ruby

http://ruby-i18n.org

Installing minitest (4.7.4) 

minitest is a complete suite of testing facilities supporting TDD, BDD, mocking and benchmarking

http://rubygems.org/gems/minitest

Using multi_json (1.7.3) 

A gem to provide easy switching between different JSON backends, including Oj, Yajl, the JSON gem (with C-extensions), the pure-Ruby JSON gem, and OkJson.

http://rubygems.org/gems/multi_json

Using atomic (1.1.9) 

an Atomic class that guarantees atomic updates to its contained value

http://rubygems.org/gems/atomic

Using thread_safe (0.1.0) 

A collection of thread-safe versions of common core Ruby classes

http://rubydoc.info/gems/thread_safe/0.1.0/frames

Using tzinfo (0.3.37)

TZInfo is a Ruby library that uses the standard tz (Olson) database to provide daylight savings aware transformations between times in different time zones.

http://rubygems.org/gems/tzinfo

Using activesupport (4.0.0.rc1)

A toolkit of support libraries and Ruby core extensions extracted from the Rails framework. Rich support for multibyte strings, internationalization, time zones, and testing.

http://rubydoc.info/gems/activesupport/3.2.13/frames

Using builder (3.1.4) 

Builder provides a number of builder objects that make creating structured data simple to do. Currently the following builder objects are supported: * XML Markup * XML Events

http://rubygems.org/gems/builder

Using erubis (2.7.0) 

Erubis is an implementation of eRuby (Embedded Ruby), a templating system that embeds Ruby in a text document.

http://rubygems.org/gems/erubis

Using rack (1.5.2) 

Rack provides an interface for developing web applications.

http://rubygems.org/gems/rack

and

http://rack.rubyforge.org/doc/

Using rack-test (0.6.2) 

Tests

Using actionpack (4.0.0.rc1) 

Web apps on Rails

http://rubygems.org/gems/actionpack

Using mime-types (1.23) 

Mime-types

Using polyglot (0.3.3) 

Polyglot provides a registry of file types that can be loaded by calling its improved version of ‘require’. It also allows a Ruby module to register a loader for the file type associated with a filename extension. 

http://polyglot.rubyforge.org

Using treetop (1.4.12) 

A Ruby-based text parsing and interpretation DSL

Using mail (2.5.4) 

Ruby mail handler

Using actionmailer (4.0.0.rc1) 

Email on Rails

Using activemodel (4.0.0.rc1) 

Toolkit for building modelling frameworks like Active Record and Active Resource.

Using activerecord-deprecated_finders (1.0.2) 

Using arel (4.0.0) 

SQL AST (abstract syntax tree) manager for Ruby. It simplifies the generation of complex SQL queries.

Using activerecord (4.0.0.rc1) 

Databases on Rails. Build a persistent domain model by mapping database tables to Ruby classes.

Using bundler (1.3.5) 

Manage gems.

Installing coffee-script-source (1.6.2) 

Installing execjs (1.4.0) 

Installing coffee-script (2.2.0) 

Language that compiles into JavaScript.

http://coffeescript.org

Using thor (0.18.1) 

A scripting framework that replaces rake, sake, rubigen.

Using railties (4.0.0.rc1) 

see earlier post

Installing coffee-rails (4.0.0) 

CoffeeScript adapter.

Using hike (1.2.2) 

Finding files in a set of paths.

Installing jbuilder (1.0.2) 

Create JSON structures via a Builder-style DSL.

Installing jquery-rails (2.2.1) 

jQuery for Rails.

Installing json (1.8.0) 

JSON

Using tilt (1.4.1) 

Generic interface to multiple Ruby template engines

Using sprockets (2.10.0) 

Using sprockets-rails (2.0.0.rc4) 

Rack-based asset packaging system that concatenates and serves JavaScript, CoffeeScript, etc.

Using rails (4.0.0.rc1) 

should be pretty straightforward…!

Installing rdoc (3.12.2) 

docs

Installing sass (3.2.9) 

Installing sass-rails (4.0.0.rc1) 

Extension to CSS3

Installing sdoc (0.3.20) 

rdoc generator

Installing sqlite3 (1.3.7) 

SQLite interface

Installing turbolinks (1.1.1) 

Turbolinks makes following links in your web application faster (use with Rails Asset Pipeline). Similar to pjax (pjax = pushState + ajax). Does not require jQuery but works great with jQuery.

Installing uglifier (2.1.1) 

Ruby wrapper for UglifyJS JavaScript compressor

Your bundle is complete!

And so is this whirlwind tour!

Code syntax highlighting when using WordPress and MarsEdit

How to add code syntax highlighting when using WordPress and MarsEdit

1. Install this:
http://wordpress.org/extend/plugins/syntaxhighlighter/

2. Use Format > Customize to create a custom PRE tag class, e.g.

Other brushes:

http://basilsalad.com/how-to/syntax-highlighting-with-marsedit-on-wordpress/

Automatic Post Tagger

Not quite as awesome as an automatic post categoriser but still pretty handy:

http://wordpress.org/extend/plugins/automatic-post-tagger/