Skip to content

Instantly share code, notes, and snippets.

View amiel's full-sized avatar

Amiel Martin amiel

View GitHub Profile
@amiel
amiel / admin_user_spec.rb
Created May 20, 2014 18:25
spec/features/admin_user_spec.rb
require 'spec_helper'
describe 'Users' do
fixtures :all
let(:user) { admin_users(:amiel) }
before { login_to_admin }
describe '#index' do
it 'renders without fail' do
visit '/admin/users'

This works with Ember Data 1.0.0-beta.7+canary.b45e23ba, but not Ember Data 1.0.0-beta.8.2a68c63a.

normalizePayload now takes just a payload.

What is the new way to do this?

@amiel
amiel / 1-other-versions.txt
Last active August 29, 2015 14:03
Npm list in ember.js -- tests in browser are failing because {{FEATURES}} is not getting replaced in tests/ember_configuration.js
$ npm --version
1.3.21
$ ember --version
version: 0.0.37
@amiel
amiel / serializers-application.coffee
Created August 6, 2014 20:47
Example serializer for supporting the lack of a root key
ApplicationSerializer = DS.RESTSerializer.extend
extract: (store, type, payload, id, requestType) ->
newPayload = {}
newPayload[type.typeKey] = payload
@_super store, type, newPayload, id, requestType
serializeIntoHash: (hash, type, record, options) ->
Ember.merge hash, @serialize record, options
var controller = this;
var success = function(model) {
controller.transitionToRoute('...');
};
var failure = function(xhr) {
controller.get('model').rollback();
if (xhr.status == 400) {
controller.showError($.parseJSON(xhr.responseText).detail);

urlTemplate Proposal

Summary

urlTemplate improves the extesibility of API endpoint urls in RESTAdapter.

Motivation

I think that Ember Data has a reputation for being hard to configure. I've often heard it recommended to design the server API around what Ember Data expects.

noun_type_enable_disable = new CmdUtils.NounType( "Enable / Disable", ['enable', 'disable'] );
CmdUtils.CreateCommand({
name: "javascript",
synonyms: ['js'],
description: 'Enable or disable javascript for your browser. You will have to refresh the page for changes to take effect.',
author: {
name: 'Amiel Martin',
email: 'amiel@tatango.com'
CmdUtils.CreateCommand({
name: "hello-world",
execute: function() {
var doc = Application.activeWindow.activeTab.document;
// find div.foo in the body of that document
jQuery('#content', doc.body).html('woot');
displayMessage( "Hello, World!" );
@amiel
amiel / gist:69934
Created February 25, 2009 01:39
give it a value in seconds, and it will return a sentence
def length_of_time_in_words(seconds)
seconds = seconds.to_i
%w[ year month week day hour minute second ].collect do |unit|
unit_in_seconds = 1.send(unit).to_i
n = seconds / unit_in_seconds
seconds -= n * unit_in_seconds
module IncrementifyString
# Helps create a user friendly unique string
# For example, calling incrementify! repeatedly starting with
# 'string' would yield:
# 'string' => 'string1' => 'string2' => 'string3' ... 'string9' => 'string10' => 'string11' ... etc
def incrementify!
if match(/[0-8]$/)
succ! # this is faster than regex parse and to_i + 1 to_s
elsif ends_with?('9')
m = match(/(\d+)$/)