Skip to content

Instantly share code, notes, and snippets.

View joshmarlow's full-sized avatar

Josh Marlow joshmarlow

View GitHub Profile
@joshmarlow
joshmarlow / gist:4001898
Created November 2, 2012 15:08
Playing with ast, matplotlib and networkx
import ast
import pprint
import networkx as nx
import matplotlib.pyplot as plt
class viz_walker(ast.NodeVisitor):
def __init__(self):
self.stack = []
@joshmarlow
joshmarlow / gist:4001910
Created November 2, 2012 15:10
Random file for playing with ast
def f3(x):
return 3*x
def f4(x):
return 4*x
def f2a(x):
return 2*f3(x)
def f2b(x):
@joshmarlow
joshmarlow / defun-wrapped-error
Last active August 29, 2015 14:17
defun wrapper to assist newbies in debugging
(defparameter defun-super-debug t)
(defmacro defun-wrapped-error (name vars &rest body)
"
A wrapper around defun that will catch any error and note which function it comes from before
re-raising the error.
"
`(defun ,name ,vars
(handler-case
(progn
@joshmarlow
joshmarlow / ambition_api_curl_example.sh
Created June 9, 2015 15:13
Ambition API - Curl/Bash Example
#!/bin/env/sh
#
# upload_to_ambition.sh
# Simple script demonstrating how to upload data to the Ambition Data API.
export AUTH_TOKEN=<AUTH-TOKEN>
curl -vvv -H "Content-Type: application/json" -X POST "https://<SUBDOMAIN>.ambition.com/public-api/integration/v1/data/new/" -H "Authorization: Token $AUTH_TOKEN" -d "{\"depot\": \"custom_depot\", \"data\": \"Data from Curl!\"}"
@joshmarlow
joshmarlow / ambition_api_python_example.py
Created June 9, 2015 15:14
Ambition API - Python Example
#!/bin/env python
#
# ambition_api_python_example.py
# Simple script demonstrating how to upload data to the Ambition Data API.
import json
import sys
import urllib2
@joshmarlow
joshmarlow / ambition_api_c#_example.cs
Created June 9, 2015 15:19
Ambition API - C# Example
/*
* upload_to_ambition.cs
* Simple program demonstrating how to upload data to the Ambition Data API
*
* This code needs to be linked to the System.Web.Extensions assembly.
*
* For mono, use 'gmcs ambition_api_c#_example.cs -r:System.Web.Extensions'
*/
using System;
@joshmarlow
joshmarlow / bindigo_makefile
Created October 16, 2015 22:06
Example Makefile for a small OCaml module
# Note: I've used a consistent naming schem for the files in this project
# (ie, bindigo.mli bindigo.ml bindigo_tests.ml).
# This allows easy construction of various make targets working working with the files.
DELIM = ----------------------------
LIB_NAME = bindigo
# Install this package so that is accessible in other projects on this sytem
install: clean uninstall $(LIB_NAME).byte $(LIB_NAME).native
@echo $(DELIM) Installing...
@joshmarlow
joshmarlow / time_it.rs
Last active September 17, 2016 16:34
time_it macro in Rust
macro_rules! time_it {
($msg:expr, $code:block) => ({
let start = SystemTime::now();
let res = { $code };
let end = SystemTime::now();
println!("{:?} duration: {:?}", $msg, end.duration_since(start).ok().unwrap());
res
})
}
@joshmarlow
joshmarlow / bst.hs
Created September 19, 2016 18:01
Binary Tree Operations
{-# OPTIONS_GHC -Wall #-}
module Tree where
import Data.List
data Tree a = Leaf
| Node Integer (Tree a) a (Tree a)
deriving (Show)
treeHeight :: Tree a -> Integer
treeHeight Leaf = 0