Skip to content

Instantly share code, notes, and snippets.

View jlturner's full-sized avatar

James Lawrence Turner jlturner

View GitHub Profile
@jlturner
jlturner / track.js
Created August 10, 2016 05:07
Higher order function that produces higher order functions to track arguments and return values of functions in JavaScript
const makeTrackFunc = mapObj => {
return f => {
return function(...args) {
const result = f.call(this, ...args);
mapObj.set(f, (mapObj.get(f) || []).concat({args, result}));
return result;
}
}
};
// Easy 249
// https://www.reddit.com/r/dailyprogrammer/comments/40h9pd/20160111_challenge_249_easy_playing_the_stock/
// node stocks_suggestion.js js 9.20 8.03 10.02 8.08 8.14 8.10 8.31 8.28 8.35 8.34 8.39 8.45 8.38 8.38 8.32 8.36 8.28 8.28 8.38 8.48 8.49 8.54 8.73 8.72 8.76 8.74 8.87 8.82 8.81 8.82 8.85 8.85 8.86 8.63 8.70 8.68 8.72 8.77 8.69 8.65 8.70 8.98 8.98 8.87 8.71 9.17 9.34 9.28 8.98 9.02 9.16 9.15 9.07 9.14 9.13 9.10 9.16 9.06 9.10 9.15 9.11 8.72 8.86 8.83 8.70 8.69 8.73 8.73 8.67 8.70 8.69 8.81 8.82 8.83 8.91 8.80 8.97 8.86 8.81 8.87 8.82 8.78 8.82 8.77 8.54 8.32 8.33 8.32 8.51 8.53 8.52 8.41 8.55 8.31 8.38 8.34 8.34 8.19 8.17 8.16 8.03 9.34
function bestMargin(suggestion,other){
if(suggestion === undefined) {
return other;
}
if(other.margin > suggestion.margin) {
return other;
@jlturner
jlturner / demo.html
Created November 18, 2015 21:12
Tiny Demo w/ text and time (Nov 18, 2015)
<!DOCTYPE html>
<html>
<head>
<style>
@font-face {
font-family: 'std';
src: url(data:font/truetype;charset=utf-8;base64,AAEAAAAOAIAAAwBgRkZUTVlJPI8AAADsAAAAHEdERUYA7gAEAAABCAAAACBPUy8yNTq5cgAAASgAAABgY21hcDskb/gAAAGIAAAB+mdhc3D//wABAAADhAAAAAhnbHlm7EEHWwAAA4wAADBcaGVhZAwFqW4AADPoAAAANmhoZWERAgfCAAA0IAAAACRobXR4AfcAAAAANEQAAAMEbG9jYY8gmyIAADdIAAABhG1heHAAxwAnAAA4zAAAACBuYW1lMIiEKwAAOOwAAANycG9zdMKGwlwAADxgAAACUXdlYmblIVZMAAA+tAAAAAYAAAABAAAAAMw9os8AAAAAupkEIAAAAADScpWfAAEAAAAOAAAAGAAAAAAAAgABAAEAwAABAAQAAAACAAAABAVTAZAAAAAEAQABAAAAAgABAAEAAAACAAEAAgAAAAIACAAAAgAEAAD3/67/+9///wgb//8AAAAAemVocgDAAA0l/AgA/wABAAgAAgAAAAABAAAAAAUABwAAAAAgAAEAAAADAAAAAwAAABwAAQAAAAAA9AADAAEAAAAcAAQA2AAAADIAIAAEABIADQB+AKEApwCtALoAzwDWAN0A7wD2AP0A/wEfAWEBeALGIAogFCAZIC8gXyCsJfz//wAAAA0AIACgAKMArQC6AL8A0QDYAN8A8QD4AP8BHgFhAXgCxiAAIBAgGSAvIF8grCX8////9v/k/8P/wv+9/7H/rf+s/6v/qv+p/6j/p/+J/0j/Mv3l4Kzgp+Cj4I7gX+AT2sQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBgAAAQAAAAAAAAABAgAAAAMAAAAAAAAAAAAAAAAA
@jlturner
jlturner / demo.html
Created November 16, 2015 20:50
Tiny Demo w/ touch events (Nov 16, 2015)
<!DOCTYPE html>
<html>
<head>
<style>
body {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
datatype json
= Array of json list
| Boolean of bool
| Float of real
| Integer of int
| Null
| Object of (json * json) list
| String of string
@jlturner
jlturner / server.rb
Created February 22, 2015 16:43
Quine Eval Server - An experiment
# Quine Eval Server - An experiment
# =================================
#
# This server, when run, will accept POST requests on the root ('/') where the post body is ruby code to eval.
# This server also makes a copy of its source code, and includes the eval'd statements in the new source.
# Because this is a sinatra server, you can use this to create new routes and build up a web service incrementally while running.
#
# Example post to server using curl:
# curl -vv -XPOST -d 'get "/hi" do ; "hi!" ; end' 'http://localhost:4567'
#
@jlturner
jlturner / curses_loop.ml
Created January 1, 2015 22:26
Infinite non-blocking curses input loop in OCaml, reading input from the keyboard
let win = Curses.initscr ();;
Curses.nodelay win true;;
Curses.noecho ();;
let rec run () =
let inputCharCode = Curses.getch () in
let input = if inputCharCode >= 0 && inputCharCode <= 255
then Some (Char.chr inputCharCode)
else None in
let couldWrite = match input with
@jlturner
jlturner / xpath_dom_picker.js
Last active August 29, 2015 14:09
JavaScript to visually pick elements from the DOM and grab the XPath to it
var taggerSelectorCSSClass = "urx-tagger-selector";
var taggerStyle;
var addStyle = function() {
taggerStyle = document.createElement("style");
taggerStyle.innerHTML = "." + taggerSelectorCSSClass + " { background-color:green !important; color:white !important; border: 4px dashed white !important; }" +
"." + taggerSelectorCSSClass + " * { color: black !important; }";
document.body.appendChild(taggerStyle);
};
@jlturner
jlturner / zk_update_channel.go
Created August 21, 2014 16:29
Receive Updates from a particular Zookeeper path on a channel
package main
import (
"fmt"
"github.com/samuel/go-zookeeper/zk"
"time"
)
func main() {
c, ech, err := zk.Connect([]string{"localhost"}, time.Minute)
#!/bin/sh
# Copyright 2012 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# git gofmt pre-commit hook
#
# To use, store as .git/hooks/pre-commit inside your repository and make sure
# it has execute permissions.
#