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 'rubygems' | |
require 'rack' | |
class Object | |
def webapp | |
class << self | |
define_method :call do |env| | |
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?) | |
[200, {}, send(func, *attrs)] | |
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
# | |
# I was asked for an example of code that was DRY, but still had an | |
# instance of Connascence of Algorithm going on. | |
# | |
# Consider the following code. I think most people would agree that | |
# the code is fairly DRY in the sense that there is no duplicated | |
# code. | |
# | |
require 'digest/sha1' |
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
~/projects/jruby ➔ # single thread performance | |
~/projects/jruby ➔ jruby --server bench/bench_threaded_reverse.rb 1 | |
... | |
concurrency is - 1 | |
started thread 0 | |
Thread 0 running | |
another 10 in #<Thread:0xc8c7d6 run> | |
another 10 in #<Thread:0xc8c7d6 run> | |
another 10 in #<Thread:0xc8c7d6 run> |
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
GitHub.TreeSlider = function () { | |
if (window.history && window.history.pushState) { | |
function a() { | |
if (e.sliding) { | |
e.sliding = false; | |
$(".frame-right").hide(); | |
$(".frame-loading:visible").removeClass("frame-loading") | |
} | |
} | |
if (!($("#slider").length == 0 || !GitHub.shouldSlide)) if (!navigator.userAgent.match(/(iPod|iPhone|iPad)/)) { |
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
## Yacc is dead - Ruby edition (recognizer only) | |
# Pretty much a direct port of the recognizer from: | |
# http://matt.might.net/articles/parsing-with-derivatives/code/dparse.rkt | |
# | |
# Requires 1.9 | |
# gem install lazy | |
require 'lazy' | |
include Lazy::Methods |
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
desc "a task which creates the database user" | |
task(:createuser) do | |
require 'yaml' | |
require 'erb' | |
path = File.join(Rails.root, 'config', 'database.yml') | |
config = YAML::load(ERB.new((IO.read(path))).result) | |
config = config[Rails.env] || config | |
adapter = config['adapter'] | |
username = config['username'] | |
password = config['password'] |
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
// a solution to http://blog.abhiomkar.in/2010/07/03/javascript-code-challenge-by-dropbox-team/ | |
// | |
var countdown = function(num){ | |
for (var i = 0; i <= num; i += 1) { | |
(function(i){ setTimeout(function(){ alert(num - i); }, i * 1000); })(i); | |
} | |
} | |
countdown(5); |
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
<!-- layout file --> | |
<% if current_user %> | |
Welcome <%= current_user.username %>. Not you? <%= link_to "Log out", logout_path %> | |
<% else %> | |
<%= link_to "Sign up", signup_path %> or <%= link_to "log in", login_path %>. | |
<% 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
#! /usr/bin/env ruby | |
Main { | |
description <<-____ | |
mp3scrape will scour any url for it's mp3 content - the script mirrors, | |
never downloading the same file twice. it does not, however, crawl a | |
website for links, it simple scapes all the songs from a single page. |
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
# I want this method in ruby-core | |
def let | |
yield | |
end | |
def fib(i) | |
let do |n = 1, result = 0| | |
if i == -1 | |
result | |
else |