Skip to content

Instantly share code, notes, and snippets.

View amiel's full-sized avatar

Amiel Martin amiel

View GitHub Profile
@amiel
amiel / my-controller.js
Created May 8, 2014 01:49
ember-validators with server validation errors
MyController = Ember.Controller.extend({
actions: {
save: function() {
this.get('model').save().then(function() {
// Success, maybe transitionToRoute or whatever
}, function(xhr) {
// Oh noes, we had an error, maybe it's a validation error
if (xhr.status == 400) {
$.parseJSON(xhr.responseText).each(function(attribute, errors) {
this.get('errors').set(attribute, errors);
#!/usr/bin/env ruby -rubygems
# :P
# exit
require 'digiusb/digiblink'
# TODO:
COLORS = {
'success' => 'green',
@amiel
amiel / gist:9625148
Last active August 29, 2015 13:57
jenkins ghprb
if [ -z "$ghprbSourceBranch" ];then
# special case non GHPRB build
git fetch origin '+refs/heads/*:refs/remotes/origin/*'
git reset --hard "$sha1"
fi
@amiel
amiel / custom-predicate.rb
Created March 11, 2014 00:00
custom predicate in rspec
class MyFoo
def awesome?
true
end
end
describe MyFoo do
let(:my_foo) { MyFoo.new }
it 'is awesome' do
@amiel
amiel / helper.rb
Created March 5, 2014 17:39
classes helper
def link_to_post(post)
html_class = ["post"]
html_class << "active" if post.active?
link_to(post.title, post, class: html_class)
end
@amiel
amiel / my_custom_date_presenter.rb
Last active August 29, 2015 13:56
HTMLCalendar date presenter example
class MyCustomDatePresenter < HTMLCalendar::DatePresenter
# Available methods: `date` and `template`
# The only required method
def html_classes
if monday?
['a-case-of-the-mundays']
else
[]
end
@amiel
amiel / api_client.rb
Created February 21, 2014 01:21
Ignoring API errors
class APIClient
def get_teapots
ignore_errors do
make_request :teapots
end
end
def get_coffeepots
ignore_errors do
make_request :coffeepots
@amiel
amiel / ignorable_errors.rb
Last active August 29, 2015 13:56
Ignoring stupid errors
SMRT_ERRORS = [ServiceClaimsIsATeapot]
def ignore_stupid_errors(error_block = ->(*){})
yield
rescue *SMRT_ERRORS => e
error_block.call e
end
module Navision
class ItemGateway
def initialize(options = {})
@client = options.fetch(:client) { Navision.item_client } # item_client => Savon.client(...)
end
def get_product_by_number(number)
get_result client.call :read, message: { 'No' => number }
end
@amiel
amiel / gist:7793267
Last active December 30, 2015 06:59
# LineItemsController
categories: (->
@get('model').mapBy('category').uniq().map (category) =>
Ember.Object.create
name: category
line_items: @get('model').filterBy 'category', category
).property('@each.category')