Skip to content

Instantly share code, notes, and snippets.

@rampion
rampion / try-catch-ex.c
Created April 8, 2009 02:35
TRY/CATCH/FINALLY macros for C
// gcc -o try-catch-ex try-catch.c try-catch-ex.c
#include <stdio.h>
#include "try-catch.h"
// Example of use for try-catch.h
int main(int argc, char *argv[])
{
int i = 101;
printf("before try block...\n");
@jlao
jlao / MapPerf.scala
Created October 18, 2010 03:27
A simple performance test comparing the performance of java.util.HashMap, scala.collection.immutable.HashMap, scala.collection.mutable.HashMap.
import java.util.HashMap
object MapPerf {
def main(args: Array[String]) {
if ( args.length < 2 ) {
println("Usage: scala MapPerf <number of elements to insert> <num trials>")
return
}
@splorp
splorp / gist:776730
Created January 12, 2011 19:36
Preferences to disable local storage in Safari
# To disable Safari’s annoying modal local database
# storage dialog, use this Terminal command:
defaults write com.apple.Safari WebKitDatabasesEnabledPreferenceKey -bool false
# To disable local storage altogether, use this command:
defaults write com.apple.Safari WebKitLocalStorageEnabledPreferenceKey -bool false
@od0x0
od0x0 / gist:965399
Created May 10, 2011 21:17
How I Load a .ogg into OpenAL Using stb_vorbis
typedef struct{
ALuint ID;
stb_vorbis* stream;
stb_vorbis_info info;
ALuint buffers[2];
ALuint source;
ALenum format;
@zliuva
zliuva / gist:1084476
Last active July 20, 2024 14:26
A minimal Mach-o x64 executable for OS X
; A minimal Mach-o x64 executable for OS X (also see below Mountain Lion version)
;
; $ nasm -f bin -o tiny_hello tiny_hello.s
; $ chmod +x tiny_hello
; $ ./tiny_hello
; Hello World!
; $
; c.f.
; http://osxbook.com/blog/2009/03/15/crafting-a-tiny-mach-o-executable/ ( the original tiny mach-o executable )
@nrabinowitz
nrabinowitz / quantize.js
Created July 25, 2011 17:19
Javascript module for color quantization, based on Leptonica
/*!
* quantize.js Copyright 2008 Nick Rabinowitz.
* Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
*/
// fill out a couple protovis dependencies
/*!
* Block below copied from Protovis: http://mbostock.github.com/protovis/
* Copyright 2010 Stanford Visualization Group
* Licensed under the BSD License: http://www.opensource.org/licenses/bsd-license.php
@camillol
camillol / spaceutil.c
Created August 6, 2011 14:54
Two ways of messing with spaces
#include <unistd.h>
#include <CoreServices/CoreServices.h>
#include <ApplicationServices/ApplicationServices.h>
typedef int CGSConnection;
extern OSStatus CGSGetWorkspace(const CGSConnection cid, int *workspace);
extern OSStatus CGSSetWorkspace(const CGSConnection cid, int workspace);
extern CGSConnection _CGSDefaultConnection(void);
int get_space_id(void);
@mre
mre / bitonic_sort.cu
Last active May 16, 2024 16:41
Bitonic Sort on CUDA. On a quick benchmark it was 10x faster than the CPU version.
/*
* Parallel bitonic sort using CUDA.
* Compile with
* nvcc -arch=sm_11 bitonic_sort.cu
* Based on http://www.tools-of-computing.com/tc/CS/Sorts/bitonic_sort.htm
* License: BSD 3
*/
#include <stdlib.h>
#include <stdio.h>
\ FCP.F, version 1.3 by Ian Osgood iano@quirkster.com
\ A simple chess program written in ANS Forth.
\ Uses Core Extension words:
\ .( .R U.R <> U> ?DO ERASE FALSE NIP TO TRUE TUCK VALUE WITHIN \
\ Uses Exception words: CATCH THROW ABORT"
\ Uses Tools Extension words: [IF] [ELSE] [THEN]
\ Uses String words: TOLOWER /STRING
\ Uses Win32Forth utilities: ms@ CELL CELL- DEFER IS [DEFINED] [UNDEFINED]
\ Will use DEFER/IS/[IS] if available for board iterator and vectors.
@ayang
ayang / app.py
Created February 4, 2012 03:47
Tornado session manager use redis
class Application(tornado.web.Application):
def __init__(self):
tornado.web.Application.__init__(self, handlers, **settings)
self.db_session = db_session
self.redis = redis.StrictRedis()
self.session_store = RedisSessionStore(self.redis)
class BaseHandler(tornado.web.RequestHandler):