Instantly share code, notes, and snippets.

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.
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))
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")
})
)
}
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);
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;
}
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
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,
View CustomErrors.js
'use strict';
/**
* Indicates an error where an invalid argument or input to a method.
* @param {string} message The error message.
* @param {string} stack The stack trace.
*/
function InvalidArgumentException(message, stack) {
this.name = 'InvalidArgumentException';
this.message = message || 'Invalid Argument';
View gist:acb0d91c8b48984e385a
while true; do
change=$(inotifywait -e close_write,moved_to,create .);
change=${change#./ * };
if [ "$change" = "style.styl" ]; then
echo $(date); stylus style.styl -o ../..;
fi;
done