Skip to content

Instantly share code, notes, and snippets.

import Queue as _oldQueue
import heapq
from time import mktime, time as _time
class PriorityQueue(_oldQueue.PriorityQueue):
'''
This class extends Python's Queue.PriorityQueue by allowing it to
evict lower priority items in order to make room. This avoids a
starvation problem where low-priority items fill the queue and prevent
a high-priority item from being inserted.
@thom-nic
thom-nic / echo.erl
Created February 27, 2011 21:04
Erlang echo script
%%% Sends a message back & forth
%%% Author: Thom Nichols
%%%
%%% Remote server communication demo.
%%% Use start_listener/1 to register a listener on a remote or local node.
%%% use send/2 to send a messge to a node and listen for its response.
-module(echo).
-author('Thom Nichols').
-import(erlang).
@thom-nic
thom-nic / NumberPickerPreference.java
Created May 6, 2011 22:06
NumberPicker Preference Dialog for Android!
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.View;
import com.quietlycoding.android.picker.NumberPicker;
public class NumberPickerPreference extends DialogPreference {
@thom-nic
thom-nic / node-builder.js
Created September 26, 2011 16:07
Node builder (DOM) for Javascript
/**
* Node builder. Call like:
* $n('div',{class:'top'},'inner text') // or:
* $n('div',{class:'top'},[$n('p',{},'nested element'])
*/
$n= function(e,attrs,inner) {
if(typeof(e)=='string') e = document.createElement(e);
if (attrs) for (var k in attrs) e.setAttribute(k,attrs[k]);
if (inner) {
if (typeof(inner)=='string') e.textContent = inner;
@thom-nic
thom-nic / userContent.css
Created November 2, 2011 13:19
Google Reader CSS tweaks
/* Collapse Google Reader iframe ad frames */
@-moz-document url-prefix(https://www.google.com/reader/),
url-prefix(http://www.google.com/reader/) {
/* Make the search bar take up less vertical space */
#top-bar { height: 44px !important; }
#search { padding: 8px 0 !important; }
/* make the 'subscribe' bar take up less vertical space */
#viewer-header, #lhn-add-subscription-section { height: 42px !important; }
/* Right panel */
@thom-nic
thom-nic / rainbows.config.rb
Created February 8, 2012 13:05
Rainbows + AMQP configuration
# run with rainbows -c rainbows.config.rb
require 'rainbows'
listen 8888 # by default Unicorn listens on port 8080
worker_processes 9 # this should be >= nr_cpus
pid "unicorn.pid"
#stderr_path "unicorn.log"
#stdout_path "unicorn.log"
# nuke workers after 30 seconds instead of 60 seconds (the default)
timeout 30
@thom-nic
thom-nic / queue_test.rb
Created February 9, 2012 20:04
AMQP Example
require 'amqp'
AMQP.start 'amqp://localhost' do
puts 'Connected.'
AMQP::Channel.new do |channel, open_ok|
channel.queue "schwartz.test2", :durable => false do |queue, ok|
queue.subscribe do |headers, msg|
puts "Got message: #{msg}"
end
EM.add_periodic_timer 5 do
@thom-nic
thom-nic / example_amqp_spec.rb
Created February 17, 2012 15:28
Testing ruby-amqp and evented-spec with MiniTest
require 'evented-spec'
require 'minitest/autorun'
require "amqp"
class TestConsumer
attr_reader :connection_string, :queue_name,
:connection, :channel, :queue,
:msg_count, :errors
def initialize opts={}
@thom-nic
thom-nic / wifi-dmesg.txt
Created June 6, 2012 18:54
Raspberry Pi wifi adapter dmesg output
Linux version 3.1.9+ (dc4@dc4-arm-01) (gcc version 4.5.1 (Broadcom-2708) ) #52 Tue May 8 23:49:32 BST 2012
CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
CPU: VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
Machine: BCM2708
Memory policy: ECC disabled, Data cache writeback
On node 0 totalpages: 57344
free_area_init_node: node 0, pgdat c03bb910, node_mem_map c0408000
Normal zone: 448 pages used for memmap
Normal zone: 0 pages reserved
Normal zone: 56896 pages, LIFO batch:15
@thom-nic
thom-nic / dmesg-apple-kbd.txt
Created June 7, 2012 13:47
Raspberry Pi dmesg errors with Apple USB keyboard
71)
hub 1-1.3:1.0: unable to enumerate USB device on port 2
DEBUG:handle_hc_chhltd_intr_dma:: XactErr without NYET/NAK/ACK
DEBUG:handle_hc_chhltd_intr_dma:: XactErr without NYET/NAK/ACK
DEBUG:handle_hc_chhltd_intr_dma:: XactErr without NYET/NAK/ACK
hub 1-1.3:1.0: cannot disable port 2 (err = -71)
usb 1-1.3: USB disconnect, device number 56