Skip to content

Instantly share code, notes, and snippets.

@deltheil
deltheil / build-cfsm.sh
Last active August 29, 2015 14:03
cfsm - Finite State Machine compiler
# -------
# cfsm
# -------
# see: http://www.mindrot.org/projects/cfsm/
# Build (tested on Mac OS X 10.9.3)
cvs -d :ext:anoncvs@anoncvs.mindrot.org:/cvs checkout cfsm mtemplate
make -C mtemplate
make -C cfsm CPPFLAGS='-D_FORTIFY_SOURCE=0'
mkdir /usr/local/share/cfsm
@deltheil
deltheil / torch-svm.md
Created November 28, 2014 16:13
A quick'n'dirty work around to install koraykv/torch-svm

torch-svm

Here's a quick'n'dirty work around to install torch-svm:

Clone the repo

git clone git@github.com:koraykv/torch-svm.git && cd torch-svm
@deltheil
deltheil / jq.sh
Last active August 29, 2015 14:11
Use jq command-line JSON processor to filter out a nested hash. See also: https://github.com/stedolan/jq/wiki/jq%20Cookbook
# http://stedolan.github.io/jq/
json='{"foo": {"genre":"deep house"}, "bar": {"genre": "progressive house"}, "baz": {"genre": "dubstep"}}'
echo "$json" | jq '[to_entries | .[] | select(.value.genre | contains("house"))] | from_entries'
# {
# "bar": {
# "genre": "progressive house"
# },
# "foo": {
# "genre": "deep house"
@deltheil
deltheil / bubble.rb
Created October 27, 2010 12:43
Speech bubble PNG icon generator - mimicks the Facebook for iPhone comments toolbar button
require 'rubygems'
require 'Rmagick'
include Magick
# In pixels
SQUARE_SIZE = 20
CORNER = 2
SPIKE_OFFSET, SPIKE_WIDTH, SPIKE_HEIGHT = 7, 4, 6
@deltheil
deltheil / MSImageView.m
Created June 16, 2011 20:19
Three20 TTImageView always checks the in-memory cache *without* using any expiration age - this version solves this problem
#import "MSImageView.h"
#import <Three20Network/TTURLCache.h>
#import <Three20Network/TTURLImageResponse.h>
#import <Three20Network/TTURLRequest.h>
#import "MSGlobals.h"
@implementation MSImageView
@deltheil
deltheil / gist:1555692
Last active September 29, 2015 05:48
Print out the width x height of a given image via ImageMagick identify
# ImageMagick `identify` format features is handy
# e.g. to obtain the width x height of a given image (360x480)
#
# See http://www.imagemagick.org/script/escape.php
# for a complete list of supported format characters
identify -format "%wx%h" myimage.jpg
@deltheil
deltheil / gist:1601327
Created January 12, 2012 16:05
GCC - list all the macros defined during the execution of the preprocessor
# -E is for preprocessor only
# -dM tells GCC to generate a list of #define directives
# e.g.
# #define __APPLE__ 1
# #define __SSE2__ 1
# #define __GNUC__ 4
# ...
gcc -E -dM - < /dev/null
@deltheil
deltheil / gist:2644728
Created May 9, 2012 14:08
Use nslookup to check an MX record
$ nslookup
> set q=MX
> github.com
Server: 212.27.40.240
Address: 212.27.40.240#53
Non-authoritative answer:
github.com mail exchanger = 10 ALT1.ASPMX.L.GOOGLE.com.
...
@deltheil
deltheil / gist:2868896
Created June 4, 2012 15:04
Create a file of given size with random data
# `head -c bytes`
# e.g. for a 1kb file:
cat /dev/random | head -c 1024 > data.bin
@deltheil
deltheil / list.c
Created June 5, 2012 16:43
Manipulate lists of records the Redis way via Tokyo Cabinet B+ Tree database
#include <stdio.h>
#include <tcbdb.h>
#include <tcutil.h>
int main(int argc, char *argv[]) {
TCBDB *db = tcbdbnew();
tcbdbopen(db, "list.db", BDBOWRITER | BDBOCREAT | BDBOTRUNC);
/* The B+ Tree database features record duplication for a given key
(see `tcbdbputdup`) which means we can easily append data for a