Skip to content

Instantly share code, notes, and snippets.

View julianwachholz's full-sized avatar
🤓

Julian Wachholz julianwachholz

🤓
View GitHub Profile
%% Erlang Programming, exercise 4-2
%%
%% A variant where the message is passed M times around.
%%
-module (ring).
-compile(export_all).
%% N processes in a ring pass around Message a total of M times.
start(N, Message, M) ->
@julianwachholz
julianwachholz / chroot.sh
Created December 12, 2014 10:42
Autoinstall ArchLinux on a existing OS
#!/bin/sh -e
ARCH_VERSION="2014.12.01"
ARCH_FILE="archlinux-bootstrap-$ARCH_VERSION-x86_64.tar.gz"
ARCH_BOOTSTRAP="http://archlinux.mirrors.ovh.net/archlinux/iso/$ARCH_VERSION/$ARCH_FILE"
ARCH_SUMS="http://archlinux.mirrors.ovh.net/archlinux/iso/$ARCH_VERSION/sha1sums.txt"
# download bootstrap image
cd /tmp
wget $ARCH_BOOTSTRAP
jwa ~> dig A ju.io
; <<>> DiG 9.8.3-P1 <<>> A ju.io
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39104
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;ju.io. IN A
@julianwachholz
julianwachholz / int2bytes.coffee
Created January 29, 2015 14:56
Ever needed to convert integers to bytes and back in javascript?
INT_BYTES = 8 # but note that javascript only does 2^53
int2bytes = (x) ->
if x > Number.MAX_SAFE_INTEGER
throw new Error "Number is larger than Number.MAX_SAFE_INTEGER (2⁵³-1)!"
bytes = []
i = INT_BYTES
loop
bytes[--i] = x & 0xff
@julianwachholz
julianwachholz / migration.py
Last active August 29, 2015 14:17
Django migration from `time without time zone` to `timestamp with time zone`
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('offers', '0001_initial'),
@julianwachholz
julianwachholz / views.py
Created May 4, 2015 11:10
Python/Django written by a PHP developer
def tadastaffregister(request):
if request.method == "POST":
start_date = request.POST['start_date']
end_date = request.POST['end_date']
result = []
date = 0
staff_member = []
staff = []
list_item = []
total = 0
@julianwachholz
julianwachholz / megagon.js
Created July 8, 2015 09:16
Generates a Megagon SVG
#!/usr/bin/env node
'use strict';
var size = 10000;
var sides = 1000000;
var padding = 50;
var path = polygon(size / 2 + padding, size / 2 + padding, size / 2, sides)
.map(function (p) { return p.x + ',' + p.y; })
.join(' ');
#!/usr/bin/env node
/*
* Bullshit Bingo Bot.
* 1) Fix the configuration to your liking and run
* 2) Use "!bullshit" and the word you want on the pile
* 3) ????
* 4) BINGO!
*
* Send complaints, cheques or anthrax to privacymyass@gmail.com.
@julianwachholz
julianwachholz / autoloader.php
Created October 7, 2011 19:53
A namespace based autoloader
<?php
spl_autoload_register(function($class)
{
$path = str_replace('\\', DIRECTORY_SEPARATOR, $class);
// Convert the PascalCased names to snake_case
$path = preg_replace('/([a-z])([A-Z](?![A-Z]))/', '$1_$2', $path);
$path = strtolower($path);
$path = LIB_PATH . '/' . $path . '.php';
<?php
namespace Feature\Testing\Annotations;
/* *
* This script does not yet belong to the FLOW3 framework. *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* *