Skip to content

Instantly share code, notes, and snippets.

View westphahl's full-sized avatar
😬
Whoops!

Simon Westphahl westphahl

😬
Whoops!
View GitHub Profile
# Evaluate prompt
setopt prompt_subst
# History config
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
# VIM key bindings
bindkey -v
# Key bindings for 'home' and 'end'
bindkey "^[[1~" beginning-of-line
epfd = epoll_create(1);
if (epfd == -1)
errExit("epoll_create");
ev.events = EPOLLIN;
ev.data.fd = sockfd;
epoll_ctl(epfd, EPOLL_CTL_ADD, sockfd, &ev);
ev.events = EPOLLIN;
ev.data.fd = STDIN_FILENO;
@westphahl
westphahl / signalblocker.py
Created July 22, 2015 17:40
context manager to block signals
import time
import signal
class SignalBlocker:
def __init__(self, signal):
self._signal = signal
self._signal_blocked = False
/* For reference see:
* http://www.franken-business.de/galileo-computing/c-von-a-bis-z/022_c_algorithmen_003.htm#mj925248949647af9ef7f16d215f433a8c
* http://www.algorithm-code.com/wiki/Insertion_sort#C_Code
*/
#include <stdio.h>
void insertion_sort(int arr[], int n) {
int i, j, x;
for (i = 1; i < n; i++) {
# setup.py
setup(
# [...]
version=__import__('example').__version__,
# [...]
)
# example/__init__.py
@westphahl
westphahl / gist:351974
Created April 1, 2010 15:53
Nginx config (uWSGI example)
# Stripped down Nginx config file for example.com
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
@westphahl
westphahl / gist:351959
Created April 1, 2010 15:40
Nginx Upstart script
# file: /etc/event.d/nginx
description "Nginx HTTP server"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /usr/sbin/nginx
@westphahl
westphahl / gist:360442
Created April 8, 2010 19:35
logrotate.d script for Nginx
/var/log/nginx/*.log {
daily
missingok
rotate 52
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
@westphahl
westphahl / gist:368358
Created April 16, 2010 12:33
Script for HS WLAN login
#!/bin/bash
# Usage: $./hs-wlan-login username
# Author: Simon Westphahl <westphahl@gmail.com>
# Required (Ubuntu): zenity, libnotify-bin, curl
if test -z "$1"
then exit
else
USERNAME=$1
@westphahl
westphahl / hash_mod_mult.py
Created June 15, 2010 11:16
Hash distribution for mult and mod
"""
Author: Simon Westphahl <westphahl@gmail.com>
Description: Testing hash distribution for multiplication and modulo.
"""
from math import sqrt, floor
text = "Loraem ipbsum dcolor sdit ameet cosetetur sadpscing eltr seed dgam nosumy eird temdfpor inidunt udft lbore edft dlore mgasdna aquyam eabrat stied dfiam volptua Atat veron eods eukt ascsam ennt jullsto duno dors ehfht eajt rbum Stimet citlla kabsd gbergren notre sklma tkitatta sanlicttus ermist Lopprem isrum dmuolor siast amppet"
word_list = text.split()