Skip to content

Instantly share code, notes, and snippets.

@nickjacob
nickjacob / asynchCaller.js
Created August 3, 2012 20:31
A little javascript that lets you setup calls to a script that you aren't sure has loaded yet. You could load this script in too
/**
* Sometimes you're working with a script hosted on a server that you can't be sure is going to ever return/you don't know when
* this script lets you make calls to the object it is eventually going to add to the window object before it's there.
* this is (probably) very similar to the code behind google analytic's _gaq.push()
*/
(function(watch_list,future_obj,interval){
var noop = function(){}, _func_ = 'function';
var __asynch = function(list,obj,intr){
this.intr=(typeof intr==='number') ? intr : 500;this.loop=null;this.obj = obj; this.calls = [];var self = this; list = list || [];
for(var i=0,l=list.length;i <l;i++) this.calls[i] = list[i];
@nickjacob
nickjacob / FileServing.php
Created July 27, 2012 17:44
Simple Static PHP File Serving
<?php
/**
* Simple File server for php
* this is in response to this:
* http://stackoverflow.com/questions/8792871/using-custom-url-rewrite-in-drupal-for-static-files
* ---
* in the process of using it I found a lot of places to refactor/clean it up, and correct some things
*/
define('CHUNK_SIZE',1048576);
@nickjacob
nickjacob / quicksortjs.md
Created July 13, 2012 17:36
Quicksort implemented in javascript

Quicksort in Javascript

Webkit's Array.sort() is implemented in c++ as selectionsort. For some variety (and a better time complexity in big arrays), I wrote up an implementation of quicksort:

Source:

(function(window){

	function quicksort(func){
// App.js
// the main logic of the application.
// this handles pretty much everything that goes on
// author: nickjacob
// generate faux-guid
function S4() { return (((1+Math.random())*0x10000)|0).toString(16).substring(1); };
function guid() { return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()); };
// actual app
var Express = require('express')
@nickjacob
nickjacob / autotest.sh
Created December 11, 2011 18:29
Shell script to automate testing of java compiler run w/ ant
#!/bin/bash
# author: nbjacob
OUTLINE="==========================================="
echo $OUTLINE
echo $OUTLINE
echo "STARTING AUTO TEST"
for a in ${@}; do
echo "TESTING DIR: $a"
for f in $(ls $a/*.bl); do
# read header of test
@nickjacob
nickjacob / str_to_bin.py
Created December 5, 2011 17:50
simple python script to convert string to binary ASCII with each character on a new line
def toBin(s):
# removes space characters, puts each ascii code on a new line
print "\n".join(filter(lambda x:x!="100000",[bin(ord(c))[2:] for c in s]))
if __name__ == "__main__":
s = input("enter a string: \n")
toBin(s)
# or: