Skip to content

Instantly share code, notes, and snippets.

@ashpool
ashpool / gevent_queue_example.py
Created April 13, 2012 12:42
Gevent Queue example
from gevent.queue import Queue
message_queue = Queue()
def receiver(n):
while not message_queue.empty():
message = message_queue.get()
print('Received %s message %s' % (n, message))
gevent.sleep(0)
@ashpool
ashpool / PiCameraStream
Created August 4, 2017 10:01 — forked from nioto/PiCameraStream
Simple MJpeg streamer for Raspberri Pi Camera
#!/usr/bin/python
'''
A Simple mjpg stream http server for the Raspberry Pi Camera
inspired by https://gist.github.com/n3wtron/4624820
'''
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
import io
import time
import picamera
<html>
<head>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<style>
iframe {
width: 356px;
height: 100%;
border: none;
mkdir $GRAPHITE_INSTALL
cd $GRAPHITE_INSTALL
wget https://launchpad.net/graphite/0.9/0.9.10/+download/graphite-web-0.9.10.tar.gz
wget https://launchpad.net/graphite/0.9/0.9.10/+download/carbon-0.9.10.tar.gz
wget https://launchpad.net/graphite/0.9/0.9.10/+download/whisper-0.9.10.tar.gz
wget https://launchpad.net/graphite/0.9/0.9.10/+download/check-dependencies.py
wget http://pypi.python.org/packages/source/T/Twisted/Twisted-12.1.0.tar.bz2
tar xfj Twisted-12.1.0.tar.bz2
@ashpool
ashpool / git-scan-rev-list
Created February 11, 2013 14:24
Scan revision history of a git repo. Usage: git-scan-rev-list <a-word-to-search-for>
#!/bin/bash
git rev-list --all | (
while read revision; do
git grep -F $1 $revision
done
)
@ashpool
ashpool / swedishgrid.rb
Last active December 11, 2015 08:18
Nothing important here, just washing some data...
require 'rubygems'
require 'iconv'
require 'roo'
require 'swedishgrid'
separator = "\t"
grid = SwedishGrid.new(:sweref99tm)
oo = Excel.new("Sverige - riskklass 1 o 2.xls")
@ashpool
ashpool / inspect.js
Created October 17, 2012 08:56
JavaScript inspection
var Inspect = {
TYPE_FUNCTION: 'function',
// Returns an array of (the names of) all methods
methods: function(obj) {
var testObj = obj || self;
var methods = [];
for (var prop in testObj) {
if (typeof testObj[prop] == Inspect.TYPE_FUNCTION && typeof Inspect[prop] != Inspect.TYPE_FUNCTION) {
methods.push
@ashpool
ashpool / sleepsort.sh
Created February 13, 2012 18:37
Sleepsort ;-)
#!/bin/bash
function f() {
sleep "$1"
echo "$1"
}
while [ -n "$1" ]
do
f "$1" &
shift
done
@ashpool
ashpool / knight.rb
Created February 12, 2012 17:14
The knight's tour is a mathematical problem involving a knight on a chessboard. The knight is placed on the empty board and, moving according to the rules of chess, must visit each square exactly once.
class Game
attr_accessor :board
def initialize(size)
@size = size
@board = Array.new(size)
end
def start(start_row, start_column)
first_move = Move.new(start_row, start_column, 0, @board)
@ashpool
ashpool / stripper.rb
Created February 12, 2012 16:51
Citerus challenge
class Stripper
def initialize(acronyms)
@stripCache = {}
@acronyms = acronyms
end
def strip(source)
return @stripCache[source] if @stripCache.has_key?(source)
result = source
@acronyms.each do |acronym|