Skip to content

Instantly share code, notes, and snippets.

  1. General Background and Overview
import static com.google.common.io.Closeables.closeQuietly;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@irr
irr / evhttp-multh-thread-httpd.cpp
Created September 24, 2012 18:50 — forked from kzk/evhttp-multh-thread-httpd.cpp
Multi-Threaded HTTPServer using evhttp
#include <event.h>
#include <evhttp.h>
#include <pthread.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <iostream>
@irr
irr / evserver.c
Created September 24, 2012 12:49 — forked from krikulis/evserver.c
Simple evhttp example
#include <evhttp.h>
void process_request(struct evhttp_request *req, void *arg){
struct evbuffer *buf = evbuffer_new();
if (buf == NULL) return;
evbuffer_add_printf(buf, "Requested: %s\n", evhttp_request_uri(req));
evhttp_send_reply(req, HTTP_OK, "OK", buf);
}
int main () {
@irr
irr / server.ls
Created September 21, 2012 17:15 — forked from santoshrajan/server.ls
A LispyScript Server example with nodejs, expressjs, twitter bootstrap
;; http://lispyscript.com
;; LispyScript example using nodejs, expressjs and twitter bootstrap
;; LispyScript templates are written in LispyScript!
;; Html5 templates support all html5 tags
;; The express server
(var express (require "express"))
(var app (express))
(app.listen 3000)
@irr
irr / lxc_stuff.sh
Created August 23, 2012 01:42 — forked from gleicon/lxc_stuff.sh
lxc general config
apt-get install lxc
lxc-create -n meh -t debian (takes some time)
echo "none /sys/fs/cgroup/ cgroup rw,cpuset,cpu,cpuacct,memory,devices,freezer 0 2" >> /etc/fstab
mount -a
lxc-start -n meh -d
lxc-list -n meh
lxc-cgroup -n meh cpu.shares
lxc-cgroup -n meh memory.limit_in_bytes
@irr
irr / a.c
Created May 25, 2012 10:30 — forked from jokea/a.c
fork+multithreaded+jemalloc = deadlock?
# cat a.c
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include "zmalloc.h"
void *worker(void *arg) {
int j;
char *p;
@irr
irr / example-user.js
Created May 4, 2012 12:20 — forked from nijikokun/example-user.js
Beautiful Validation... Why have I never thought of this before?!
var user = {
validateCredentials: function (username, password) {
return (
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' }
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' }
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' }
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' }
: (!/^([a-z0-9-_]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' }
: false
);
@irr
irr / gist:2593581
Created May 4, 2012 09:28 — forked from keimlink/gist:831633
Startup script for the Supervisor server (RHEL)
#!/bin/bash
#
# Startup script for the Supervisor server
#
# Tested with Red Hat Enterprise Linux Server release 5.5
#
# chkconfig: 2345 85 15
# description: Supervisor is a client/server system that allows its users to \
# monitor and control a number of processes on UNIX-like \
# operating systems.
@irr
irr / v6hex.erl
Created March 13, 2012 13:50 — forked from jj1bdx/v6hex.erl
v6hex.erl: an example module for IPv6-address tuple to hex string conversion
%% v6hex.erl:
%% IPv6-address tuple to hex string conversion
%% by Kenji Rikitake
%% MIT license (see the end of this module)
-module(v6hex).
-export([v6hex/1,
v6hex_revarpa/1,
v6hex_addr/1,