artathack.com

about web and mobile development

Issues With ZSH and Octopress

Since I moved from bash to zsh I figured out some commands for Octopress stopped working.

E.g. when I run rake deploy I get this:

1
2
$ bundle exec rake deploy
zsh: correct 'deploy' to '_deploy' [nyae]?

To get rid of the annoying message I now use some commands with quotation marks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# deploying
$ bundle exec rake deploy
->
$ bundle exec "rake deploy"

# installing new themes
$ bundle exec rake install[slash]
->
$ bundle exec rake "install[slash]"

# generating a blog post
$ rake new_post[Issues with zsh and Octopress]
->
$ rake "new_post[Issues with zsh and Octopress]"

Link a Table Row With jQuery

Since I had to do this lately and didn’t found a tutorial which was up to date I decided to write one by myself. If you google this task the great post of Imar Spaanjaars How Do I Make a Full Table Row Clickable Using jQuery? is one of the top results, so I´d like to show a quite similar but simplified version of this example. (just to provide and alternative attempt not a better one, to make this clear!)

I also use a table with 3 rows which are all linked to different sites. Imar solves the solution by using an additional column in which he provides the links as a fallback for old browsers and hides them with jQuery.

1
2
3
4
5
6
7
8
9
10
11
12
<tr>
  <td><a href="http://www.google.com/">http://www.google.com/</a></td>
  <td>1</td>
  <td>2</td>
  <td>3</td>
</tr>
<tr>
  <td><a href="http://www.yahoo.com/">http://www.yahoo.com/</a></td>
  <td>4</td>
  <td>5</td>
  <td>6</td>
</tr>

If you don’t care about old browsers I think there is a shorter method. Instead of using and additional <td> I want to link the table row <tr> explicitly like:

1
2
3
4
5
6
7
8
9
10
<tr url="http://www.google.at">
  <td>1</td>
  <td>2</td>
  <td>3</td>
</tr>
<tr url="http://www.yahoo.at">
  <td>4</td>
  <td>5</td>
  <td>6</td>
</tr>

To trigger the url when clicking at a table row you can use the live() event of jQuery like this:

1
2
3
4
5
$(function () {
  $("table tr").live("click",function() {
    location.href = $(this).attr("url");
  });
});

To communicate to your user that a table row is clickable you might want to use some css:

1
2
3
.Pointer {
  cursor: pointer;
}

The whole code:

https://gist.github.com/4524458

Run Ruby Scripts Within VIM!

Since I’m writing lots of Ruby scripts lately I was tired testing them using the Command Line and MacVim.

Saving the file, go to to terminal, reuse last command $ ruby foobar.rb

to slow and boring!!!

Fortunately I found out it is possible to run Ruby Scripts inside VIM with the following 2 commands:

1
2
3
:set makeprg=ruby\ %

:make

If you are lazy like me put something like this in your .vimrc and run your scripts blazingly fast (3 keystrokes)!

1
map <Leader>rr :set makeprg=ruby\ %<cr>:make<cr>

If you use RVM and want to use a specific version of your installed rubies you can go with something like this:

1
map <Leader>rr :set makeprg=~/.rvm/bin/ruby-1.9.3-p194\ %<cr>:make<cr>

Of course this works with other scripting languages as well e.g.:

1
map <Leader>rp :set makeprg=python\ %<cr>:make<cr>

iTerm2: Stay in the Same Directory

I use iTerm2 for about a year now but recognized one “hidden” handy feature just some days ago.

If you cd in a directory where you might want to run a server, run your tests, use your VCS of choice and so on you need to open the same directory over and over again in your tabs or split panes. Open a new Tab and cd to the same directory all the time is very wasteful. So I´ve written a script which does that for me and bundled it with Spark so I just needed to type a shortcut to open a new Tab and cd to my current directory.

BUT with iTerm2 you can achive this behaviour very easily:

Go to Preferences -> Profiles -> General -> Working Directory -> Advanced Configuration -> Edit

first

Then you´ll be in this menu:

second

And change the Radio Button to Reuse previous session´s directory and you´ll get the automatic cd of your current directory for free!

UPDATE:

If you use zsh & RVM you want to add this line to your .zshrc:

__rvm_project_rvmrc

https://rvm.io/integration/zsh/