Skip to content

Instantly share code, notes, and snippets.

View Luit's full-sized avatar

Luit van Drongelen Luit

View GitHub Profile
@Luit
Luit / shortener.vcl
Created December 1, 2011 11:03
A very ugly first version of a URL shortening service written in VCL inline C. There's a whole lot still to be done, but this thing works quite well already.
C{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <hiredis/hiredis.h>
}C
sub vcl_recv {
if (req.http.host ~ "(?i)^a.luit.it$") {
if (req.url ~ "(?i)^/l/.*[A-Za-z0-9\-_]{4,}\+?$") {
@Luit
Luit / reconnect.patch
Created December 4, 2011 14:33
A simple patch to fix libvmod-redis from completely halting to function after redis-server closes the connection
diff --git a/src/vmod_redis.c b/src/vmod_redis.c
index b59652b..7c0544e 100644
--- a/src/vmod_redis.c
+++ b/src/vmod_redis.c
@@ -81,6 +81,18 @@ redis_common(struct sess *sp, struct vmod_priv *priv, const char *command)
}
reply = redisCommand(c, command);
+ if (c->err == REDIS_ERR_EOF) {
+ // It seems Redis has disconnected the client, let's try to
@Luit
Luit / default.vcl
Created December 4, 2011 19:40
A much better version of a URL shortening service in VCL. It now uses libvmod-redis and works similar to the ugly Inline C VCL.
import redis;
sub vcl_recv {
if (req.url ~ "^/[lL]/[A-Za-z0-9\-_]{4,32}=?=?$") {
set req.http.New-Location = redis.call(regsub(req.url, "^/[lL]/([A-Za-z0-9\-_]{2})([A-Za-z0-9\-_]{2,30}=?=?)$", "HGET short:\1 \2"));
if (req.http.New-Location) {
error 666;
}
error 404 "Not Found";
}
@Luit
Luit / default.vcl
Created December 4, 2011 22:14
A variation on the libvmod-redis based URL shortener, now doing a curveball to make the redirect cacheable.
import redis;
backend default {
.host = "127.0.0.1";
.port = "8080";
}
backend self {
.host = "127.0.0.1";
.port = "80";
@Luit
Luit / gist:4244643
Created December 9, 2012 12:23
What the hell, Chromium!?
luit@xps14:~$ free -m # My laptop feels sluggish
total used free shared buffers cached
Mem: 3836 3644 191 0 10 498
-/+ buffers/cache: 3135 701
Swap: 8190 1031 7159
luit@xps14:~$ free -m # I think it's Chromium, let's shut that thing down
total used free shared buffers cached
Mem: 3836 1246 2589 0 12 426
-/+ buffers/cache: 808 3028
Swap: 8190 337 7853
#!/usr/bin/env python
import datetime
import twitter
OAUTH_T = '' # You can't have my OAuth secrets
OAUTH_TS = ''
OAUTH_CK = ''
OAUTH_CS = ''
@Luit
Luit / utils.go
Last active December 24, 2015 23:49
package utils
func Slugify(title string) string {
var slug []byte
for _, x := range title {
switch {
case ('a' <= x && x <= 'z') || ('0' <= x && x <= '9'):
slug = append(slug, byte(x))
case 'A' <= x && x <= 'Z':

Keybase proof

I hereby claim:

  • I am Luit on github.
  • I am luit (https://keybase.io/luit) on keybase.
  • I have a public key whose fingerprint is 52BD 2314 CA93 839B 2A50 1397 984B E3B2 71A8 8C47

To claim this, I am signing this object:

@Luit
Luit / kseD.ino
Last active August 29, 2015 14:16
// kinda smart ergonomic Desk, or kseD for short, is a project to make my
// no-frills ergonomic desk a bit more special.
/*
Serial commands:
E <upper> <lower>
Read value from EEPROM (might disappear once testing is done)
G <upper> <lower>
@Luit
Luit / .bashrc-snippet
Last active August 29, 2015 14:27
check_docker_memory function
function check_docker_memory {
for id in $(docker ps -q --no-trunc); do
name=$(docker inspect -f "{{.Name}}" $id)
echo $(numfmt --to=iec --suffix=B $(cat /sys/fs/cgroup/memory/system.slice/docker-$id.scope/memory.usage_in_bytes)) ${name#/}
done
}