November 2011
1 post
Scrolling in screen
In GNU screen you can’t use the normal terminal scrolling. One way to still retrieve your history is by switching into copy mode via C-a [ or C-a ESC You can then use the arrow or movement keys h j k l for scrolling. Exit with ESC. Yay.
Nov 22nd
1 note
March 2011
2 posts
3 tags
Disable logger in Rails & Rspec
Parts of my Rails code have a good portion of logging code, because I want to observe it’s behavior closely in the real world. I will probably remove the logging code, once I’m confident enough with the code But during testing these log lines distract me from the test results and hide other stuff. So I decided it is better to disable it. I did this by adding the following code to...
Mar 21st
12 notes
Pretty JSON with curl
When using curl to call REST APIs returning JSON, it is often hard to see the structure of the response. We need to prettify that! Fortunately, the Ruby json gem has a script called “prettify_json.rb”, that we can just pipe JSON to. Awesome. Install the json gem gem install json Use it $ curl "http://api.soundcloud.com/users/4126.json" | prettify_json.rb { "id": 4126, ...
Mar 2nd
February 2011
1 post
2 tags
Screen
When working remote via SSH, you often want to make sure that your processes continue to run, even if your connection dies. Screen is the tool for that. It creates shell sessions, that are detached from your terminal session. Thus they run, without you being connected. Also different users can share screen sessions with each other. This are some of the basic commands: Open a new screen...
Feb 21st
3 notes
November 2010
2 posts
Keys in Ruby Hashes are Case Sensitive
> a = {} => {} > a['content-type'] = "My first string" => "My first string" > a['Content-Type'] = "My second string" => "My second string" > a => {"content-type"=>"My first string", "Content-Type"=>"My second string"}
Nov 25th
Avoid clutter in irb
When using irb, the prompt might get cluttered bad, if you handle huge objects, since irb always returns the last object. To clean this up, just append ; nil to your input. This will return nil, since it is the last object. Cluttered: > numbers = (1..1000).collect { |i| i } => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,...
Nov 4th
1 note
October 2010
5 posts
1 tag
See surrounding lines in grep
When you search for something with grep, you sometimes need some context for the search results. Use the following arguments for that: grep -B 2 foo bar.txt # 2 lines before every match grep -A 3 foo bar.txt # 3 lines after every match grep -C 1 foo bar.txt # 1 line before and after every match grep -n 1 foo bar.txt # 1 line before and after every match
Oct 20th
2 tags
Compare View on Github
GitHub has introduced compare view about half a year ago. It basically is a nice frontend to git diff. You can specify a start and an end point for the diff. This can be commit hashes, tag or branch names: http://github.com/<USER>/<REPO>/compare/[<START>...]<END> For example, this is everything that happened between some commit a the current master branch in the...
Oct 19th
1 note
Run only some tests in RSpec
When working with fairly big test suites in RSpec you do not want to run all tests always. Especially with Red-Green-Refactor you are only interested in some tests, sometimes even only in one describe block. RSpec helps you with this. You can specify specific files to be run: spec spec/models/my_model_spec.rb spec spec/models/my_model_spec.rb spec/models/your_model_spec.rb Sometimes...
Oct 6th
2 tags
Copy/Paste in Terminal on Mac
The following two commands let you use the Mac OS X clipboard in terminal: pbcopy pbpaste #examples cat text.txt | pbcopy pbpaste > copy_of_text.txt
Oct 5th
Executing external commands in vim
In vim I sometimes want to execute commands on the command line. Switching to a console window sometimes seems too much of a hassle. Alternatively you can execute commands in vim. :! command # example :! ls -tl | head -n10 The bang symbol ! switches to the command line. In the example I look at the latest changed file in my working directory.
Oct 5th
September 2010
3 posts
2 tags
Global .gitignore
To globally ignore files do the following: git config --global core.excludesfile ~/.gitignore then create the .gitignore file, open it and put all the stuff inside you want to ignore. Mine looks the following way at the moment: # RVM RC .rvmrc # VIM *.un~ # Mac OS X Finder DS_Store .DS_Store [found in peepcode google group]
Sep 27th
Project-Wide Search in Vim
I am using ack for project-wide search in vim. This vim plugin replaces grep in vim to use ack instead. You can search for something in the following way then: :grep "search_pattern" location # search_pattern = regex pattern # location = absolute or relative path #example :grep "require\('debug'\)" . This will open a vim quickfix window. Pressing enter jumps to the first search result. Here...
Sep 27th
1 note
Installing old versions with Homebrew
Sadly Homebrew (in current version 0.7) does not support installing old versions of software. If you want to install older versions of it anyway, you have to alter the Formulas for the software. There are two ways to do this: 1. Go to the directory where your Homebrew Formulas are. I think the default is: cd /usr/local/Library/Formula/ and there you can directly alter the Formulas, like...
Sep 15th
April 2010
1 post
Freenerd →
Apr 14th