Skip to content

Instantly share code, notes, and snippets.

View wolph's full-sized avatar

Rick van Hattem wolph

View GitHub Profile
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Threading;
using System.Runtime.InteropServices;
@wolph
wolph / quicksort_y_combinator_lambda_calculus.py
Created August 19, 2015 11:44
Quicksort using the Y Combinator (lambda calculus) in pure Python
# Quicksort using the Y Combinator (lambda calculus) in pure Python
>>> Y = lambda f: lambda *args: f(Y(f))(*args)
>>> quicksort = Y(lambda f:
... lambda x: (
... f([item for item in x if item < x[0]])
... + [y for y in x if x[0] == y]
... + f([item for item in x if item > x[0]])
... ) if x else [])
@wolph
wolph / eventghost_domoticz.py
Created September 13, 2015 17:47
Example script to access domoticz from eventghost, I'll make this in a plugin somewhere in the future :)
LIGHT_ID = 123
LIGHT_LEVEL = 40
DOMOTICZ_URL = 'http://domoticz/json.htm?'
def fetch(**kwargs):
import json
import urllib
params = urllib.urlencode(kwargs.items())
url = DOMOTICZ_URL + params
@wolph
wolph / replace.zsh
Created September 23, 2015 10:18
Regular expression (Perl pie) to search and replace Django STATIC_URL with the static (from staticfiles) templatetag
perl -pi -e 's/"\{\{\s*STATIC_URL\s*\}\}\/?([^"]+)"/"{% static \x27$1\x27 %}"/g' templates/***/*.html
@wolph
wolph / clean-merged-branches.sh
Created January 13, 2012 06:58
clean-merged-branches
#!/bin/sh
#/ Usage: clean-merged-branches [-f]
#/ Delete merged branches from the origin remote.
#/
#/ Options:
#/ -f Really delete the branches. Without this branches are shown
#/ but nothing is deleted.
#/ -n Dry-run, only show what would be removed.
set -e
@wolph
wolph / .gitconfig
Created July 23, 2012 13:47
Global git garbage collect
[alias]
global-gc = !git-global-gc.sh
@wolph
wolph / sparql.py
Created October 25, 2012 13:36
Ontology Engineering Sesame Wrapper
#!/usr/bin/env python
import os
import sys
import subprocess
import fileinput
os.chdir(os.path.dirname(__file__))
process = subprocess.Popen(
@wolph
wolph / test.c
Last active December 15, 2015 12:19
Passing functions in C with function return type casting
#include <stdio.h>
int a(){
return 42;
}
double b(){
return 3.141592653589793;
}
@wolph
wolph / proxy.py
Created July 14, 2013 16:14
Gevent based proxy server for non http compliant webserver
from gevent.local import local
from gevent.pywsgi import WSGIServer
from gevent import monkey
import socket
import pprint
import sys
def application(environ, start_response):
url = environ['PATH_INFO']
@wolph
wolph / y_combinator_quicksort.py
Created May 30, 2016 21:06
Implementing the Quick sort algorithm using the Y Combinator
Y = lambda f: lambda *args: f(Y(f))(*args)
quicksort = Y(lambda f:
lambda x: (
f([item for item in x if item < x[0]])
+ [y for y in x if x[0] == y]
+ f([item for item in x if item > x[0]])
) if x else [])