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 'benchmark' | |
ordered_array = (0..10_000).map { |p| [p,p,p,p,p] }.flatten | |
random_array = ordered_array.dup.shuffle | |
Benchmark.bm do |b| | |
b.report('index') do | |
random_array.map { |n| ordered_array.index(n) } | |
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
#include <iostream> | |
using namespace std; | |
class A | |
{ | |
public: | |
virtual void Hello() { cout << "Hello from A" << endl; } | |
virtual ~A() {} | |
}; |
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
Rehearsal ------------------------------------------------------ | |
proc wrapped eval: 1.020000 0.030000 1.050000 ( 0.605000) | |
instance_eval: 2.950000 0.030000 2.980000 ( 2.273000) | |
--------------------------------------------- total: 4.030000sec | |
user system total real | |
proc wrapped eval: 0.200000 0.000000 0.200000 ( 0.204000) | |
instance_eval: 1.800000 0.010000 1.810000 ( 1.767000) |
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
class Foo | |
class << self | |
attr_accessor :a, :b | |
end | |
def self.register(args = {}) | |
args.each do |k,v| | |
self.send(:"#{k}=", v) | |
end | |
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
#include <iostream> | |
template <int N> | |
void pr(const std::string &msg) | |
{ | |
std::cout << msg << std::endl; | |
pr<N-1>(msg); // would be nice to do tail call optimization here... | |
} | |
template <> |
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
#!/bin/env ruby | |
ENV['RAILS_ENV'] = 'production' | |
require 'fileutils' | |
def sudo(cmd, as = 'root') | |
puts "sudo: #{cmd}" | |
system("sudo -u #{as} #{cmd}") | |
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
class Rubage | |
(def foo a, b, c | |
puts a | |
puts b | |
puts c | |
(puts a.gsub /A/, 'B') | |
end) | |
end | |
(if $0 == __FILE__ |
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 Parasite | |
def self.infect(object) | |
(class << object; self end).class_eval do | |
include Beasties | |
end | |
end | |
module Beasties | |
def __parasites__ |
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
#!/bin/bash | |
export GIT_SSL_NO_VERIFY=true | |
# rpmforge | |
rpm -Uhv http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS//rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm | |
yum update -y | |
# dev requirements | |
yum groupinstall -y "Development Tools" | |
yum install -y \ |
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 AutoVivifying | |
def method_missing name, *args | |
if name.to_s !~ /\=$/ | |
self.send(:"#{name}=", self.class.new) | |
else | |
super | |
end | |
end | |
end |
NewerOlder