Skip to content

Instantly share code, notes, and snippets.

View ktusznio's full-sized avatar
🥙
might be eating a pita

Kamil Tusznio ktusznio

🥙
might be eating a pita
View GitHub Profile
@ktusznio
ktusznio / address_fields.haml
Created December 2, 2012 07:04
Haml address fields
%input(type="hidden" name="address[id]" value="#{address.id}")
%fieldset
%ul
%li
%label(for="address[first_name]") First Name
%input(type="text" name="address[first_name]" value="#{address.first_name}" size="20")
%li
%label(for="address[last_name]") Last Name
%input(type="text" name="address[last_name]" value="#{address.last_name}" size="20")
Threadflip.InfiniteScrollCollection =
infiniteScroll: (options) ->
success = options.success || ->
offset = options.offset || 400
enabled = false
start = (params = {}) ->
unless enabled
# Bind to the scroll event.
$(window).scroll onScroll
describe Purchase do
let(:have_1) { FactoryGirl.build_stubbed(:have, asking_price: 15) }
let(:have_2) { FactoryGirl.build_stubbed(:have, asking_price: 20) }
describe "#amount_for_haves" do
let(:amount_for_haves) { purchase.amount_for_haves([have_1, have_2], credit, promo) }
let(:credit) { 0 }
let(:expected_amount_for_haves) do
# Order haves by asking_price, high to low.
have_2_expected_amount_hash.merge(have_1_expected_amount_hash)
@ktusznio
ktusznio / have.rb
Last active December 11, 2015 04:58
def available_if_enough_info
if self.available? || self.display_only?
if self.can_be_available?
self.available!
else
self.display_only!
end
end
end
@ktusznio
ktusznio / spec.rb
Created January 25, 2013 03:26
Break a big object up into smaller dependencies that are defined per context. This avoids redefining the big object for each context.
describe Foo do
let(:big_params) do
{
foo: foo,
name: "name",
...
}
end
let(:foo) { nil }
class BaseView extends Backbone.View
template: ""
# Render hooks.
beforeFirstRender: ->
beforeRender: ->
afterRender: ->
afterFirstRender: ->
render: =>
class InFlip
initialize: (options) ->
@set 'stripe_token', new Threadflip.StripeToken(options.stripeToken)
fetchStripeToken: ->
@get('stripe_token').fetch()
def solution(strengths, weights, connections)
# simulate the order by going through the conections and building the graph
# at each step, evaluate the graph to detect breaks
# at each step, attach the weight, then travel up the graph and check for breaks O(n * log(n))
# data structure:
# node(parent_node, strength, weight (incl. children), children)
# map(i: node)
# create root node
class LRUCache
MAX_SIZE = 3
def initialize
@cache = {}
@max_size = MAX_SIZE
@lru_list = List.new
end
def get(key)
var $ = require('jQuery');
var _ = require('_');
var React = require('react');
var FinancingApplicationView = require('financing/views/FinancingApplicationView.react.jsx');
var FinancingConstants = require('financing/FinancingConstants.js');
var FinancingApplicationData = require('financing/models/FinancingApplicationData.js');
var FinancingApplicant = require('financing/models/FinancingApplicant.js');
var activeApplicant = new FinancingApplicant();