Skip to content

Instantly share code, notes, and snippets.

Objects
=======
Here's an object:
+------------+
| Object |
+------------+
If we expand it we can see it contains three parts:
$:.unshift 'lib'
require 'rubygems'
require 'camping'
require 'parkaby'
Camping.goes :App
module App
include Parkaby::Frameworks::Camping
## There's more than one way to do it.
# 0
thing = [1, 2, 3]
# 1
thing.each { }
# 2 (raggi)
thing.each() { }
## Taken from The Ruby Programming Language, page 110.
# The following simple Ruby program demostrates a flip-flop. It reads a
# text file line-by-line and prints any lines that contains the text "TODO".
# It then continues printing lines until it reads a blank line.
ARGF.each do |line | # For each line of standard in or of named files
print line if line=~/TODO/..line=~/^$/ # Print lines when flip-flop is true
end
REGEXP_PAIRS = Hash[*%w[{ } ( ) [ ] < >]]
REGEXP_PAIRS.default_proc = proc { |h, k| k }
def on_regexp_beg(content)
@regexp_stack << content
end
def on_regexp_end(content)
start = @regexp_stack.pop[-1]
stop = Regexp.escape(REGEXP_PAIRS[start])
if $sitedir then
if (not $sitedir.=~(Regexp.quote(version))) then
$sitedir = File.join($sitedir, version)
end
else
$sitedir = File.join($libdir, "site_ruby")
end
$ sudo gem update
sudo: uid 501 does not exist in the passwd file!
$ whoami
501
$ grep 501 /etc/passwd
$ grep magnus /etc/passwd
## Oh shit. Let's open a new shell:
Password:
Login incorrect
# Creates a little histogram of the frequency of words occuring in your string
# Usage : ruby word_histogram.rb "Test string, string"
h=Hash.new(m=0);ARGV[m].scan(/\w+/).map{|x|h[x.downcase]+=1;m=[m,x.size].max};h.sort.map{|k,v|puts"=> %-#{m+4}s#{'*'*v}"%k}
@judofyr
judofyr / srt.rb
Created September 26, 2009 19:29
require 'time'
require 'optparse'
%w[operation time].
inject(OptionParser.new){|o,i|
o.on("-"+c=i[0,1],"--#{i} X"){|v|eval("$#{c}=v")}
o}.parse!;$t,$o=$t.tr(',','.').to_f,$o=='sub'?:-:
:+;puts File.read(ARGV[0]).gsub(/^(.*) --> (.*)$/){
[$1,$2].map{|x|(t=Time.parse(x.strip).send($o,$t)).
From 80ca680d8c16a6dccd80c2d7ab09bf9eea816b35 Mon Sep 17 00:00:00 2001
From: Magnus Holm <judofyr@gmail.com>
Date: Wed, 30 Sep 2009 21:19:29 +0200
Subject: [PATCH 1/4] * test/ripper/test_parser_events.rb: Add test case for 1939
---
test/ripper/test_parser_events.rb | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb