Skip to content

Instantly share code, notes, and snippets.

View igrigorik's full-sized avatar
:octocat:

Ilya Grigorik igrigorik

:octocat:
View GitHub Profile
@headius
headius / gist:727684
Created December 3, 2010 23:01
A GIL for JRuby?
~/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>
require 'strscan'
class Keylog
def convert(input)
output = ""
scan(input) {|s| output << s }
output
end
def count_keys(input)
keys = 0
@border
border / Makefile
Created January 12, 2011 01:36
json example in golang
include $(GOROOT)/src/Make.inc
GOFMT=gofmt -spaces=true -tabindent=false -tabwidth=4
all:
$(GC) jsontest.go
$(LD) -o jsontest.out jsontest.$O
format:
$(GOFMT) -w jsontest.go
@zaius
zaius / background.sh
Created January 16, 2011 23:29
How to redirect a running process output to a file and log out
ctrl-z
bg
touch /tmp/stdout
touch /tmp/stderr
gdb -p $!
# In GDB
p dup2(open("/tmp/stdout", 1), 1)
p dup2(open("/tmp/stderr", 1), 2)
@igrigorik
igrigorik / ruby-1.9-tips.rb
Created February 3, 2011 17:19
Ruby 1.9 features, tips & tricks you may not know about...
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
@jbaudanza
jbaudanza / config.ru
Created February 8, 2011 21:55
Example of an asynchronous rack based app on heroku
# config.ru
#
# The Heroku architecture is based on Thin, which is based on EventMachine. This means
# you can access the EventMachine API and make use of Thin's asynchronous extension to
# the rack API.
#
# This is a simple asynchronous rack backed app that will hold a request for 4 seconds
# and respond with "Hello".
#
# In theory an app structured like this should be able to handle a huge number of
@brixen
brixen / memory.rb
Created February 18, 2011 21:56
Easy tool for checking how much memory Rubinius uses
$ rbx memory.rb
memory used: 19.4M
$ bin/mspec ci -T -rmemory core/array
rubinius 1.2.1 (1.8.7 cdbdd275 2011-02-15 JI) [i686-apple-darwin9.8.0]
................................................................................................................
Finished in 3.992361 seconds
112 files, 2166 examples, 4420 expectations, 0 failures, 0 errors
@mnot
mnot / kindle_my_rfc.sh
Created March 12, 2011 01:06
Quick and dirty way to get Internet-Drafts onto your kindle
#!/bin/sh
# Kindle My RFC (or Internet-Draft)
#
# Sends an Internet Draft to your kindle
# Invocation:
# > kindle_my_rfc [path/to/rfc2629-xml-file]
# > kindle_my_rfc [draft-name-with-number-00]
#
# Requires:
@michaelbernstein
michaelbernstein / extconf.rb
Created March 27, 2011 19:55
My snappy wrapper from earlier in the week to show igrigorik
require 'mkmf'
# Give it a name
extension_name = 'lrsnappy'
# The destination
dir_config(extension_name)
$LIBS << " -lstdc++ -lsnappy"
@carsonmcdonald
carsonmcdonald / gist:911761
Created April 9, 2011 20:48
node.js SPDY proxy
var tls = require('tls');
var fs = require('fs');
var Buffer = require('buffer').Buffer;
var zlib = require('zlib');
var BufferList = require('bufferlist');
var Binary = require('bufferlist/binary');
var Put = require('put');
var http = require('http');
var options =