Skip to content

Instantly share code, notes, and snippets.

@jamesarosen
jamesarosen / git-changes-histogram.rb
Created December 13, 2016 21:47
Generate a histogram of line changes (insertions + deletions) from a GitHub repo, bucketed by week
require 'time'
class Commit
DATE = /^Date: +(\w{3} \w{3} \d{1,2}.+)$/
MERGE = /^Merge: +([a-z0-9]+) ([a-z0-9]+)$/
CHANGES = /^ *\d+ files? changed(?:, (\d+) insertions?...)?(?:, (\d+) deletions?...)? *$/
attr_reader :sha
def self.sha_for(pointer)
@jamesarosen
jamesarosen / list-prs-by-time-open.js
Created December 13, 2016 21:45
List Top N closed/merged pull requests for a GitHub repository, ordered by number of days open
const RSVP = require('rsvp');
const moment = require('moment');
const GITHUB_API_TOKEN = process.env.GITHUB_API_TOKEN;
const GITHUB_USER = process.env.GITHUB_USER;
const GITHUB_REPO = process.env.GITHUB_REPO;
const TOP_N = 30;
fetchAllPRs();
function fetchAllPRs() {
@jamesarosen
jamesarosen / components.delete-blog.js
Created November 18, 2016 20:03
passing-deferreds-down
import Ember from 'ember';
export default Ember.Component.extend({
classNames: [ 'delete-blog' ],
sudoDeferred: null,
isDone: false,
isWorking: false,
message: null,
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
@jamesarosen
jamesarosen / ember-context.md
Created September 13, 2016 22:42
Playing with an idea for Contexts for Ember Objects

Impetus

I have several components that have complex flows. For example, a "deploy this code" button. It might have the following flow:

  1. if the user is typing, the button is hidden
  2. after the user stops typing, the button appears, is disabled, and reads "Saving..."
  3. after the code is saved, the button is enabled and reads "Test & Deploy"
  4. after the user clicks the button, it is disabled and reads "Testing..."
  5. if the tests fail, the button remains disabled and reads "Tests Failed"
  6. if the tests pass, the button remains disabled and reads "Deploying..."
@jamesarosen
jamesarosen / ember-blocking-field.md
Last active September 9, 2016 19:37
A discussion of fields and forms in Ember

I have a form with three fields: Foo, Bar, Baz. Bar is really sensitive, so if the user changes it, I want to show a confirmation modal when the user tries to submit the form (but not until then). Currently, we have the is-bar-changed and show-modal logic in the containing form. I'd prefer to move it down into a component:edit-bar. But I can't figure out a good way to model that component having an opportunity to pause the parent form's submission, then continue or abort asynchronously.

Pass Down Hook Registry

One option would be for the form to yield some sort of hook registry:

@jamesarosen
jamesarosen / on-css.md
Last active November 13, 2018 15:47
On CSS

I don't have a Grand Vision for (S)CSS, but I do have some ideas.

Cohesion & Coupling

In JavaScript (and any other "programming language"), we value cohesion and eschew coupling. To value cohesion is to say that all of the foo-related things are in the Foo component or the app/pods/foo pod or the lib/foo addon. Like things are together. To eschew coupling is to say that two unrelated things should not need to know about one another. Unlike things don't rely on one another. Further reading on Cohesion & Coupling:

import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'section',
classNames: [ 'i18n-demo' ],
i18n: Ember.inject.service(),
beenClicked: false,
text: Ember.computed('i18n.locale', function()
{