Skip to content

Instantly share code, notes, and snippets.

View tinybike's full-sized avatar

Jack Peterson tinybike

  • Merica
View GitHub Profile
# Fun with sequential differences
# @author [email protected]
# Recursion (hideous...or maybe I'm just bad at it)
function seqdiff!(x; top=NaN, differences=[])
if isempty(x)
return [0, differences], sum(differences)
end
if isnan(top)
top = pop!(x)
@tinybike
tinybike / mssql_to_csv.py
Last active October 22, 2023 18:12
simple mssql -> csv file example using pymssql
#!/usr/bin/env python
"""
simple mssql -> csv file example using pymssql
@author [email protected]
"""
import csv
import datetime
import pymssql
from decimal import Decimal
@tinybike
tinybike / Resourceful.m
Last active August 29, 2015 14:05
'game of life' where aging is an emergent property of resource limits
% Resourceful.m
% A 'game of life' where aging is an emergent property of resource limits.
% (c) Jack Peterson ([email protected]), 4/21/2012
% Setup:
% A single type of organism with a single resource type.
% Things live on an env_size x env_size grid.
% env is the environmental grid.
% haz is the hazards grid. Each time step, there is a probability haz(i,j)
% that an organism living at tile (i,j) will be killed.
@tinybike
tinybike / AutoFilter.m
Created August 22, 2014 19:45
estimates the autoregression kernel of a noisy input signal using a low-pass filter
% AutoFilter.m
% Estimates the autoregression kernel of a noisy input signal
% using a simple low-pass filter.
% (c) Jack Peterson ([email protected]), 2011
% Variable definitions:
% tests: number of different corrupted signals to analyze
% its: maximum filter power to test on each signal
% noisemax: number of different noise levels to test
% nstd: standard deviation of white noise
@tinybike
tinybike / trader.py
Created August 22, 2014 19:50
simple agent-based model of a financial market
#!/usr/bin/env python
"""
A simple agent-based model of a financial market.
(c) Jack Peterson ([email protected]), 2012
"""
from __future__ import division
from random import random, shuffle
import pylab as p
from collections import Counter
@tinybike
tinybike / AFTree.m
Created August 22, 2014 19:53
anti-ferromagnetic-like model for tree growth
% AFTree.m
% "Anti-ferromagnetic" model for tree growth
% (c) Jack Peterson ([email protected]), 2011
% Define an NxN grid (T), with each grid point big enough to hold one tree.
% Each element T(i,j) = 1 if there a tree has randomly started to grow
% there, and T(i,j) = 0 otherwise.
N = 100;
T = round(rand(N));
@tinybike
tinybike / licorify.m
Created August 22, 2014 19:57
convert .81x licor files into matlab structures
function licor = licorify(filename)
%% licorify.m converts .81x Licor files into a Matlab structure (licor),
% which is organized as follows:
%
% - licor.headers: Structure containing the 31-row header block from the .81x
% file; i.e., the 'TSource' data is stored in licor.headers.TSource
%
% - licor.footers: Structure containing the 23-row footer block, organized in
% the same way as licor.headers
%
@tinybike
tinybike / randarbmulti.m
Created August 22, 2014 20:02
random numbers from arbitrary probability distribution functions
function f = randarbmulti(x,y,N)
% RANDARBMULTI generates N random numbers from an arbitrary PDF, defined by
% vectors x and y. Modified from randarb.m (Dave Dykes) at:
% http://www.mathworks.com/matlabcentral/fileexchange/6506-obs-from-arbitrary-pdf
%
% (c) Jack Peterson ([email protected]), 4/21/2013
cdf_y = cumsum(y);
sum_y = sum(y);
@tinybike
tinybike / postback.php
Created August 29, 2014 01:06
Authorize.Net transaction postback handler
<?php
/**
* Example Authorize.Net transaction postback handler.
* Writes transaction records to a MySQL database.
*
* Uses the Authorize.Net PHP SDK, which can be found at:
* https://github.com/AuthorizeNet/sdk-php
*
* Example HTML form:
*
@tinybike
tinybike / wordcount.py
Last active August 29, 2015 14:05
parse a text file and count the occurrences of words in the file
#!/usr/bin/env python
"""
parse a text file and count the occurrences of words in the file
@author Jack Peterson ([email protected])
"""
import sys
import math
import sqlite3
def wordcount(data):