Skip to content

Instantly share code, notes, and snippets.

View jergason's full-sized avatar
🦢
theft puts a parade in my walk

Jamison Dance jergason

🦢
theft puts a parade in my walk
View GitHub Profile
@jergason
jergason / foo.jsx
Last active August 29, 2015 14:06 — forked from fivetanley/foo.html
/** @jsx: React.DOM */
var React = require('react');
var IfThingy = React.createClass({
render: function() {
var ifThingy;
if (this.props.someVar) {
ifThingy = <h1>Some Var Is {this.props.someVar}</h1>;
}
else {
@jergason
jergason / makeN.js
Created May 23, 2014 17:22
A use for the Array() constructor!
function makeN(n, obj) {
// gotta use .apply(null) because Array(n) makes a new empty array of size n and map behaves starngely
// Array.apply(null, Array(n)) creates an array of size n with undefined as the value of every item
// we can then call map on it to get back an array with n `obj`s.
return Array.apply(null, Array(n)).map(function() { return obj; });
}
React.renderComponent(
<MomentPreviewList data={previewList}/>,
document.getElementById('moment-live-feed')
)
async.waterfall [
(cb) -> doStuff(cb)
(result, cb) -> doOtherStuff(result, cb)
(someOtherResult, cb) -> finally(someOtherResult, cb)
], (err, res) ->
console.log 'res is', res
# ᕕ( ᐛ )ᕗ WELP
async.waterfall [
Ticket = Backbone.Model.extend({
urlRoot: 'api/Ticket/'
});
TicketView = Backbone.View.extend({
initialize: function(model) {
this.model = model;
this.listenTo(this.model, 'change', this.render.bind(this));
this.render()
@jergason
jergason / index.html
Last active December 11, 2015 23:39
Deleting a record removes all records? This is using the latest Ember and Ember Data built from master on January 30th, 2013. What am I doing dumb? Start the webserver and navigate to http://localhost:3000/#/tab, and click the delete button on one of the tab items, and behold the weirdness.
<!DOCTYPE html>
<head>
<title>Ordr: Rstaurant Mnu Systm</title>
<script type="text/x-handlebars" data-template-name="tab">
<ul>
{{#each tabItem in tabItems}}
{{ partial "tabItem" }}
{{else}}
<li><h3>Click a food to add it</h3></li>
{{/each}}
@jergason
jergason / promises_vs_callbacks.js
Created November 20, 2012 15:42
Promises vs nested callbacks?
// Assume the error handling logic is pretty different at each async step,
// and I have multiple different error conditions that require different
// actions to handle them.
// How can I do this with promises without passing some kind of additional
// data to the error handler so it can know what logic to use?
function someFattyAsyncThing(data, cb) {
someAsyncOp(data, function (err, res) {
if (err) {
return cb(err);
}
@jergason
jergason / view.coffee
Created November 9, 2012 15:48
Better Child Views in Backbone
# Base view class that all views extend
# NOTE: This is from real production code, so it has some messiness for
# dealing with real production issues.
View = Backbone.View.extend
initialize: (@model) ->
@render
super
@jergason
jergason / jasmine.js
Created August 8, 2012 04:37 — forked from fivetanley/jasmine.js
jasmine again
define( [ 'views/SearchView' ], function( SearchView ){
describe('SearchView', function() {
var searchView, spy
beforeEach(function() {
setFixtures( $( "<input type='search' id='search'/>" ) )
searchView = new SearchView()
searchView.render()
spy = jasmine.createSpyObj( 'event', [ 'handler' ] )
})
destroy: function() {
this.$el.remove()
this.off()
// destroy any children
for (var selector in this.autoChildren)
this.destroyChild(selector)
this.autoChildren = null
}