Skip to content

Instantly share code, notes, and snippets.

@esmevane
esmevane / linkshare_feed.rb
Created November 21, 2012 21:03
[Ruby / Rails] LinkshareFeed class suggestion
class LinkshareFeed
def initialize order
@order = order
@items = order.line_items
end
def sku_list
"#{@items.map(&:sku).join('|')}|Discount"
end
@esmevane
esmevane / hcl.js
Created December 6, 2012 02:30
[d3 js] Example snippet to build a random Hcl transitioned color
var randomHcl;
randomHcl = function() {
d3.scale.linear().domain(d3.range(100)).interpolate(d3.interpolateHcl).range(['blue', 'green'])
};
randomHcl(30);
@esmevane
esmevane / beany.coffee
Created December 11, 2012 22:20
CoffeeScript to JS closure and context demonstration
class @Beany extends Array
constructor: (@souffle = true) -> console.log @souffle
beany = new Beany
@esmevane
esmevane / gist:4503076
Created January 10, 2013 15:50
[ Sublime Config ] Translate tags to spaces + tab_size 2
{
"tab_size": 2,
"translate_tabs_to_spaces": true
}
@esmevane
esmevane / with_interest.rb
Created February 11, 2013 15:11
[ Ruby ] Simple minitest + object-oriented recursion example "With interest"
require 'minitest/autorun'
require 'minitest/pride'
class WithInterest
def initialize amount, interest, years = 1
@amount = amount
@interest = interest
@years = years
end
@esmevane
esmevane / download.js.coffee
Created March 1, 2013 04:23
[ CoffeeScript ] iframe downloader hack
class Download
constructor: (@source) ->
@iframe = document.createElement 'iframe'
@iframe.style.display = 'none'
@iframe.src = @source
perform: -> document.body.appendChild @iframe
Download.Perform = (src) -> (new Download(src)).perform()
@esmevane
esmevane / minitest_mock_and_stub_combo.rb
Created April 27, 2013 01:38
[ Ruby / Minitest ] Example of mocking + stubbing in minitest
require 'minitest/autorun'
class Origin
attr_accessor :name
def set_name name
self.name = name
end
end
@esmevane
esmevane / measure.rb
Created May 9, 2013 21:24
[Ruby] A handy debug block method
def measure(method_name)
result = nil
time = Benchmark.measure do
result = yield if block_given?
end
puts "== DEBUG: #{method_name} benchmark time: #{time}"
return result
end
@esmevane
esmevane / expect_call.coffee
Created July 16, 2013 20:35
[ CoffeeScript / Jasmine ] Put this in your jasmine tests to abstract simple .toHaveBeenCalled() patterns
expectCall = (object, methodName, action) ->
spyOn object, methodName
action()
expect(object[methodName]).toHaveBeenCalled()
expectCall HE.Modal, 'modalDisplay', -> HE.Modal.InitDomPresence()
@esmevane
esmevane / singleton_example.coffee
Created September 3, 2013 23:28
[ CoffeeScript ] Singleton example with private functions
SingletonExample =
do ->
privateFunction = -> "I'm so hidden"
publicFunction = -> alert privateFunction()
publicFunction: publicFunction
SingletonExample.publicFunction()
alert SingletonExample.privateFunction()