Skip to content

Instantly share code, notes, and snippets.

Avatar

Ethan Miller ezmiller

View GitHub Profile
@ezmiller
ezmiller / checkout-branch-on-fork
Created Oct 2, 2019
Checking out a branch from a fork
View checkout-branch-on-fork
# See here: https://github.community/t5/How-to-use-Git-and-GitHub/Checkout-a-branch-from-a-fork/td-p/77
git ls-remote --refs origin -- will list refs for remote `origin`, some will look like `refs/pull/<some-num>/head`
git fetch origin pull/123/head:pr/123 && git checkout pr/123 # fetch and checkout PR #123, eg.
View use-clj-plot.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ezmiller
ezmiller / factorial.clj
Created Oct 2, 2018
Recursive Factorial
View factorial.clj
(defn factorial [n]
(if (= n 1)
1
(* n (factorial (- n 1)))))
View 2016-kings-county-pres-primary-35th-color.json
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ezmiller
ezmiller / Datomic News Updates
Created Mar 12, 2017 — forked from k1m190r/Datomic News Updates
Datomic update examples against a social news database
View Datomic News Updates
;; Datomic example code
;; demonstrates various update scenarios, using a news database
;; that contains stories, users, and upvotes
;; grab an in memory database
(use '[datomic.api :only (q db) :as d])
(def uri "datomic:mem://foo")
(d/create-database uri)
(def conn (d/connect uri))
@ezmiller
ezmiller / wrap_strings.R
Created Aug 22, 2016
R function for wrapping long strings
View wrap_strings.R
## Function to wrap long strings
# Source: http://stackoverflow.com/a/7367534/496488
wrap_strings <- function(vector_of_strings,width) {
as.character(
sapply(vector_of_strings, FUN=function(x) {
paste(strwrap(x, width=width), collapse="\n")
})
)
}
@ezmiller
ezmiller / stacktrace.js
Created Jan 19, 2016
How to log a strack trace anywhere in Javascript
View stacktrace.js
var e = new Error('dummy');
var stack = e.stack.replace(/^[^\(]+?[\n$]/gm, '')
.replace(/^\s+at\s+/gm, '')
.replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@')
.split('\n');
console.log(stack);
@ezmiller
ezmiller / ContentEditable.jsx
Created Sep 14, 2015
A React component for a content editable div
View ContentEditable.jsx
var ContentEditable = React.createClass({
shouldComponentUpdate: function(nextProps){
return nextProps.html !== this.getDOMNode().innerHTML;
},
componentDidUpdate: function() {
if ( this.props.html !== this.getDOMNode().innerHTML ) {
this.getDOMNode().innerHTML = this.props.html;
}
@ezmiller
ezmiller / gist:1a4a364fa167b90ed133
Created Jun 23, 2015
A example method for preloading html5 videos in a queue
View gist:1a4a364fa167b90ed133
// Have to use an object so that count can function as a reference
var loadQueue = {
count:0
}
/**
* Preloads videos
*
* If limit has been reached video is not preloaded but an
@ezmiller
ezmiller / parseUrl.js
Created Jun 11, 2015
A quick way to parse a url using the DOM
View parseUrl.js
var parseUrl = function(url) {
var parser, urlInfo;
parser = document.createElement('a');
parser.href = url;
urlInfo = {
protocol: parser.protocol,
hostname: parser.hostname,
port: parser.port,
You can’t perform that action at this time.