Skip to content

Instantly share code, notes, and snippets.

View JackStouffer's full-sized avatar
💭
I may be slow to respond. Email me.

Jack Stouffer JackStouffer

💭
I may be slow to respond. Email me.
View GitHub Profile
@JackStouffer
JackStouffer / get_odbc_schema.php
Created May 14, 2014 14:16
A simple script to get all tables and their schema from an odbc connection
<?php
$connection = odbc_connect("YOURCONNECTION", "", "");
$result = odbc_tables($connection);
$tables = array();
while (odbc_fetch_row($result))
{
if(odbc_result($result,"TABLE_TYPE")=="TABLE")
{
@JackStouffer
JackStouffer / mongo_to_dict.py
Created July 24, 2014 20:19
Turn a Mongoengine object in a json-ible dictionary
def mongo_to_dict(obj):
""" Turn a mongoengine object into a jsonible python object
"""
return_data = []
if isinstance(obj, db.Document):
return_data.append(("id", str(obj.id)))
for field_name in obj._fields:
@JackStouffer
JackStouffer / sortable_between_tabs.css
Last active August 29, 2015 14:04
jQuery UI Sortable Between Tabs
#sortable1 li, #sortable2 li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 120px; }
@JackStouffer
JackStouffer / autorotate.py
Created December 1, 2014 03:08
Fix the EXIF image rotation browser bug by rotating the image manually
from PIL import Image
def autorotate(path):
""" This function autorotates a picture based upon its EXIF data
because smartphones use a little used EXIF option to set the
rotation of an image rather than save the data in that orientation
"""
image = Image.open(path)
try:
@JackStouffer
JackStouffer / monthly_resample.py
Created December 22, 2014 16:03
Get Data Grouped By Month in Pandas
import pandas
import numpy
def resampled_data(query, date_col, target_col, period="M"):
""" Function that takes an sql query and returns the sum of a target column
by a period. Useful for getting monthly data
"""
df = pandas.read_sql(query, conn)
df.set_index(df[date_col], inplace=True)
@JackStouffer
JackStouffer / main.d
Last active August 29, 2015 14:22
example for bug report
import std.stdio;
import Dgame.Window;
import Dgame.Graphic;
import Dgame.System.StopWatch;
import Dgame.System.Font;
import Dgame.System.Keyboard;
interface Entity {
@JackStouffer
JackStouffer / ringbuffer.d
Created August 11, 2015 19:24
A simple ring buffer implementation in D with unit tests
import std.traits : isNumeric;
struct RingBuffer (T, uint buffer_length = 4) if (isNumeric!T) {
private T[buffer_length] buffer;
private T sum;
private byte lastIndex;
@safe @nogc nothrow pure {
this(const T initial_value) {
this.lastIndex = 0;
@JackStouffer
JackStouffer / quadtree.d
Created August 11, 2015 19:27
A Quadtree implementation in D with unit tests
import std.traits: hasMember;
/*
Quadtree implementation that allows the collision resolver
to only scan a small subset of the possible colliding objects
See Also:
http://gamedevelopment.tutsplus.com/tutorials/quick-tip-use-quadtrees-to-detect-likely-collisions-in-2d-space--gamedev-374
*/
struct Quadtree(T, uint MAX_OBJECTS = 10, uint MAX_LEVELS = 5) if (
@JackStouffer
JackStouffer / dmd.conf
Created September 4, 2015 19:15
My dmd conf
[Environment]
DFLAGS=-I%@P%/../../phobos -I%@P%/../../druntime/import -w -dip25 -m64 -g -debug -L%@P%/../../phobos/generated/osx/debug/64/libphobos2.a
################ Unified Information ################
Cores per CPU = 2
Threads per CPU = 4
------------------ TLB Information ------------------
Instruction TLB:
- - - - - ITLB1: - - - - - - - - - - - - - - - - - -
Page size = 4 KB
Pages count = 64
Pages count = 64
Associativity: 8-way associative