This is original posted on intridea blog.

I recently worked in a Rails project with Peter (@sporkd). The project is intended to be used as a sub-site, and should be served under sub-URI. After google, we ended up by setting config.assets.prefix and wrapped all routes in scope. The solution is simple and worked well. But soon, some weird bugs were found, and Peter was successfully isolated the problem to session (see demo sporkd/asset_prefix_test)

After several hours debugging, I finally found out the cause. To make a long story short, the routes configured in routes.rb should not start with config.assets.prefix, otherwise session save is skipped. The demo sporkd/asset_prefix_test can be fixed by simply setting config.assets.prefix to /one/assets. You also get a bonus by setting a unique prefix for assets, since it is easy to add expiration header for assets in web server.

# ^Xa to insert all matches
zle -C all-matches complete-word _generic
bindkey '^Xa' all-matches
zstyle ':completion:all-matches:*' old-matches only
zstyle ':completion:all-matches::::' completer _all_matches

UPDATE: The snippet above brings insert-completions to zsh. Thanks, Trevor Joynson, who has provided the solution in comment.

Command insert-completions (see man bash) is the feature I most miss in bash.

[insert-completions] Insert all completions of the text before point that would have been generated by possible-completions.

Its default binding is M-*, a.k.a, Alt-Shift-8 or Meta-Shift-8.

It is useful for simple batch operations, such as removing all git branches starting with feature/.

After I switched to zsh, I have been looking for a similar command, but for no results. However, I just discovered the zsh way to select multiple completions recently, using accept-and-hold (see man zshzle).

[accept-and-hold] Push the contents of the buffer on the buffer stack and execute it.

The default binding is M-a (a.k.a, Alt-a or Meta-a). If the command line has input content ls, M-a executes the line ls without clearing the input.

It seems unrelated. But if completion menu is activated and a menu item is selected (the simplest way is Tab twice), accept-and-hold accepts the current menu item without closing completing menu. So it is possible to select multiple items by navigating to wanted items, and type M-a to select them.

Jasmine is a behavior-driven development framework for testing JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM. And it has a clean, obvious syntax so that you can easily write tests.

It is very easy to integrate Jasmine into Rails, since the team provides the jasmine gem. The jasmine gem also supports assets pipeline, just prepend assets/ to file path. For example, app/assets/javascripts/application.js.coffee can be referred as assets/application.js in jasmine.yml src_files.

However, spec_files does not support assets pipeline, so the files in spec/javascripts cannot be written in CoffeeScript. But if spec/javascripts is appended to assets pipeline paths, the spec files can be added to src_files in jasmine.yml.

This post explains how to apply such trick, and how to integrate jasmine gem with guard-jasmine and travis.

I also created a demo repository, see its commits for integration steps.

When I implement time input feature for 19wu (an open source ticket sale system), I want to split the datetime into date and time parts, so JavaScript date picker and time picker can be used. This post introduces two methods I found.

Compound datetime input

composed_of utilizes assign_multiparameter_attributes trick like datetime_select, and fields_for mocks an association.

The github repository doitian/rails-compound-input-demo contains demos for both methods.

There are two TAB’s in Emacs, (kbd "TAB") (\t, [9]) and (kbd "<tab>") ([tab]). If modes like yasnippet and auto-complete want to bind on TAB, their trigger key must be the same with the original Tab command. Since Emacs binds indent-for-tab-command on (kbd "TAB"), so it’s better to use it as the trigger key. Yasnippet binds to it by default, It is also easy to setup auto-complete to trigger using Tab.

;; trigger using TAB and disable auto start
(custom-set-variables
 '(ac-trigger-key "TAB")
 '(ac-auto-start nil)
 '(ac-use-menu-map t))

But in some modes (ruby-mode, markdown-mode, org-mode), the command is bind to (kbd "<tab>"), when the real Tab key is typed, the function bind on (kbd "<tab>) has higher priority, so yasnippet and auto-complete are not invoked. It is easy to fix by moving the keybinding:

(defun iy-tab-noconflict ()
  (let ((command (key-binding [tab]))) ; remember command
    (local-unset-key [tab]) ; unset from (kbd "<tab>")
    (local-set-key (kbd "TAB") command))) ; bind to (kbd "TAB")
(add-hook 'ruby-mode-hook 'iy-ac-tab-noconflict)
(add-hook 'markdown-mode-hook 'iy-ac-tab-noconflict)
(add-hook 'org-mode-hook 'iy-ac-tab-noconflict)

Yasnippet tries functions in yas/prompt-functions when it needs user to select one choice, such as selecting snippets with the same trigger key, such as helper method yas/choose-value.

popup is a visual popup interface library extracted from auto-complete by its author. It has better look and feel than all the built-in yas/prompt-functions. Also it is easy to customize, and its isearch mode is very efficient, the items are filtered on-the-fly when typing.

Many editor can wrap a line that reaches the window width and show an indicator in the margin, for example, Emacs.

Emacs line wrap with bent arrow in fringe

I want to add such line wrap indicators to the code block in HTML. It is easy to add indicators as background image in CSS. But the indicators should only be shown when the line is wrapped. And from the figure, the wrap indicator is not displayed on the last line in the right margin, and not on the first line in the left margin. There’s a :first-line pseudo element selector, there’s no :last-line. However, it can be achieved by using :before and :after with position trick.

You can check the result in this jsfiddle: http://jsfiddle.net/fbDKQ/6/ . Resize the result panel to see the line wrap indicators. Following is a detailed explanation.

Not fully tested, let me know if it mess up your buffer.

Pow is a zero-config Rack server for Mac OS X. Here I steal its idea to build a zero-config system based on Nginx with Passenger.

RVM has since moved to using .profile, so just put the “cd .” in .profile and it will work

— Mikael Wikman commented below

Original Article

Tmux is a terminal multiplexer. I switched to Tmux from GNU Screen recently.

I work on several Ruby projects. I use RVM to manage gem set for different projects, and use rvmrc file to switch gem set automatically. I usually start a Tmux session for a project in its root directory, so all the windows and panes in the session use the project root as default directory. The problem is, the new created shell in the session does not load .rvmrc in the root directory. I have to force loading the file using “cd .