Skip to content

Instantly share code, notes, and snippets.

View adamstrickland's full-sized avatar

Adam Strickland adamstrickland

  • New York, NY
View GitHub Profile
module Mongoid
class << self
def Money(value)
Money.create_from_value(value)
end
end
class Money
class << self
def create_from_value(value)
class Product
field :traits, type: Array, default: []
after_initialize :load_traits!
on_save :validates_methods
def load_traits!
self.traits.each do |trait|
self << class
self.send(:include, trait.camelize.constantize)
class AutomaticExpirationDate < Molecule::Mechanics::Repercussion
extend Molecule::ExchangeConcepts
def act(subj, *args)
subj.pricing.expiry = self.class.expires_day_before(subj.tenor_start) if subj.option?
# Molecule::ExchangeConcepts.expires_day_before is .get_expiry *without* the call to .calculate_expiry
end
end
ng_products = Product.where(:"commodity.name" => /ng/i).each do |p|
p.expiry_rule = :preceeding_weekday
end
@adamstrickland
adamstrickland / calling_out.js
Last active December 17, 2015 08:18
jquery callback
MyObject = {
respondToCallback: function (response, context) {
// context will === "abc123" when called via doingSomething()
},
doingSomething: function(callback) {
var _foo = "abc123";
var _self = this;
var _default_callback = function (resp, status, jqxhr) {
_self.respondToCallback(response, _foo);
};
@adamstrickland
adamstrickland / widget_context.rb
Last active December 15, 2015 11:49
A shared context for RSpec'ing Apotomo Widgets with Devise mixed in
shared_context "widget" do
let(:widget_klass) { self.described_class }
let(:widget_name) { widget_klass.to_s.underscore.gsub(/_widget/, '') }
let(:widget_instance) { root.find_widget(widget_name) }
let(:current_user) { create(:user) }
before {
self.class.has_widgets do |r|
r << widget(widget_name)
end
class Audit
include Mongoid::Document
include Mongoid::Timestamps
include RailsAdminImport::Import
class << self
def create_with_type_message_meta(_type, _message, _user)
self.create_without_type_message_meta({
:type => _type,
:content => _message,
@adamstrickland
adamstrickland / ko.bindingHandler.visualize.js
Created January 23, 2013 19:31
position plotting ***WORK IN PROGRESS***
ko.bindingHandlers.visualize = {
update: function (elem, acc, all, ctx, vm) {
vm.visualization.update();
},
init: function (elem, acc, all, ctx, vm) {
var _options = ko.utils.unwrapObservable(acc)();
var _data = (_options.data() || []);
var _height = _options.height || 250;
var _width = _options.width || 506;
var _default_color_scheme = 'cool'; // other options: 'spectrum14', 'colorwheel', 'spectrum2000', 'spectrum2001', 'classic9'
ko.bindingHandlers.daterangepicker = {
_defaultStart: function () {
return moment().add('months', 1).startOf('month').toDate();
},
_defaultEnd: function () {
return moment().add('months', 1).startOf('month').add('years', 1).subtract('days', 1).toDate();
},
_deriveStartDate: function (_options) {
@adamstrickland
adamstrickland / gist:3006114
Created June 27, 2012 19:11
sample workflow in js
function generateLead (lead, _callback) {
var _lead = {
id: lead.correlationId || generateCorrelationId(),
foo: 'foo',
bar: 'bar'
};
var _respond = function (attrs) {
_callback($.extend(attrs, _lead)); //invoke the _callback provided by client
};
clarity.inquireAsync(lead, function (_data) {