Skip to content

Instantly share code, notes, and snippets.

@jamesarosen
jamesarosen / volary.md
Created April 9, 2014 01:52
Installing Multiple Sets of Bower Dependencies

Overview

Ember-I18n declares the following dependencies:

"cldr":       "^1.0",
"jquery":     ">=1.7 <3",
"handlebars": "^1.0",
"ember":      ">0.9.7 <2"
@jamesarosen
jamesarosen / comcast.md
Last active August 29, 2015 14:03
Why I Hate Comcast: A Story of Customer Disservice

I just signed another year lease on my apartment, so I figured if I have another year here, I might as well try to improve my Internet service and/or price. I really dislike how my current provider, Comcast, is opposing Net Neutrality, so I looked around for altneratives. Nope, still just Comcast and AT&T. Monopolies :(

So I went to comcast.com. Ooh, neat! They have a promotion on Internet that would cut my rate way down. I signed in. "This is a business address. For business service, call us or enter another address." I clicked "enter another address," hoping they just had my address wrong. That link takes me back to ""This is a business address. For business service, call us or enter another address." So much for a usable website.

OK, fine, I'll call. After a couple minutes of playing verbal and key-based phone tree, I get a very nice customer service agent. I ask him what plans are available in my region. He looks for a minute and says, "We have a promotion to add voice, give you the same Internet servic

@jamesarosen
jamesarosen / ideas.md
Created March 4, 2015 00:22
Ideas for testing Ember apps & add-ons against multiple versions of libraries

package.json

Use a custom key in package.json:

alternateDependencies: [
  { "ember": "1.8.1" },
  {
    "ember": "1.12.0-beta",
 "handlebars": false,
@jamesarosen
jamesarosen / application_serializer.js
Created March 4, 2015 06:38
It's hard to test this Ember-Data Serializer
import DS from "ember-data";
function ensureRoot(rootName, payload) {
var result;
if (payload[rootName] == null) {
result = {};
result[rootName] = payload;
} else {
result = payload;
@jamesarosen
jamesarosen / series_component.md
Created March 15, 2015 22:01
An open letter to Chris Henn on the topic of SeriesComponents in Ember

Dear Chris Henn,

I loved your talk at EmberConf this year. Thanks so much for sharing that with us!

I had recently spiked on replacing our graphing library with some components and happened upon a very similar solution to what you described. What I didn't know is that there was an existing grammar for these concepts. I knew a few terms like axes and series, so those became nouns (or components) in my world. My template looks like this:

{{#viz-chart as |d|}}
  {{viz-xaxis dimensions=d}}
 {{viz-yaxis dimensions=d}}
@jamesarosen
jamesarosen / 1-overview.md
Last active August 29, 2015 14:18
Some trouble with Helpers in Ember 1.10+, HTMLBars

I'm having trouble with Ember.HTMLBars.makeBoundHelper. I ran ember g helper format-date, which emitted app/helpers/format-date.js (see below). Note that it uses Ember.HTMLBars.makeBoundHelper. The helper function expects a Date and a format String.

When I render the template (see below), the helper receives instead

  1. an Array of the form [ Sat Feb 28 2015 16:00:00 GMT-0800 (PST), "MMMM YYYY" ]
  2. an empty Object
  3. an Object of the form { morph: Morph }
  4. an Object of the form { data: Object, dom: DOMHelper, helpers, Object, hooks: Object, useFragmentCache: true: view: undefined }

If I change Ember.HTMLBars.makeBoundHelper to Ember.Handlebars.makeBoundHelper, the helper function receives

@jamesarosen
jamesarosen / naming.md
Last active August 29, 2015 14:20
How to Name Things in Programs
  1. You find yourself asking, "I need to arrange some interactions. What should I call the players and the interaction?"
  2. For each interaction
  3. Ask "What message do I want to send?"
  4. Ask "To whom should I send it?" Be as specific as possible. changePassword goes to the PasswordChanger.
  5. Ask "Is there already another recipient that is enough like this one that I am comfortable combining them?" If so, do.

I'm considering refactoring a number Ember.Components that have API interactions to use one or more API service objects. I'm concerned with the layer violation: making API calls in the view layer.

  1. "change password"
  2. changePassword(old, new) -> Promise
@jamesarosen
jamesarosen / first-focus-fail.md
Created July 6, 2015 22:13
jQuery Focuses on Second Call

I'm trying to test some code that involves focus and blur handlers using event delegation. $(...).focus() doesn't work, but $(...).focus().focus() does!

The tests pass fine on PhantomJS and Safari, but fail on Chrome and Firefox. (No, I've never seen that happen before either!)

Here's a simple reproduction:

$('body').append("<div class='my-container'><input /></div>");
var $div = $('.my-container');
$div.on('focus', 'input', function(e) {
@jamesarosen
jamesarosen / merge-promises.md
Last active August 29, 2015 14:24
A Promise-Aware Hash-Merging Function

I have a case in an Ember.Route where I want to start a few asynchronous fetches, each of which resolves with a complex Object, and then eventually merge the results. RSVP has some nice higher-level Promise utilities, but it doesn't have merge. So I wrote one.

If you only ever want to merge two Promises, you could do this

function mergeTwoPromises(promiseA, promiseB) {
  return new Ember.RSVP.Promise(function(resolve, reject) {
    Ember.RSVP.all([ promiseA, promiseB ])
    .then(function([ hashA, hashB ]) {
      resolve(Ember.merge(hashA, hashB));
def merge_two_sorted_lists(a, b, &comparator)
comparator ||= lambda { |x,y| x <=> y }
linrec(
:cond => lambda { |pair| pair.first.empty? || pair.last.empty? },
:before => lambda do |pair|
preceding, following = case comparator.call(pair.first.first, pair.last.first)
when -1; [pair.first, pair.last]
when 0; [pair.first, pair.last]
when 1; [pair.last, pair.first]
end