This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def do_jobs | |
begin | |
while true | |
# do interesting things | |
end | |
rescue NoMoreDiskSpace | |
# tidy things up | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'timeout' | |
Timeout.timeout(rand) do # random number between 0 and 1 (seconds) | |
sleep 0.1 | |
sleep 0.1 | |
sleep 0.1 | |
sleep 0.1 | |
sleep 0.1 | |
sleep 0.1 | |
sleep 0.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env ruby | |
require 'rubygems' | |
require 'pony' | |
# total memory used | |
total_memory_used = `free | awk '$1=="Mem:" {print $3 / $2 * 100}'`.to_i | |
# active memory used | |
used = `awk '$1=="Active:"{active=$2}$1=="MemTotal:"{total=$2}END{print active/total * 100}' /proc/meminfo`.to_i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2012-09-27 18:08:53.258 growlnotify[83684:707] Got disconnected: Error Domain=NSPOSIXErrorDomain Code=61 "Connection refused" UserInfo=0x7fb3e2a0f900 {NSLocalizedDescription=Connection refused, NSLocalizedFailureReason=Error in connect() function} | |
2012-09-27 18:08:53.260 growlnotify[83684:707] <GrowlGNTPRegistrationAttempt: 0x7fb3e2a0f770> failed because Error Domain=NSPOSIXErrorDomain Code=61 "Connection refused" UserInfo=0x7fb3e2a0f900 {NSLocalizedDescription=Connection refused, NSLocalizedFailureReason=Error in connect() function} | |
2012-09-27 18:08:53.260 growlnotify[83684:707] Failed to register with (null) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foo | |
bar | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# diff -c 1.txt 3.txt - lack of newline is announced in output | |
*** 1.txt 2012-11-03 23:24:05.000000000 -0400 | |
--- 3.txt 2012-11-03 23:28:44.000000000 -0400 | |
*************** | |
*** 1,2 **** | |
! foo | |
bar | |
\ No newline at end of file | |
--- 1,2 ---- | |
! food |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# diff -c 1.txt 2.txt | |
*** 1.txt 2012-11-03 23:24:05.000000000 -0400 | |
--- 2.txt 2012-11-03 23:24:13.000000000 -0400 | |
*************** | |
*** 1,2 **** | |
foo | |
! bar | |
\ No newline at end of file | |
--- 1,3 ---- | |
foo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function chpwd { | |
if [ -r $PWD/Gemfile ]; then | |
export PATH=./bin:${PATH//\.\/bin:} | |
else | |
regexp-replace PATH '\./bin:' '' | |
fi | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def my_method(arg1, arg2) | |
unless Foo == arg1.class | |
raise ArgumentError, | |
"A Foo is expected for the first argument. An #{arg1.class} was given." | |
end | |
unless Bar == arg2.class | |
raise ArgumentError, | |
"A Bar is expected for the first argument. An #{arg2.class} was given." | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object | |
def self.typecheck(object) | |
unless self == object.class | |
raise ArgumentError, | |
"expected type: #{self}. given: #{object.class}." | |
end | |
end | |
end | |
class Foo; end |