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
| #!/usr/bin/env ruby | |
| require 'rubygems' | |
| require 'rack' | |
| server = Rack::Handler::Mongrel | |
| app = Rack::ShowExceptions.new(Rack::Lint.new(Rack::File.new("."))) | |
| server.run(app, :Port => 9292) |
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
| # Loops are cool I guess... | |
| def fib(num) | |
| return 1 if num == 1 | |
| return 1 if num == 2 | |
| x = 1 | |
| y = 1 | |
| a = 0 |
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 'benchmark' | |
| def loopy_fib(num) | |
| return 1 if num == 1 | |
| return 1 if num == 2 | |
| x = 1 | |
| y = 1 | |
| a = 0 |
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 'test/unit' | |
| # First of all, let's write a test | |
| # | |
| # A new board should be empty | |
| class BoardTest < Test::Unit::TestCase | |
| def test_a_new_board_should_be_empty | |
| board = Board.new | |
| assert_equal(0, board.size) |
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
| // prototype | |
| new Ajax.Request("/your/mom", onSuccess: function(response) { $("lightbox_content").innerHTML = response.responseJSON.contents }) | |
| new Ajax.Updater("lightbox_content", "/your/mom"); | |
| // jquery | |
| $.getJSON("/your/mom", function(json) { $("#lightbox_content").html(json.contents) }) |
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 'benchmark' | |
| # This takes like forever because '+=' adds seconds, not days. | |
| bm = Benchmark.measure do | |
| next_meeting = Time.now.next_month.beginning_of_month | |
| while next_meeting.strftime("%a") != "Thu" | |
| next_meeting += 1 | |
| end | |
| end | |
| bm.real |
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 'open-uri' | |
| require 'rubygems' | |
| require 'ri_cal' | |
| ics = open("http://www.google.com/calendar/ical/2skt4ks0v2ka25svaitomsnc60%40group.calendar.google.com/public/basic.ics") | |
| cal = RiCal.parse(ics) | |
| cal.first.events.each do |event| | |
| puts event.start_time | |
| 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
| gems$ git clone http://github.com/wycats/artifice.git | |
| Initialized empty Git repository in /Users/josh/code/gems/artifice/.git/ | |
| remote: Counting objects: 21, done. | |
| remote: Compressing objects: 100% (17/17), done. | |
| remote: Total 21 (delta 3), reused 0 (delta 0) | |
| Unpacking objects: 100% (21/21), done. | |
| gems$ | |
| gems$ cd artifice/ | |
| artifice$ | |
| artifice$ rake |
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 'pp' | |
| class Base | |
| def self.update_all(one, two = nil, three = {}) | |
| puts "one:" | |
| pp one | |
| puts "two:" | |
| pp two |
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 'benchmark' | |
| n = 1_000_000 | |
| Benchmark.bm(7) do |x| | |
| x.report('gsub') { for i in 1..n; 'hello'.gsub('l', ''); end } | |
| x.report('tr') { for i in 1..n; 'hello'.tr('l', ''); end } | |
| x.report('delete') { for i in 1..n; 'hello'.delete('l'); end } | |
| end | |
| # user system total real |
OlderNewer