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 / 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 }
@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
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)
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
@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")
@ktusznio
ktusznio / state_options.haml
Created November 13, 2012 21:43
HAML state options
%select
%option(value="AL") Alabama
%option(value="AK") Alaska
%option(value="AZ") Arizona
%option(value="AR") Arkansas
%option(value="CA") California
%option(value="CO") Colorado
%option(value="CT") Connecticut
%option(value="DE") Delaware
%option(value="FL") Florida
@ktusznio
ktusznio / dollarize.coffee
Created October 26, 2012 08:08
Dollarize helper in Coffeescript
dollarize = (n, currency = "$", decimals = 2,
decimalSeparator = ".", thousandsSeparator = ",") ->
if n instanceof String
n = parseInt n, 10
sign = if n < 0 then "-" else ""
wholeDigits = "" + Math.abs(n - (n % 1))
@ktusznio
ktusznio / NSManagedObject+KTManagedObject.h
Created July 16, 2012 18:26
Core Data Categories to get started with Core Data
//
// NSManagedObject+KTManagedObject.h
// Created by Kamil Tusznio on 12-07-10.
//
#import <CoreData/CoreData.h>
@interface NSManagedObject (KTManagedObject)
+ (NSArray *)fetchAll;
@ktusznio
ktusznio / gist:1790846
Created February 10, 2012 16:53
batman.js checkbox example
<!DOCTYPE html>
<html>
<head>
<title>Test App</title>
<script type="text/javascript" src="../lib/es5-shim.js"></script>
<script type="text/javascript" src="../lib/batman.js"></script>
<script type="text/javascript" src="../lib/batman.solo.js"></script>
<script type="text/javascript" src="../lib/extras/batman.rails.js"></script>
<script type="text/javascript" src="../lib/coffee-script.js"></script>
</head>
@ktusznio
ktusznio / controller.coffee
Created January 10, 2012 21:24
Batman Filtering
class Shopify.OrdersController extends Shopify.ApplicationController
index: (params) ->
@allOrders = Shopify.Order.get('all')
@_filterOrders()
addFilter: (type, value) ->
@set "#{type}Filter", value
@_filterOrders()
_filterOrders: ->