Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View ecmendenhall's full-sized avatar

Connor Mendenhall ecmendenhall

View GitHub Profile
@ecmendenhall
ecmendenhall / jasmine_chrome_tests.md
Created September 18, 2012 02:17
Integrating the Jasmine test runner for Chrome extension development

[Jasmine][jas] is an excellent framework for JavaScript testing, but I had a tough time coaxing it into cooperation with the Chrome extension I was developing. Jasmine's default testrunner uses an inline script block that listens for window.onload to setup the test environment, but Chrome prohibits extensions from running inline code. Alas, it's not as easy as importing the inline code as a separate file. After a little tinkering, this is what I came up with:

Extension
    ├── html
    ├── js 
    ├── manifest.json
    └── tests
        ├── jasmine
        │   └── lib

│   └── jasmine-1.2.0

@ecmendenhall
ecmendenhall / unidiomatic.py
Last active December 12, 2015 07:08
Help! My Python is turning into Lisp!
def free(exp):
return set(walkreduce(lambda x: isinstance(x, unicode),
walkfilter(lambda x: (x not in bound(exp) and
x != 'lambda'),
exp)))
@ecmendenhall
ecmendenhall / pi_montecarlo.py
Created February 28, 2013 04:46
A Monte Carlo simulation that estimates pi. Just like on Wikipedia! http://en.wikipedia.org/wiki/Monte_carlo_method
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
def new_figure():
figure = plt.figure(122, figsize=(10.0, 5.0))
figure.add_subplot(121)
plt.axis('equal')
@ecmendenhall
ecmendenhall / ntaps.ipynb
Last active December 15, 2015 08:19
The n-taps problem: how many beers should you try before switching to your favorite so far?
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ecmendenhall
ecmendenhall / py_oneliners.md
Created March 26, 2013 06:10
Handy Python one-liners I sometimes forget.

Serve files in the current directory over HTTP:

python -m SimpleHTTPServer 8000

Start a simple SMTP server that prints messages to stdout:

python -m smtpd -n -c DebuggingServer localhost:25
@ecmendenhall
ecmendenhall / TerminalViewTest.java
Last active December 17, 2015 00:39
Testing printed terminal output with JUnit 4.
@RunWith(JUnit4.class)
public class TerminalViewTest extends TicTacToeTest {
private final PrintStream stdout = System.out;
private final ByteArrayOutputStream output = new ByteArrayOutputStream();
private TerminalView terminalview;
@Before
public void setUp() throws UnsupportedEncodingException {
terminalview = new TerminalView();
@ecmendenhall
ecmendenhall / key-listener.clj
Created May 9, 2013 02:50
A keypress listener using Jline and Clojure futures.
(ns keylistener.core
(:require [clojure.java.io :as io])
(:import [jline.console ConsoleReader])
(:gen-class))
(def console (ConsoleReader.))
(defn keypress-loop []
(let [char (.readCharacter console)]
(if (not (nil? char))
@ecmendenhall
ecmendenhall / core.clj
Created May 13, 2013 01:13
A Monte Carlo simulation to estimate Pi with Clojure and Incanter.
(ns montecarlopi.core
(require [incanter.core :refer [sqrt sq view]]
[incanter.charts :refer [function-plot
add-points
add-text
set-x-label
set-y-label
set-y-range
xy-plot]]))
@ecmendenhall
ecmendenhall / on-lisp-chapter-6.clj
Last active December 17, 2015 17:29
Network closures in Clojure, from Chapter 6 of "On Lisp."
;; Figure 6.2 – Representation and definition of nodes
(def nodes (atom {}))
(defn defnode [name contents & [yes no]]
(swap! nodes assoc name {:contents contents :yes yes :no no}))
;; Figure 6.3 – Sample network
(defn make-nodes [node-maker]
(node-maker :people "Is the person a man?" :male :female)
(node-maker :male "Is he living?" :live :dead)
@ecmendenhall
ecmendenhall / quiet-queries.clj
Created June 20, 2013 00:21
Quiet cascalog queries
(require '[cascalog.io :refer [with-log-level])
(defmacro ?<-- [& forms] `(with-log-level :fatal (?<- ~@forms)))