Skip to content

Instantly share code, notes, and snippets.

View ctbarna's full-sized avatar

Chris Barna ctbarna

View GitHub Profile
@ctbarna
ctbarna / rotator.js
Created April 6, 2011 18:10
A simple image rotator I wrote because I don't have admin access in CommonSpot. Images are grabbed from the srcID selector in a custom page then rotated through targetDiv on a target page depending on the day of the year. Functionality is kind of hacky be
/**
* rotator.js
* @author Chris Barna <[email protected]>
* Rotate images based on the date.
**/
// Variables
var url = "rotation.cfm";
var srcID = "#cs_control_9951781";
var customPanelDivs = new Array("#cs_control_9963945", "#cs_control_9963960");
@ctbarna
ctbarna / conditionally-load-jquery.js
Created April 13, 2011 18:22 — forked from benbalter/conditionally-load-jquery.js
Conditionally load jQuery (with slight version independence). Not expecting the API to change a whole lot in the sub-versions.
//Conditionally load jQuery
//inspired by http://www.smashingmagazine.com/2010/05/23/make-your-own-bookmarklets-with-jquery/
window.onload = function () {
if (typeof jQuery == 'undefined') {
var jQ = document.createElement('script');
jQ.type = 'text/javascript';
jQ.onload = jQ.onreadystatechange = myOnLoadEvent;
jQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js';
document.body.appendChild(jQ);
@ctbarna
ctbarna / ga-ext.js
Created April 27, 2011 18:07
Track External Links with Google Analytics
var gaParentDiv = ""; // Only change links in this selector including trailing space.
var trackingBase = "/ext/";
$(parentDiv+"a[href^=http\\:\\/\\/]:not(a[href*=\\/"+document.domain+"])").click(function () {
pageTracker._trackPageview(trackingBase+$(this).attr("href"));
});
@ctbarna
ctbarna / fdny_response_time.rb
Created August 22, 2011 17:05
Parse FDNY response time.
# Parse the FDNY average response time into JSON.
require 'rubygems'
require 'csv'
require 'json'
FILE = '../../Data/FDNY_monthly_response_time_001.TXT'
# Read the data
data = CSV.read(FILE, :col_sep => "\t",
:headers => true, :write_headers => false)
@ctbarna
ctbarna / amazon.rb
Created August 30, 2011 20:41
A little script I wrote to download images from Amazon.
# Download book covers from Amazon.
# Requires asin gem.
require 'net/http'
require 'asin'
client = ASIN::Client.instance
# Images Folder
IMG_DIR = ""
# API credentials
# Shell script to install PARI/GP
VERSION=2.5.0
URL=http://pari.math.u-bordeaux.fr/pub/pari/unix/pari-$VERSION.tar.gz
DATE=`date +%s`
# Credit to http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
DIR="$( cd "$( dirname "$0" )" && pwd )"
mkdir $DIR/tmp$DATE
cd $DIR/tmp$DATE

Installing PARI/GP on Mac

Prerequisites

  • Apple Developer Tools
    • Note: this is like 2GB. You might be better off simply installing the gcc compiler from here. I actually have no idea if this will work but if somebody is brave enough to try, that'd be awesome.
  • Slight knowledge of the command line (or at least a little bravery and some faith).
@ctbarna
ctbarna / hw4prob1.r
Created May 12, 2012 20:21
2d Ising Model
# hw4prob1.r
# 2d ising model
hamiltonian <- function (E, J, sig, N) {
nearest_neighbor_sum = sum(sig[1:N-1,]*sig[2:N,], sig[,1:N-1]*sig[,2:N])
return(-E * nearest_neighbor_sum - J * sum(sig))
}
ising <- function (E, J, N, beta, iterations) {
number = N*N
Number::toPaddedString = (radix, digits=2) ->
str = this.toString(radix)
while str.length < digits
str = "0" + str
str
@ctbarna
ctbarna / interpolator.coffee
Created August 2, 2012 02:05
Coffeescript Color Interpolator
root = exports ? window
Number::toPaddedString = (radix, digits=2) ->
str = this.toString(radix)
while str.length < digits
str = "0" + str
str