Skip to content

Instantly share code, notes, and snippets.

View timsgardner's full-sized avatar

Tims Gardner timsgardner

  • Arcadia Technologies
  • Brooklyn, NY
View GitHub Profile
@timsgardner
timsgardner / LiteBirdDisplayer.js
Created June 14, 2016 21:01
LiteBirdDisplayer and BirdForm
var BirdForm = React.createClass(
{
getInitialState: function(){
return {birdName:'', wingspan:''};
},
handleBirdNameChange: function(e){
console.log(e.target.value);
this.setState({birdName: e.target.value});
},
handleBirdWingspanChange: function(e){
var ParagraphPile = React.createClass(
{getInitialState: function(){
return({tog: false});
},
handleClick: function(e){
labeledLog('state', this.state);
e.preventDefault();
var tog2 = !(this.state.tog);
this.setState({tog: tog2});
},
@timsgardner
timsgardner / birdsDisplay.js
Last active June 13, 2016 18:40
birds display
var birdData = [
{birdName: 'seagull',
wingspan: 'eighteen feet'},
{birdName: 'chickadee',
wingspan: 'three nanometers'}
];
var BirdDisplay = React.createClass(
{getInitialState: function(){
@timsgardner
timsgardner / template_match.clj
Last active June 9, 2016 03:38
template match
(defn template-match? [template-node data-node]
(cond
(atomic-node? template-node)
(= template-node data-node)
(predicate-node? template-node)
(predicate-match? template-node data-node)
:else
(and
function isSortedObject(obj){
//var props = Object.getOwnPropertyNames(obj);
var i = 0;
for(var k in obj){
if(k != i){
return false;
}
i++;
}
return true;
@timsgardner
timsgardner / linkedList.js
Last active May 26, 2016 14:38
linked lists
function first(linkedList){
return (linkedList === null) ? null : linkedList[0];
}
function rest(linkedList){
return (linkedList === null) ? null : linkedList[1];
}
function prepend(x, linkedList){
return [x, linkedList];
;; sort of like reset
(defn thing-1 [game-object-with-state, kw, val]
(let [a (get-state-atom game-object-with-state)]
(swap! a assoc kw val)
game-object-with-state))
;; sort of like swap
(defn thing-2 [game-object-with-state, kw, f]
(let [a (get-state-atom game-object-with-state)]
(swap! a update kw f val)
@timsgardner
timsgardner / intsFrom.js
Last active May 26, 2016 15:01
intsFrom
// makes an infinite sequence (memoized generator) of all integers from supplied n up
var intsFrom = function(n){
return {
thunk: {realized: false,
state: null,
deref: function(){
if(this.realized){
return this.state;
}else{
console.log("running a computation!!");
@timsgardner
timsgardner / lazyseq.js
Last active May 21, 2016 16:56
javascript lazy seq
function isFunction(x){
return typeof(x) === 'function';
}
function jsBool(x){
return !( x === null || x === undefined || x === false);
}
function isSeq(x){
return jsBool(x.myType === "seq");
@timsgardner
timsgardner / uids.js
Created May 16, 2016 14:00
javascript uids and fake dbs
// ============================================================
// UIDs
// should hide the idCounter in a closure, just leaving it global for sake of simplicity here:
var idCounter = 0;
var nextId = function(){
idCounter = idCounter + 1;
return "id_" + idCounter;
};