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 / day-18.js
Last active December 19, 2021 04:46
day-18.js
const fs = require('fs');
const input = fs.readFileSync("./day-18/input.sample", "utf8").split("\n");
function magnitude(num) {
if (typeof num === "number") return num;
const [left, right] = num;
return 3 * magnitude(left) + 2 * magnitude(right);
}
@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;
export function loadSegment(writeKey) {
if (!writeKey) {
throw new Error("loadSegment: blank writeKey.");
}
var analytics = (window.analytics = window.analytics || []);
if (!analytics.initialize)
if (analytics.invoked)
window.console &&
console.error &&
### Keybase proof
I hereby claim:
* I am ktusznio on github.
* I am ktusznio (https://keybase.io/ktusznio) on keybase.
* I have a public key ASA4KeJnQKl5ok63_6cNVA9r4R51CFiBzKJ8OErfoZvgawo
To claim this, I am signing this object:
@ktusznio
ktusznio / _hero.scss
Created July 28, 2017 16:44
Responsive SASS mixins for retina displays
.hero {
background: url('/images/hero-mobile.jpg') no-repeat center center;
background-size: cover;
@include breakpoint(tablet) {
background-image: url('/images/hero.jpg');
}
@include retina {
background-image: url('/images/hero-mobile@2x.jpg');
class InFlip
initialize: (options) ->
@set 'stripe_token', new Threadflip.StripeToken(options.stripeToken)
fetchStripeToken: ->
@get('stripe_token').fetch()
class BaseView extends Backbone.View
template: ""
# Render hooks.
beforeFirstRender: ->
beforeRender: ->
afterRender: ->
afterFirstRender: ->
render: =>
@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)