Skip to content

Instantly share code, notes, and snippets.

View ept's full-sized avatar

Martin Kleppmann ept

View GitHub Profile
Giveaway of old computing equipment! Everything still works, as far as I know.
If you want anything, let me know ASAP (@martinkl on Twitter), otherwise
it's going for recycling. You can pick it up in Kingston upon Thames
(south-west London). Everything free, the sooner it's gone the better.
Desktop computers
-----------------
module RegexTest
LAMBDAS = {
:one => lambda{|str| str[/(\w+)/, 1] },
:two => lambda{ puts "$1 = #{$1}" }
}
end
RegexTest::LAMBDAS[:one].call('foo')
# => "foo"
RegexTest::LAMBDAS[:two].call
@ept
ept / gist:2920086
Created June 12, 2012 20:56
Ratio of mean to median household income, by country (2004)
Ratio of mean to median household income, by country (2004)
Country Mean Median Currency Mean greater by
United Kingdom 16,685 13,637 British Pound 22.4%
United States 32,195 26,672 United States Dollar 20.7%
Italy 15,835 13,367 Euro 18.5%
Poland 14,844 12,697 Polish złoty 16.9%
Australia 29,417 25,581 Australian Dollar 15.0%
Canada 33,785 29,394 Canadian Dollar 14.9%
@ept
ept / gist:2838935
Created May 30, 2012 20:57
Make Storm use exec instead of forking a child for the JVM (patch for 0.7.1 release)
--- a/bin/storm 2012-05-30 19:57:54.265944289 +0000
+++ b/bin/storm 2012-05-30 20:36:25.516040172 +0000
@@ -82,12 +82,15 @@
"""
print name + ": " + confvalue(name, [STORM_DIR + "/conf"])
-def exec_storm_class(klass, jvmtype="-server", childopts="", extrajars=[], args=[]):
- nativepath = confvalue("java.library.path", extrajars)
- args_str = " ".join(map(lambda s: "\"" + s + "\"", args))
- command = "java " + jvmtype + " -Dstorm.home=" + STORM_DIR + " " + get_config_opts() + " -Djava.library.path=" + nativepath + " " + childopts + " -cp " + get_classpath(extrajars) + " " + klass + " " + args_str
@ept
ept / Podfile
Created November 20, 2011 00:20
Podfiles
platform :ios
dependency 'JSONKit'
dependency 'ASIHTTPRequest'
@ept
ept / qrupdate.log
Created August 28, 2011 21:14
brew install qrupdate
==> Downloading http://downloads.sourceforge.net/qrupdate/qrupdate-1.1.1.tar.gz
File already downloaded in /Users/martin/Library/Caches/Homebrew
/usr/bin/tar xf /Users/martin/Library/Caches/Homebrew/qrupdate-1.1.1.tar.gz
==> Using Homebrew-provided fortran compiler.
This may be changed by setting the FC environment variable.
==> make -j 1 install
make -j 1 install
/usr/local/bin/gfortran -O3 -march=core2 -msse4.1 -w -pipe -fPIC -c caxcpy.f
/usr/local/bin/gfortran -O3 -march=core2 -msse4.1 -w -pipe -fPIC -c cch1dn.f
/usr/local/bin/gfortran -O3 -march=core2 -msse4.1 -w -pipe -fPIC -c cch1up.f
@ept
ept / failure
Created August 11, 2011 02:47
Exceptions in Neo4j.rb (1.1.4)
jruby-1.6.3 :001 > require 'rubygems'
=> true
jruby-1.6.3 :002 > require 'neo4j'
=> true
jruby-1.6.3 :003 > inserter = Neo4j::Batch::Inserter.new
=> #<Neo4j::Batch::Inserter:0xd713fe @rule_inserter=#<Neo4j::Batch::RuleInserter:0x4936f3 @inserter=#<Neo4j::Batch::Inserter:0xd713fe ...>>, @batch_inserter=#<Java::OrgNeo4jKernelImplBatchinsert::BatchInserterImpl:0x118abfe>>
jruby-1.6.3 :004 > node_a = inserter.create_node('name' => 'andreas')
=> 1
jruby-1.6.3 :005 > node_c = inserter.create_node('name' => 'craig')
=> 2
class BridgeController < ApplicationController
rescue_from YouShallNotPassException, :status => 403, :error_code => 'no_way' do |exception, response|
response[:where] = exception.backtrace.first
end
# Assuming a route like this:
# map.connect "/khazad_dum/bridge/cross", :controller => :bridge, :action => :cross, :format => :json
# then this will return a HTTP 403 error with the following JSON object as body:
# {"error_code": "no_way", "message": "No balrogs past this point please",
# "where": "bridge_controller.rb:12:in `cross'"}
import java.util.logging.Logger
import com.rabbitmq.client.{AlreadyClosedException, Channel, Connection, ConnectionFactory,
ConnectionParameters, QueueingConsumer, ShutdownSignalException, AMQP}
object RabbitExample {
case class Config(host: String, port: Int)
val config = Config("localhost", 5672)
private val log = Logger.getLogger(this.getClass.getName)
private var connectionFactory: ConnectionFactory = null
Consuming example queue...
Exception in thread "main" com.rabbitmq.client.ShutdownSignalException: connection error; reason: java.io.EOFException
at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:599)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:461)
Caused by: java.io.EOFException
at java.io.DataInputStream.readUnsignedByte(Unknown Source)
at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:117)
at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:151)
at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:288)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:431)