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
## 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 |
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
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]) |
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
if $sitedir then | |
if (not $sitedir.=~(Regexp.quote(version))) then | |
$sitedir = File.join($sitedir, version) | |
end | |
else | |
$sitedir = File.join($libdir, "site_ruby") | |
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
$ 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 |
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
# 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} |
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 '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)). |
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
From 80ca680d8c16a6dccd80c2d7ab09bf9eea816b35 Mon Sep 17 00:00:00 2001 | |
From: Magnus Holm <[email protected]> | |
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 |
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 'stringio' | |
def silent | |
$stdout = StringIO.new | |
yield | |
ensure | |
$stdout = STDOUT | |
end | |
puts "Hello" |
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 Echo < Plugin | |
author "Henrik Hodne (dvyjones)" | |
permission :echo, :default => false | |
help "Says whatever text you pass to it." | |
def echo(line) | |
say(line) | |
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
alert("Hello World!") |