Skip to content

Instantly share code, notes, and snippets.

Interesting tidbit:
Due to this line in ruby's Timeout module:
https://github.com/ruby/ruby/blob/v1_9_3_429/lib/timeout.rb#L84
If you use your own custom class, you don't get the original timeout exception backtrace.
This is probably a good thing.
require 'celluloid/autostart'
class FetcherTimeoutError < StandardError; end
class ProjectMessage
attr_accessor :project
def initialize(project)
@project = project
end
@saimonmoore
saimonmoore / self-control.bash
Created May 23, 2013 10:24
turn internet on/off for a short while
#!/bin/bash
PORTS="80 443"
UNDO=
for p in $PORTS
do
iptables -I OUTPUT -p tcp --dport $p -j DROP -v
UNDO="$UNDO iptables -D OUTPUT -p tcp --dport $p -j DROP -v;"
done
@saimonmoore
saimonmoore / gist:5484615
Created April 29, 2013 20:41
Unbuffer tty and copy ansi escape sequences in OSX
script -q /dev/null bundle exec rspec spec/lib/organization/manager_spec.rb -c -f d | bcat
@saimonmoore
saimonmoore / export_skype_chat_history.sh
Created April 5, 2013 08:24
Bash function to export Skype chat history for a particular conversation
function export_skype_chat_history {
sqlite3 ~/Library/Application\ Support/Skype/saimonmoore/main.db "SELECT author,timestamp, body_xml FROM messages WHERE dialog_partner = '$1'" > ~/Desktop/skype_chat_history_$1.txt
}
module C; def self.included(base); alias :__foo :foo; define_method :foo do |*args|; puts 'dm:'; puts super(*args);puts send('__foo', *args); end; end; def foo; puts 'C';end; end
=> nil
>> A.new.foo C
=> nil
>> class A; include B; include C; end => A
>> A.new.foo dm:
B
C
=> nil
@saimonmoore
saimonmoore / gist:5061143
Created February 28, 2013 23:41
Conditional execution
$ irb
>> class C
>> def self.opt?
>> true
>> end
>> end
=> nil
>>
?> module B
>> def foo
location / {
if (-f $uri/index.html) {
add_header Cache-Control "max-age=0, no-store";
add_header Pragma "no-cache";
expires 0;
}
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
$ cat .rbenv-vars
PASSWD=$foo
$ rbenv vars
export PASSWD=''$foo''
$ vim .rbenv-vars
$ cat .rbenv-vars
PASSWD=\$foo
$ rbenv vars
export PASSWD=''\$'foo'