Skip to content

Instantly share code, notes, and snippets.

View kkleidal's full-sized avatar

Ken Leidal kkleidal

  • Genesis Therapeutics
  • Boston, MA
View GitHub Profile
@kkleidal
kkleidal / jquery.file.upload.js
Created August 5, 2014 22:42
jQuery AJAX File Upload
(function ($) {
var oldUpload = $.fn.upload;
jQuery.fn.upload = function( options ) {
if ( this.prop('tagName') !== "INPUT" || this.attr('type') !== 'file' ) {
throw new Error("Cannot call upload function for given element type. Only works for <input type='file' />");
}
var files = this.prop('files');
var defaultCallback = function() { };
@kkleidal
kkleidal / client.py
Created October 24, 2014 20:21
PyZMQ Basic Pub/Sub Interaction
import zmq
protocol = "tcp"
host = "tidmarsh.media.mit.edu"
port = "1305"
host = "127.0.0.1"
port = "5556"
# Socket to talk to server
@kkleidal
kkleidal / gitlog.sh
Created November 17, 2014 01:28
Convenient Git log
git log --oneline --graph --color --decorate --all
@kkleidal
kkleidal / Pair.java
Created November 28, 2014 22:40
Java Pair class
package util;
/**
* Creates a pair of two objects
*
* @param <T1> the type of object 1
* @param <T2> the type of object 2
*/
public class Pair<T1, T2> {
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
function wrapHTML(html) {
return "<!DOCTYPE html><html><body>" + html + "</body></html>\n";
}
function serveIndex(response, rootPath, localPath, cb) {
@kkleidal
kkleidal / pid.sh
Created January 6, 2015 15:30
PID of Process BASH
#!/bin/bash
# Get the PID of a process matching the pattern specified
# in the first argument as displayed in ps axf
# This line can be used in any script, just replace $1 with the match string:
PID=$(ps axf | grep "$1" | grep -v grep | awk '{print $1}' | head -n1)
echo "$PID"
@everywhere const exact = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092
@everywhere function approx_pi(n::Integer)
current_term = 0.5
sum = current_term
for i=1:n
current_term *= (2 * i) * (2 * i - 1) / (16 * i * i) * (2 * (i - 1) + 1) / (2 * i + 1)
sum += current_term
end
return 6 * sum
print "Hello world!"
@kkleidal
kkleidal / downloader.bash
Last active August 29, 2015 14:21
FileListDownloader
#!/bin/bash
DIR=$(pwd)
DELIMETER="\t"
DOWNLOADS_FILE=$1
DOWNLOAD_TO=$2
MY_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
PRIVATE_KEY=$MY_DIR/mitKeyStore.pem
@kkleidal
kkleidal / searchpdfs
Created May 18, 2015 18:39
Search text of pdfs in working directory
#!/bin/bash
# Based on http://stackoverflow.com/questions/4643438/how-to-search-contents-of-multiple-pdf-files
find $(pwd) -name '*.pdf' -exec sh -c "pdftotext '{}' - | grep --with-filename --label='{}' --color '$1'" \;