This file contains 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
module Debug | |
def who_am_i? | |
self.class.name | |
end | |
end | |
class A | |
include Debug | |
end |
This file contains 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
module Summable | |
def sum | |
inject{ |i,j| i + j } | |
end | |
end | |
class Array | |
include Summable | |
end |
This file contains 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
For those having trouble with 'ç' on Ubuntu 11.04: | |
Open gtk.immodules | |
$ sudo vim /usr/lib/gtk-2.0/2.10.0/gtk.immodules | |
Edit the following line: | |
"cedilla" "Cedilla" "gtk20" "/usr/share/locale" "az:ca:co:fr:gv:oc:pt:sq:tr:wa" |
This file contains 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
# Selection sort (very slow on large lists) | |
a = [9,8,6,1,2,5,4,3,9,50,12,11] | |
n = a.size - 1 | |
n.times do |i| | |
index_min = i | |
(i + 1).upto(n) do |j| | |
index_min = j if a[j] < a[index_min] |
This file contains 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
# Insertion sort (inefficient on large lists) | |
require 'test/unit' | |
def sort(a) | |
n = a.size - 1 | |
1.upto(n) do |i| | |
new_value = a[i] | |
j = i | |
while j > 0 && a[j - 1] > new_value do |
This file contains 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
# Bubble sort (inefficient for sorting large data volumes) | |
require 'test/unit' | |
def sort(a) | |
swapped = true | |
n = a.size | |
j = 0 | |
while swapped do | |
swapped = false |
This file contains 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
cd ~/Dropbox | |
mkdir -p repos/myrepo.git | |
cd !$ | |
git --bare init | |
cd ~/Projects/myrepo | |
git remote add dropbox file://$HOME/Dropbox/repos/myrepo.git | |
git push dropbox master |
This file contains 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
a = [1,2,3,4] | |
a.select{|n| n > 2} # 3,4 | |
a.reject{|n| n > 2} # 1,2 | |
a.collect{|n| n * 2} # 2,4,6,8 |
This file contains 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 'dbi' | |
begin | |
dbh = DBI.connect("DBI:Mysql:test:localhost", "root", "") | |
row = dbh.select_one("SELECT VERSION()") | |
puts "Server version: #{row[0]}" | |
rescue DBI::DatabaseError => e | |
puts "An error occurred" | |
ensure | |
dbh.disconnect if dbh |
This file contains 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
#DevKit | |
Download DevKit at http://rubyinstaller.org/downloads | |
ruby dk.rb init | |
ruby dk.rb review | |
ruby dk.rb install | |
#curl | |
Download curl at http://www.gknw.net/mirror/curl/win32/ (devel) |
OlderNewer