Skip to content

Instantly share code, notes, and snippets.

@nelsnelson
nelsnelson / seccomp-example.sh
Created February 13, 2014 21:39
lxc 1.0.0.beta1 seccomp example
$ cat seccomp-example.sh
#! /usr/bin/env bash
cat << EOF > /tmp/config
lxc.seccomp = /tmp/whitelist
EOF
cat << EOF > /tmp/whitelist
1
whitelist
0
@nelsnelson
nelsnelson / InterruptDemo.java
Last active December 14, 2015 12:39
Test demo to show how future.cancel(true); does not seem to be working. test/InterruptDemo.java
package test;
import java.lang.InterruptedException;
import java.lang.Runnable;
import java.util.Calendar;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@nelsnelson
nelsnelson / future_cancellation_test.rb
Last active December 14, 2015 12:39
This is a test of the future.cancel(true) method.
#! /usr/bin/env jruby
=begin
$ ./interrupt.rb
Current time: Monday March 4 03/04/2013 21:40:06.304
Scheduled event for 10 seconds from now
f1: Current time: Monday March 4 03/04/2013 21:40:06.341
Cancelling f1
f2: Current time: Monday March 4 03/04/2013 21:40:11.357
Got f1: Current time: Monday March 4 03/04/2013 21:40:11.361
@nelsnelson
nelsnelson / latency.markdown
Created October 25, 2012 22:07 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Syscall on Intel 5150 ...................... 105 ns
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Context switch on Intel 5150 ............. 4,300 ns  =   4 µs

Send 2K bytes over 1 Gbps network ....... 20,000 ns = 20 µs

@nelsnelson
nelsnelson / non_persistent_test.rb
Created March 2, 2012 03:55 — forked from jeremyevans/non_persistent_test.rb
Testing non-persistent fields on persisted identity-mapped entity instances in JRuby and Sequel through jdbc-postgres
#! /usr/bin/env jruby
require 'rubygems'
require 'sequel'
gem 'jdbc-postgres'
DB = Sequel.connect('jdbc:postgresql://localhost:5432/test?user=test&password=test')
DB.create_table? :test do
@nelsnelson
nelsnelson / non_persistent_test.rb
Created March 1, 2012 03:46
Testing non-persistent fields on persisted identity-mapped entity instances in JRuby and Sequel through jdbc-postgres
#! /usr/bin/env jruby
require 'rubygems'
require 'sequel'
gem 'jdbc-postgres'
@connection = Sequel.connect('jdbc:postgresql://localhost:5432/test?user=test&password=test')
Sequel::Model.db = @connection
Sequel::Model.plugin :identity_map
@nelsnelson
nelsnelson / method_test.rb
Created August 23, 2011 23:43
I don't get it. Can anybody explain to me what is happening here?
#! /usr/bin/env ruby
module Helper
def help1
@help1 ||= [ :success1 ]
end
def help1=(a)
@help1 = a
end
def help2
@nelsnelson
nelsnelson / wrapper_test.rb
Created August 22, 2011 03:29
This is a demo of an error I am seeing when attempting to access self inside the initialize method of a class
#! /usr/bin/env jruby
require 'java'
java_import java.util.Date
class Klass
def initialize
puts "Hi. I'd like to see what I look like during initialization. :)"
puts "self # => #{self} (#{self.class})"
@nelsnelson
nelsnelson / pip_fail.txt
Created June 30, 2011 16:09
An example of pip for python failing to install readline
nels.nelson@peregrine:~$ sudo pip install readlline
Downloading/unpacking readlline
Could not find any downloads that satisfy the requirement readlline
No distributions at all found for readlline
Storing complete log in /Users/nels.nelson/.pip/pip.log
nels.nelson@peregrine:~$ sudo easy_install readline
Searching for readline
Reading http://pypi.python.org/simple/readline/
Reading http://www.python.org/
Reading http://github.com/ludwigschwardt/python-readline
@nelsnelson
nelsnelson / gist:946971
Created April 28, 2011 18:35
To store a 1:1 (one pixel = 1/72 inch) image of the entire surface of the Earth
Assuming image resolution:
72ppi = 5184 pixels per square inch
Surface area of the Earth:
510,072,000 km2 = (7.90613181 × 10 to the 17th) square inches
Assuming (for a lossless PNG) an average storage size of:
~7.76 bits per pixel
7.90613181 × 10 to the 17th square inches