Skip to content

Instantly share code, notes, and snippets.

View igrigorik's full-sized avatar
:octocat:

Ilya Grigorik igrigorik

:octocat:
View GitHub Profile
@mrflip
mrflip / async_aroundware_demo.rb
Created May 1, 2011 07:13
Goliath middleware that does an asynchronous request, and only proceeds with the response when both the endpoint and our middleware's responses have completed
#!/usr/bin/env ruby
$: << File.dirname(__FILE__)+'/lib'
require 'goliath'
require 'em-synchrony/em-http'
#
# Here's an example of how to make an asynchronous request in the middleware,
# and only proceed with the response when both the endpoint and our middleware's
# responses have completed.
@rdp
rdp / Go2.java
Created May 23, 2011 22:18
example file that seems to get slower when used with hotspot JVM. Us
/* use like
$ javac Go2.java
$ java -client Go2
$ java -server Go2
*/
public class Go2 {
@chrishamant
chrishamant / guestbook.go
Created July 11, 2011 13:30
Go Lang app engine sample
// Copyright 2011 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package guestbook
import (
"http"
"io"
"os"
@mnot
mnot / sun buffering goes wild
Created August 11, 2011 02:32
The raw HTTP of a GET response from http://www.sun.com/ (before the Oracle acquisition), reproduced here in its entirety.
HTTP/1.1 200 OK
Server: Sun-Java-System-Web-Server/7.0
Date: Mon, 07 Dec 2009 07:25:34 GMT
P3p: policyref="http://www.sun.com/p3p/Sun_P3P_Policy.xml", CP="CAO DSP COR CUR ADMa DEVa TAIa PSAa PSDa CONi TELi OUR SAMi PUBi IND PHY ONL PUR COM NAV INT DEM CNT STA POL PRE GOV"
Cache-control: public
Set-cookie: JROUTE=W2VMz2yu926eYGvP; Path=/
X-powered-by: JSP/2.1
Set-cookie: JSESSIONID=80765ae114eab08df95a11208c62; Path=/
Content-type: text/html;charset=UTF-8
Via: 1.1 https-www
require 'jruby'
module Serialize
def self.serialize(obj)
baos = java.io.ByteArrayOutputStream.new
oos = java.io.ObjectOutputStream.new(baos)
oos.write_object(JRuby.reference(obj))
oos.close
@headius
headius / gist:1408381
Created November 30, 2011 07:54
JRuby Fiber perf compared to 1.9.3
# Ruby 1.9.3
ruby-1.9.3-p0 ~/projects/jruby $ ruby -v bench/bench_fiber_ring.rb 5 100 1000
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
bench/bench_fiber_ring.rb:23: warning: mismatched indentations at 'end' with 'def' at 21
100 fibers / 1000 passes: 0.150000 0.000000 0.150000 ( 0.155022)
100 fibers / 1000 passes: 0.150000 0.000000 0.150000 ( 0.153985)
100 fibers / 1000 passes: 0.150000 0.000000 0.150000 ( 0.153822)
100 fibers / 1000 passes: 0.150000 0.000000 0.150000 ( 0.152370)
100 fibers / 1000 passes: 0.160000 0.000000 0.160000 ( 0.155857)
@tarcieri
tarcieri / example_task.mirah
Created December 21, 2011 20:39
Kilim "Hello World" with Mirah
# Adapted from https://github.com/kilim/kilim/blob/master/examples/kilim/examples/SimpleTask.java
import "kilim.Mailbox"
import "kilim.Pausable"
import "kilim.Task"
class ExampleTask < Task
def initialize
@mailbox = Mailbox.new
end
@amacdougall
amacdougall / focus.vim
Created March 6, 2012 23:38
Simple vim script for a single centered text column.
" Name: focus.vim
" Author: Alan MacDougall <smoke@alanmacdougall.com>
" License: Public Domain
"
" Focus on a single column of text, showing it in a distraction-free format.
" Save this as ~/.vim/scripts/focus.vim (or whatever you please), and invoke
" it with :source <filename>. Of course, you could certainly hook that up to a
" :command, or a macro, or a Vimscript function...
" collapse current splits and divide screen in three
@paulmillr
paulmillr / mapreduce.scala
Created March 10, 2012 16:03
Why functional programming matters (aka MapReduce for humans)
import com.cloudera.crunch._
import com.cloudera.scrunch._
class ScrunchWordCount {
def wordCount(inputFile: String, outputFile: String) = {
val pipeline = new Pipeline[ScrunchWordCount]
pipeline.read(from.textFile(inputFile))
.flatMap(_.toLowerCase.split("\\W+"))
.filter(!_.isEmpty())
.count
@toolmantim
toolmantim / simpler_goliath_test_helpers.rb
Created March 25, 2012 18:57
Simpler test helpers for Goliath
# Additional methods for Goliath::TestHelper to make simple Goliath testing
# simple. You might need the other syntax for testing gnarly stuff, but I've
# yet to need it. To use, just include this in your spec_helper.rb.
#
# Your spec must respond to #api and return the Goliath API class to test.
#
# @example
# describe MyAPI do
# let(:api) { MyAPI }
# describe "GET /" do