Scrappy Ruby tips and techniques for the young at heart!
This is the first article in a series where I’ll implement a Unix shell in pure Ruby code.
Since the release of Heroku’s Cedar platform they’ve opened up the opportunity for users to run web applications on any stack. Using something called a buildpack we can describe a template for deploying any kind of application.
Story.find_by_legacy_id(legacy_id) or raise ActiveRecord::RecordNotFound
You’re doing it really wrong, use the bang version instead, like that: Story.find_by_legacy_id!(legacy_id)
The exception will automatically raised and you don’t need to pollute your code :)
In order to get your login shell to execute the script (without forking) you have to use the “.” command (for the Bourne or Korn shells) or the “source” command (for the C shell). I.e. you type
. myscript
You can use free tool:
free -m
or
cat /proc/meminfo
but showing info in KB
http://www.rampant-books.com/t_linux_8_system_buffers_ram.htm
Complementing this post from Ruby Quicktips
If you want to ensure that a local variable has a value, you can do so:
>> somevar
NameError: undefined local variable or method `somevar' for main:Object
from (irb):1
>> somevar = somevar || "somevalue"
=> "somevalue"
but if you try to set another variable, using a value of a variable that may not exists, you will get an error:
>> somevar
NameError: undefined local variable or method `somevar' for main:Object
from (irb):1
>> someothervar = somevar || "somevalue"
NameError: undefined local variable or method `somevar' for main:Object
from (irb):2
If you need to find out what commit a word/phrase was removed, you may try this:
git log --pretty=oneline -S'my_method_name'
This command can be used to find any piece of code, removed or not.
By default git stash show shows only a simple diff, to show the full version, use -u parameter, like this:
git stash show -u
if you are trying to use thin with a rails app and is getting this:
$ thin start
>> Using rails adapter
Missing the Rails 2.3.5 gem. Please `gem install -v=2.3.5 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.
so, all you need to do is uninstall rack 1.1.0. I am using rack 1.0.1 now it’s working very nice.
source: http://osdir.com/ml/RubyonRailsTalk/2010-01/msg01970.html
PS: Could someone, please, show me a theme that no breaks with long lines of code? ¬¬
ActiveSupport adds some methods to convert strings into dates/times, it’s very nice, take a look.
Instead:
>> Date.parse('2010-01-12')
=> Tue, 12 Jan 2010
You can do:
>> '2010-01-12'.to_date
=> Tue, 12 Jan 2010
It’s very more intuitive and readable!
http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Conversions.html