Skip to content

Instantly share code, notes, and snippets.

View shelling's full-sized avatar

shelling shelling

View GitHub Profile
@shelling
shelling / singleton.py
Created June 21, 2011 03:05
Singleton in Python
#!/usr/bin/env python
class Hello(object):
singleton = None
def __new__(clz):
if not clz.singleton:
clz.singleton = object.__new__(clz)
return clz.singleton
@shelling
shelling / foreach.el
Created April 12, 2011 05:48
foreach in elisp
#!/usr/bin/env emacs --script
(require 'cl)
(defun foreach (alist func)
(while alist
(progn
(funcall func (car alist))
(setq alist (cdr alist)))
))
@shelling
shelling / a.el
Created April 10, 2011 16:54
recursive *.el loader
#!/usr/bin/env emacs --script
(require 'cl)
(defun show-string-list (l)
(message
(mapconcat (lambda (s) (concat s "\n")) l "")))
(defun show-pack (s)
(file-name-nondirectory (replace-regexp-in-string "\\.el$" "" s)))
@shelling
shelling / hello-eventmachine.rb
Created April 10, 2011 14:36
hello EventMachine
#!/usr/bin/env ruby
#-*- mode: ruby -*-
require 'rubygems'
require "eventmachine"
require "evma_httpserver"
class EchoServer < EM::Connection
include EM::HttpServer
@shelling
shelling / load.sh
Created April 9, 2011 06:14
recursive rcfile loader
# vim: syntax=sh
#
function load {
if [ -f $1 ]; then
source $1
fi
if [ -d $1 ]; then
for file in $1/*; do
load $file
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
void print_array( int* array, int size ) {
printf("[");
for ( int i = 0; i < size; i++ ) {
printf("\"%d\"", array[i]);
if ( i < size-1 ) { printf(", "); }
}
@shelling
shelling / qsort.c
Created March 22, 2011 15:38
quick sort
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int* intcat( int* a1, int size1, int* a2, int size2 ) {
int *result = malloc((size1+size2)*sizeof(int));
int *iter = result;
for ( int i = 0; i < size1; i++ ) { *iter++ = *a1++; }
for ( int i = 0; i < size2; i++ ) { *iter++ = *a2++; }
return result;
@shelling
shelling / test.c
Created March 22, 2011 12:59
using qsort() in stdlib.h
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
void print_array( int* array, int size ) {
printf("[");
for ( int i = 0; i < size; i++ ) {
printf("\"%d\"", array[i]);
if ( i < size-1 ) { printf(", "); }
}
/*
Modification of Paul Bourkes FFT code by Peter Cusack
to utilise the Microsoft complex type.
This computes an in-place complex-to-complex FFT
x and y are the real and imaginary arrays of 2^m points.
dir = 1 gives forward transform
dir = -1 gives reverse transform
*/
void FFT(int dir, long m, complex <double> x[])
@shelling
shelling / tsn.srt
Created March 5, 2011 08:05
The Social Network subtitle
1
00:00:04,829 --> 00:00:09,829
Credit to: Sakti Tandi [1st Indonesian-Script]
English. Subs. and. Re-Sync. by npdv-iD
2
00:00:19,043 --> 00:00:21,168
You know there are more people
with genius IQ living in China