Skip to content

Instantly share code, notes, and snippets.

@gamefreak
gamefreak / gist:1901886
Created February 24, 2012 16:31
commentify
nmap <silent> <leader>/ :call Commentify()<cr>
vmap <silent> <leader>/ :call Commentify()<cr>
"Commentify config
if !exists("b:commentType")
let b:commentType="#"
endif
augroup Commentify
#! /usr/bin/python
from os import system as s
import sqlite3,datetime
s('rm -f ./test.sqlite');
conn = sqlite3.connect('test.sqlite');
c = conn.cursor();
c.execute('CREATE TABLE foo(bar STRING PRIMARY KEY, baz STRING,bin);');
c.execute('CREATE INDEX index_bar ON foo(bar);');
c.execute('CREATE INDEX index_baz ON foo(baz);');
console.time('creation');
var array = [];
for (var i = 0; i < 100000; i++) {
array.push({i:i});
}
console.timeEnd('creation');
console.group('for index');
@gamefreak
gamefreak / Makefile
Created December 1, 2011 16:17
RES Makefile prototype
LINK = ln -f
BUILD_DIR = ./build
MODULE_DIR = ./lib
RES_FILE = reddit_enhancement_suite.user.js
MODULES = $(MODULE_DIR)/$(RES_FILE)
BUILT_FILE = $(BUILD_DIR)/$(RES_FILE)
- (id)initWithResArchiver:(ResUnarchiver *)coder {
if (self) {
[coder skip:1u];//type
reflexive = (BOOL)[coder decodeSInt8];
[inclusiveFilter setHex:[coder decodeUInt32]];
[exclusiveFilter setHex:[coder decodeUInt32]];
owner = [coder decodeSInt16];
delay = [coder decodeSInt32];
subjectOverride = [coder decodeSInt16];
directOverride = [coder decodeSInt16];
@gamefreak
gamefreak / gist:1261559
Created October 4, 2011 12:48
Pixel Magnitude function
#define SLICE(value, shift) (int16_t)((value & (0xff << shift)) >> shift)
static inline uint32_t pixel_magnitude(uint32 pixel, uint32 color) {
int16_t r = SLICE(pixel, 24) - SLICE(color, 24);
int16_t g = SLICE(pixel, 16) - SLICE(color, 16);
int16_t b = SLICE(pixel, 8) - SLICE(color, 8);
return (r*r+g*g+b*b);
}
#undef SLICE
@gamefreak
gamefreak / gist:1261537
Created October 4, 2011 12:40
Failed MMX attempt.
static uint32_t pixel_magnitude(uint32 pixel, uint32 color) {
_m_empty();
__m64 null_ = _m_from_int(0x00000000);
__m64 pixel_ = _m_from_int(pixel);
pixel_ = _mm_unpacklo_pi8(pixel_, null_);
__m64 color_ = _m_from_int(color);
color_ = _mm_unpacklo_pi8(color_, null_);
pixel_ = _mm_sub_pi16(color_, pixel_);
pixel_ = _mm_madd_pi16(pixel_, pixel_);
color_ = _mm_srli_si64(pixel_, 32);
@gamefreak
gamefreak / pictdecoder.cpp
Created October 1, 2011 22:16
Partial PICT decoder for eventual use in Athena
//
// main.cpp
// pictdecoder
//
// Created by Scott McClaugherty on 9/30/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#include <iostream>
#include <fstream>
//gcc -framework Cocoa ./hdsize.m && ./a.out
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
const int width = 100+75;
const int height = 400000+100;
CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(NULL, width, height, 5, 2 * width, cs, kCGImageAlphaNoneSkipFirst);
CGContextSetRGBFillColor(ctx, 0.0f, 0.0f, 0.0f, 1.0f);
@gamefreak
gamefreak / gist:1180877
Created August 30, 2011 13:31
Athena command line options
Athena --base/file [--force-dl] [-l/--list] [-c/--check] [--format ares/xsera/lua/dump/antares outfile]
Conversion:
infile: optional may use base data, may need retrieve from web [forceable]
outformat
ares
xsera
lua
antares
dump