Skip to content

Instantly share code, notes, and snippets.

View jamesarosen's full-sized avatar

James A Rosen jamesarosen

View GitHub Profile
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
@jamesarosen
jamesarosen / forms.md
Last active June 1, 2016 22:48
Inline Validations, Form Resetting, and Initial Values in Ember

Conditionally Show Validation Errors

I have a component for an <input> that (a) knows about validations and (b) knows how to only show validation errors if the user has touched the field or submitted the form:

// my-input/component.js
export default Ember.Component.extend({
  attributeBindings: [ 'isValid:data-is-valid', 'showValidationErrors:data-show-validation-errors' ],
  classNames: [ 'my-input' ],
@jamesarosen
jamesarosen / algorithms.md
Last active April 7, 2016 16:40
Practicing some algorithms

Sorting

Mergesort

export default function mergesort(array) {
  if (array.length <= 1) { return array; }
  const halfIndex = Math.floor(array.length / 2);
  const left = array.splice(0, halfIndex);
  return merge(mergesort(left), mergesort(array));
@jamesarosen
jamesarosen / house-hunting.md
Last active April 14, 2016 16:48
House Hunting in the Bay Area

Priorities

My priorities (please suggest things I didn't think of):

  1. Under $1.3M
  2. Safe neighborhood
  3. Livable condition, but it doesn't have to be super up-to-date; no major structural problems
  4. Quiet street; not next to train tracks, highway, or a lot of bars; prefer not on El Camino or similarly major streets
  5. Less than 2mi from some shops / a town center
  6. Freestanding home; not part of a condo/townhome association
@jamesarosen
jamesarosen / hash-table.js
Last active March 25, 2016 06:21
Implementing a HashTable based on JS arrays... just for fun
export default class HashTable {
constructor(size) {
this._data = new Array(size);
}
// Inserts `value` under `key`, forgetting any previous value stored under `key`.
// Returns the HashTable.
insert(key, value) {
bucketFor(this._data, key, true).insert(key, value);
return this;
@jamesarosen
jamesarosen / trouble.md
Last active February 19, 2016 20:42
Trouble with Ember 1.13 Query Params

Some notes on problems I'm experiencing with Ember's Query-Params.

Background

I'm trying to create a "global" query-param that exists on controller:application and sticks around for the whole session. An example might be http://myapp.com/some/route?locale=es. The only oddity is that only some users are allowed to set this parameter; for other users, it's ignored. I started with the following

// app/pods/application/controller.js
@jamesarosen
jamesarosen / application.controller.js
Last active February 18, 2016 18:43
Query Params Investigation
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
queryParams: [ 'refreshCount' ],
refreshCount: Ember.computed({
get() { return 0; },
set(prop, newVal) { return +newVal; }
}),
@jamesarosen
jamesarosen / application.controller.js
Created February 5, 2016 18:06
Application Query Params
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
queryParams: [ 'myParam' ]
});
@jamesarosen
jamesarosen / git-excise-attempt.md
Last active January 13, 2016 00:14
Trying to excise some commits

I have a project with a long git history. I want to open-source it, but there's a long section at the beginning that I want to remove first.

*    ddfe660 - (HEAD, origin/master)
|
|    (many hundreds of commits, including merges)
|
*    420b801 - (the intended beginning of the new history)
*    00a3516 - (the most recent commit I want squashed out)
@jamesarosen
jamesarosen / stuck.md
Last active January 8, 2016 01:52
I'm stuck on fixing our build, so I'm writing down what I've done. Maybe someone will have some ideas.

My team has been working on an Ember.js application for the better part of a year now. About a month or two ago, we started seeing the following in our Travis CI build output intermittently:

...
ok 483 PhantomJS 2.0 - Acceptance: stats/filter: filter by service
ok 484 PhantomJS 2.0 - Acceptance: stats/filter: filter by region
not ok 485 PhantomJS - Browser "phantomjs /home/travis/build/fastly/Tango/node_modules/ember-cli/node_modules/testem/assets/phantom.js http://localhost:7357/5881" exited unexpectedly.