Skip to content

Instantly share code, notes, and snippets.

View boukeversteegh's full-sized avatar

Bouke Versteegh boukeversteegh

View GitHub Profile
@boukeversteegh
boukeversteegh / pipehttp.py
Created November 20, 2012 18:58
Pipe data to webserver
import BaseHTTPServer
import sys
server_host = 'localhost'
server_port = 8744
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_HEAD(s):
s.send_response(200)
s.send_header("Content-type", "text/html")
require_once 'wopr.php';
$settings = array(
'host' => 'localhost',
'port' => 1981,
);
$wopr = new WOPR($settings['host'], $settings['port']);
$wopr->connect();
<style>
td {
padding: 4px;
}
input {
width: 100%;
display: block;
border: 1px inset #EEE;
margin: -1px;
}
# Given a position (x,y), returns next position in a grid spiral.
def next(pos):
x, y = pos
top = False
right = False
bottom = False
left = False
horizontal = abs(x) <= abs(y)
vertical = abs(y) <= abs(x)
import multiprocessing
# Define a function
square = lambda x: x**2
if __name__ == "__main__":
mylist = [1, 2, 3, 4, 9, 2, 5, 2, 7, 0, 5, 4, 1, 3, 5, 7]
# Create a pool with 8 multicore threads
# Apply the function to all arguments in the list
class Gate {
protected:
Out outputs[];
public:
virtual void propagate();
};
void Gate::propagate() {
int noutputs = sizeof(this->outputs)/sizeof(*(this->outputs));
cout << noutputs << " outputs.";
@boukeversteegh
boukeversteegh / functionalprogramming.py
Last active December 17, 2015 02:09
How to do functional programming in Python
import inspect
# Callable class to wrap functions
class F:
def __init__(self, func, *args):
self.func = func
self.args = args
# Currying
@boukeversteegh
boukeversteegh / gist:5849167
Created June 24, 2013 10:29
Bookmarklet to switch EN/NL on wikipedia
javascript:document.location = $('[href^="//' + ['nl', 'en'][0+(document.location.host.substr(0,2)=="nl")] + '.wikipedia.org"]').attr('href');
<?php
abstract class DefaultController {
public function read($id) {
if( empty($id) ) {
throw Exception("No ID specified!");
}
$this->_read($id);
}
public abstract function _read($id);
@boukeversteegh
boukeversteegh / BADPS.md
Last active November 7, 2015 16:53
[DRAFT] Bitcoin Address Discovery Protocol over SMS

Bitcoin Address Discovery Protocol over SMS


Title:   Bitcoin Address Discovery Protocol over SMS
Author:  Bouke Versteegh <info@boukeversteegh.nl>
Status:  Draft
Created: 2014-03-14