Skip to content

Instantly share code, notes, and snippets.

View amiel's full-sized avatar

Amiel Martin amiel

View GitHub Profile
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 / 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
@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 / 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 / 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 / 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 / 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
#!/usr/bin/env ruby -rubygems
# :P
# exit
require 'digiusb/digiblink'
# TODO:
COLORS = {
'success' => 'green',
@amiel
amiel / IDEAS.md
Created May 13, 2014 20:38
nested urls ideas
@amiel
amiel / example.js
Created May 14, 2014 21:23
Example gist cursor misalignment.
Object.create({ braces: { make: { it: { slightly: { worse: { each: { time: {} } } } } } } });
return { cursor: "is basically one character off here" };