Skip to content

Instantly share code, notes, and snippets.

View taylorlapeyre's full-sized avatar

Taylor Lapeyre taylorlapeyre

View GitHub Profile
const dictionary = {
"one": 1,
"two": 2,
"three": 3,
"four": 4,
"five": 5,
"six": 6,
"seven": 7,
"eight": 8,
"nine": 9,
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function roll20() {
return getRandomInt(1, 20);
}
@taylorlapeyre
taylorlapeyre / react?.js
Last active July 23, 2018 17:46
React if jsx was actually just arrays like ["h1", "Hello World"]
const Ops = {
CREATE: "CREATE",
UPDATE: "UPDATE",
DELETE: "DELETE",
KEEP: "KEEP"
};
function constructTree(dom) {
if (dom.nodeType === document.TEXT_NODE) {
return dom.textContent;
export function createElement(tagName, options, ...children) {
// If the "tagName" is a function, we assume it is a custom element and delegate element creation to it.
// Otherwise, we create a new Element ourselves.
const isCustomElement = typeof tagName === 'function'
const element = isCustomElement ? tagName(options) : document.createElement(tagName)
if (!options) {
return element
}
Verse 1
#######
E D A E
We’ve been gone for such a long time that I’m almost afraid to go home
E D A E
A long road is a long dragged out imagination with which to go wrong
E D A E
We keep rolling on
@taylorlapeyre
taylorlapeyre / happy.clj
Last active August 29, 2015 14:20
Happy Numbers
(defn square [x] (* x x))
(defn happy
"Given a number, returns a new number that is the result of summing
the squares of its digits"
[x]
(let [characters (map str (seq (str x)))
digits (map #(Integer/parseInt %) characters)]
(reduce + (map square digits))))
var SelectThing = React.createClass({
getInitialState: function() {
return {
chosenFirstValue: "",
chosenSecondValue: ""
}
},
updateFirstSelectValue: function(e) {
var SelectThing = Backbone.View.extend({
events: {
'input .select1': 'updateFirstSelect',
'input .select2': 'updateSecondSelect'
},
template: _.template($('#select-thing-template').html()),
initialize: function(collection1, collection2) {
@taylorlapeyre
taylorlapeyre / interleave.clj
Last active August 29, 2015 14:16
interleave
(defn interleave [arrays]
(let [largest-length (apply max (map count arrays))]
(->> (for [i (range largest-length)]
(map #(nth % i nil) arrays))
(flatten)
(remove nil?))))
(interleave [[1 2 3] ["a" "b" "c"]])
class Matrix
attr_reader :elements
def initialize(elements)
@elements = elements
end
def dimensions
{ rows: @elements.first.count, cols: @elements.count }
end