Skip to content

Instantly share code, notes, and snippets.

@danfinlay
danfinlay / gist:dce9ea82cb2193c1f232
Created July 14, 2014 17:39
Ticket Account Race Condition

Currently on a user’s first connection, their account is made. If they make two requests in quick succession (as is typical during a normal page load), this leads to two accounts being created at the same time.

We need some strategy to avoid this dual-account creating.

@danfinlay
danfinlay / Geddy-Assn.value-query
Created July 23, 2014 21:20
Demonstrating the result I'm getting using Geddy's current association-value querying.
Team.all({'players.name': 'Daffy Duck'}
, {includes: ['Player']});
error: missing FROM-clause entry for table "User#newsPosts"
at Connection.parseE (/Project/node_modules/pg/lib/connection.js:561:11)
at Connection.parseMessage (/Project/node_modules/pg/lib/connection.js:390:17)
(See full trace by running task with --trace)
@danfinlay
danfinlay / gist:cbfe5a7693cd811d1199
Created January 28, 2015 04:31
Editing DOM with Javascript

Editing DOM With Javascript

A friend recently asked me for some help with jQuery. He wanted to know how to store data on html elements from the JSON payload he was receiving. His initial approaches were much like some of my own early approaches, storing data on elements using data attributes, and then updating those accordingly.

I've since come to learn that these are considered bad practices, and for good enough reasons. Sure, it can work, but it will be slow, and difficult to implement, and if your UI gets very complicated, you'll find yourself juggling multiple sources of truth in your application.

There are several approaches available to the modern web app developer, and I'm sorry I don't believe I'm a grand enough authority to choose a specific one for a project that isn't mine, but I am aware of enough different approaches I think I can get you oriented with what to look for in a good solution.

A Single Source of Truth

@danfinlay
danfinlay / gist:386894cc297faae39c61
Created February 4, 2015 17:22
How to filter an Ember.js array based on an asynchronous relationship?
//model definitions
var Post = Ember.Model.extend({
body: DS.attr('string'),
author: DS.belongsTo('user', {async: true, inverse: 'posts'})
})
var User = Ember.Model.extend({
name: DS.attr('string'),
male: DS.attr('boolean'),
posts: DS.hasMany('post', {async:true, inverse: 'author'})
@danfinlay
danfinlay / gist:83a16d4e371a58b951ea
Created February 14, 2015 02:07
ES6 Fun Example Using Generators & Block Comments
var fs = require('fs')
var path = require('path')
run(function * (done){
var files = yield fs.readdir(__dirname, done);
var file
for( var i = 0; i < files.length; i++ ){
file = files[i];
@danfinlay
danfinlay / gist:570e179c0eb28e971c57
Last active August 29, 2015 14:15
Ember-CLI Module System

The ES6 Module System in Ember-CLI

I'm writing this tutorial at the request of @atduskgreg, the author of the excellent Making Things See, recommended to me by the great Max Ogden.

Greg wanted to know what was up with importing modules in Ember-CLI. And I admit, this can be a confusing process, and I still remember being frustrated and confused.

To be honest I'm not an expert on the internals, so I can't really lay out the step by step build process, although as the Ember-Cli docs say, it relies on the ES6 Module Transpiler to do the heavy lifting.

I'm going to focus on some quick and easy how-tos:

@danfinlay
danfinlay / gist:e3b23bf042ec0c719409
Created February 17, 2015 18:31
Weird Node-sass Error in Ember-CLI
> [email protected] install /Users/danielfinlay/Documents/Development/Issue Tracker/Raincheck/node_modules/ember-cli-sass/node_modules/broccoli-sass/node_modules/node-sass
> node build.js
child_process: customFds option is deprecated, use stdio instead.
child_process: customFds option is deprecated, use stdio instead.
CXX(target) Release/obj.target/binding/binding.o
In file included from ../binding.cpp:1:
../node_modules/nan/nan.h:481:19: error: no type named 'ExternalAsciiStringResource' in 'v8::String'; did you mean 'ExternalStringResource'?
v8::String::ExternalAsciiStringResource *resource) {
~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
@danfinlay
danfinlay / testing-interface-vs-impelmentation-dan01.md
Last active August 29, 2015 14:21
Testing interface vs implementation

Testing: Interface vs Implementation

This is my reply to my friend @mehulkar's recent blog post on Testing behavior vs implementation.

First, a caveat...

I'm going to start with my usual rhetorical shennanigans, which is to emphasize that nothing is black and white, it's a continuum, etc. I'll even go so far as to say that I completely, 100% agree with your thesis in a very extreme way, that behavior should always be tested instead of implementation, I will just then add

You can't always get what you want

CSS is Fun:
Starwipe.js
An incredible prank is to play with someone’s global chrome CSS file, <user-data-dir>/<profile>/User StyleSheet/Custom.css
Make all logos spin?
Make global hue slowly and gradually warp and cycle?
PostCSS: A Javascript module system for composing custom CSS pre-processors. It aspires to be BabelJS for CSS.
postcss-colorblind: Renders your CSS as a colorblind person would see it.
doiuse: Parses your css and tells you if you’re using features compatible with your target browsers.
rtlcss: mirrors interface for right-left reading languages and cultures.