Skip to content

Instantly share code, notes, and snippets.

View rkh's full-sized avatar
👀
heeeyyyy

Konstantin Haase rkh

👀
heeeyyyy
View GitHub Profile
require 'benchmark'
n = (ARGV.shift || 1000000).to_i
def append(words, n)
n.times { res = words.inject("") {|string, p| string << "#{p}_"} }
end
def join_under(words, n)
n.times { res = words.map{|s| s}.join("_") }
@sstephenson
sstephenson / gist:771090
Created January 8, 2011 19:41
Automatic *.test host resolution in OS X
$ sudo su -
# mkdir /etc/resolver
# cat > /etc/resolver/test
nameserver 127.0.0.1
port 2155
^D
^D
$ brew install dnsmasq
$ dnsmasq --port=2155 --no-resolv --address=/.test/127.0.0.1
$ ping foo.test
@postmodern
postmodern / c_parser.rb
Created January 16, 2011 04:24
An ANSI C Parser using the Ruby Parslet library.
#
# A C Parser using the Parslet library.
#
# ANSI C Grammar:
#
# * http://www.lysator.liu.se/c/ANSI-C-grammar-l.html
# * http://www.lysator.liu.se/c/ANSI-C-grammar-y.html
#
require 'parslet'
def require_or_install(path, gem_name = path, version = '> 0')
require path
rescue LoadError
require 'rubygems'
require 'rubygems/user_interaction'
require 'rubygems/dependency_installer'
installer = Gem::DependencyInstaller.new
installer.install gem_name, version
@skojin
skojin / irb_require_without_bundler_hack.rb
Created January 25, 2011 13:33
workaround to load irb specific gem (loaded in .irbrc) in bundler environment, like rails3 console
# Add all gems in the global gemset to the $LOAD_PATH so they can be used in rails3 console with bundler
if defined?(::Bundler)
$LOAD_PATH.concat Dir.glob("#{ENV['rvm_path']}/gems/#{ENV['rvm_ruby_string']}@global/gems/*/lib")
end
@rkh
rkh / fun1.rb
Created January 25, 2011 18:33
module ClassHook
extend_object Class
def new(sclass = Object, *args)
super(sclass.to_class, *args)
end
end
module ModuleHook
append_features Module
#define STRING char *
#define IF if(
#define THEN ){
#define ELSE } else {
#define FI ;}
#define WHILE while (
#define DO ){
#define OD ;}
#define INT int
#define BEGIN {
@rtomayko
rtomayko / gist:814024
Created February 7, 2011 05:11
sample of github git fetch times by protocol
$ uname -a && git --version
Darwin asha.local 10.6.0 Darwin Kernel Version 10.6.0: Wed Nov 10 18:13:17 PST 2010; root:xnu-1504.9.26~3/RELEASE_I386 i386
git version 1.7.2.1
$ git clone git://github.com/github/gitignore.git
$ cd gitignore
$ # fetching over ssh
$ yes | head -5 | (while read ; do time git fetch [email protected]:github/gitignore.git; done) 2>&1 | grep real
real 0m2.103s
rvm install ruby-head-n18 --branch ruby_1_8
rvm alias ruby-head-n18 1.8.8
>> "1" =~ /(?<a>\d)/ && a
NameError: undefined local variable or method `a' for main:Object
from (irb):5
from /Users/lee/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `<main>'
>> /(?<a>\d)/ =~ "1" && a
=> "1"