Skip to content

Instantly share code, notes, and snippets.

@jackmaney
jackmaney / node_fiddle_stdin.js
Created November 29, 2012 07:01
Node fiddling: event wrapper around STDIN reading
var events = require("events");
var util = require("util");
Writer = function(prefix)
{
if(typeof prefix === "undefined")
{
this.prefix = "";
}
else
@jackmaney
jackmaney / gist:4209323
Created December 4, 2012 22:06
jQuery fiddling: Grabbing the option that was selected in a <select>
<!doctype html>
<html>
<head>
<title>test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(
function() {
$("#clicky").click(function(evt) {
@jackmaney
jackmaney / tarball_test.py
Created August 23, 2013 21:41
Tarballing a directory in Python
import tarfile
dir = "/some/directory"
tar = tarfile.open(dir + "/some_file.tar.gz",'w:gz')
tar.add(dir + "/some_subdirectory",arcname='some_subdirectory')
tar.close()
@jackmaney
jackmaney / github_stars.js
Created August 26, 2013 22:57
Getting all starred repos
var https = require("https");
var util = require("util");
var output = "";
https.get("https://relevant.url.to.get.stars"
, function(res) {
res.on('data', function(d) {
output += d;
});
@jackmaney
jackmaney / subdomain_test.js
Created September 1, 2013 04:05
Finding subdomains via Node and Express
var express = require("express");
var app = express();
app.all("/",function(req,res){
res.writeHead(200,{"Content-Type":"text/plain"});
res.end(req.headers.host);
});
app.listen(3000);
@jackmaney
jackmaney / marked_test.html
Created September 12, 2013 10:26
Converting markdown in a textarea to HTML. Also uses the Tabby jQuery extension to allow tabs in textareas.
<!doctype html>
<html>
<head>
<title>Marked test</title>
<script type="text/javascript" src="js/marked.js"></script> <!-- https://github.com/chjj/marked -->
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="js/jquery.textarea.js"></script> <!-- https://github.com/alanhogan/Tabby -->
<script type="text/javascript">
$(document).ready(function(){
$("#blah").tabby();
@jackmaney
jackmaney / prime_sieve.hs
Created September 26, 2013 17:57
Prime number sieve as a single list comprehension
[n | n <- [2..100], [m | m <- [2..n-1], n `mod` m == 0] == []]
@jackmaney
jackmaney / gist:8016614
Created December 18, 2013 02:59
First example in the javaPlex tutorial...in Java (instead of Matlab)
import edu.stanford.math.plex4.api.Plex4;
import edu.stanford.math.plex4.homology.barcodes.BarcodeCollection;
import edu.stanford.math.plex4.homology.chain_basis.Simplex;
import edu.stanford.math.plex4.homology.interfaces.AbstractPersistenceAlgorithm;
import edu.stanford.math.plex4.streams.impl.ExplicitSimplexStream;
public class BasicHomology {
public static void main(String[] args) {
@jackmaney
jackmaney / gist:8201138
Last active January 1, 2016 21:08
Getting IPython and Pandas & Friends to Work Nicely on Windows

For the love of the gods, don't bother with pip on windows. Instead use this site, with freely-available Windows binaries for Python packages:

http://www.lfd.uci.edu/~gohlke/pythonlibs/

Installation order:

  • Python 2.7.6 (obviously first)
  • Zeromq
  • numpy-MKL
  • dateutil
@jackmaney
jackmaney / user_agent.js
Created April 2, 2014 18:16
Server-side UA Sniffing to Detect Browser
var express = require('express');
var uaParser = require('ua-parser')
var app = express();
app.get('/', function(req,res){
var r = uaParser.parse(req.headers['user-agent']);
res.status(200).send(r.ua.family);
})