Skip to content

Instantly share code, notes, and snippets.

View adamkuipers's full-sized avatar

Adam Kuipers adamkuipers

View GitHub Profile
; Find Nth algorithm
;
; This algorithm finds the nth largest element in a list. First, it sorts
; the list in descending order and then places the value at index n in
; location 127.
;
; Dynamic Instruction Count for 19.b. at location 30
; 18,240 instructions
; 30th largest element in given array is 32
;
@adamkuipers
adamkuipers / gist:12578343d31a651bee4a
Last active August 29, 2015 14:06
ActiveRecord failing at batch-insert
irb(main):083:0> order.save.explain
(0.4ms) BEGIN
SQL (15.1ms) INSERT INTO "orders" ("address_id", "created_at", "customer_id", "order_request_id", "price_cents", "shipping_price_cents", "source", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "id" [["address_id", 291085], ["created_at", Wed, 10 Sep 2014 19:07:34 UTC +00:00], ["customer_id", 63601], ["order_request_id", "2687c3b4-c0b3-44a1-887d-04073ae62d1b"], ["price_cents", 8900], ["shipping_price_cents", 1200], ["source", "web-cart"], ["updated_at", Wed, 10 Sep 2014 19:07:34 UTC +00:00]]
SQL (4.1ms) UPDATE "customers" SET "orders_count" = COALESCE("orders_count", 0) + 1 WHERE "customers"."id" = 63601
SQL (7.9ms) INSERT INTO "order_items" ("created_at", "order_id", "photo_count", "printer", "product", "source", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["created_at", Wed, 10 Sep 2014 19:07:34 UTC +00:00], ["order_id", 80566], ["photo_count", 3], ["printer", 1], ["product", "calendardateless"], ["so
@adamkuipers
adamkuipers / gist:49d76c6494eb50d49821
Created November 24, 2014 20:31
Creating rabbitmq connection on after_fork callback.
Resque.after_fork do |job|
$rabbitmq_connection = Bunny.new(AMQP_URL)
$rabbitmq_connection.start
$rabbitmq_channel = $rabbitmq_connection.create_channel
$rabbitmq_exchange = $rabbitmq_channel.topic('stream', durable: true)
end
@adamkuipers
adamkuipers / readableweb
Created July 1, 2015 06:06
The Readable Web
adamkuipers@Adams-MacBook-Air ~
% curl https://www.google.com/\#q\=elm+lang !10002
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description"><meta content="noodp" name="robots"><meta content="/images/google_favicon_128.png" itemprop="image"><title>Google</title><script>(function(){window.google={kEI:'jIKTVYOpE5bioASHj4SoDw',kEXPI:'3700268,4010073,4029815,4032235,4032500,4032677,4032998,4033307,4033344,4036363,4036366,4036425,4036471,4036486,4036847,4036948,4037333,4037457,4037855,4037921,4037960,4038216,4038417,4038464,4038961,4039016,4039046,4039263,4039280,4039382,4039386,4039403,4039879,4039908,4040020,4040028,4040117,4040136,8300096,8300200,8300202,8500394,8501258,8501295,8501407,8501489,10200083',authuser:0,kscs:'c9c918f0_10'};google.kHL='en';})();(functio
@adamkuipers
adamkuipers / gist:5d50202dd2ef5959e86e
Last active August 29, 2015 14:26
ondir GIT_COMMITTER_EMAIL change
adamkuipers@Adams-MacBook-Pro ~
% echo $GIT_COMMITTER_EMAIL
adamkuipers@Adams-MacBook-Pro ~
% cd development/sps/PrintStudio-iOS
adamkuipers@Adams-MacBook-Pro ~/development/sps/PrintStudio-iOS [country-picker *]
± % echo $GIT_COMMITTER_EMAIL
adam@socialprintstudio.com
@adamkuipers
adamkuipers / FunctionOverloading.swift
Created October 9, 2015 19:55
Function overloading swift bug
// Doesn't work.
func doBimpy(f1: Bimpy, _ f2: Bimpy) -> Bimpy {
return Bimpy()
}
// Works
func doBimpy2(f1: Bimpy, _ f2: Bimpy) -> Bimpy {
return Bimpy()
}
@adamkuipers
adamkuipers / hk.swift
Last active December 8, 2015 19:46
Higher-kinded types encoded as path-dependent types
// Based off of https://gist.github.com/runarorama/33986541f0f1ddf4a3c7
protocol λ {
typealias α
}
struct K<L: λ>: λ {
typealias α = L.α
}
class Parser<T> : StringLiteralConvertible {
typealias StringLiteralType = Swift.StringLiteralType
typealias ExtendedGraphemeClusterLiteralType = ExtendedGraphemeClusterType
typealias UnicodeScalarLiteralType = UnicodeScalarType
let token: String
required init(stringLiteral value: StringLiteralType) {
self.token = value
}
scala> val x1: Float = Long.MaxValue
x1: Float = 9.223372E18
scala> val x2 = Long.MaxValue - Int.MaxValue
x2: Long = 9223372034707292160
scala> x1 == x2
res0: Boolean = true
@adamkuipers
adamkuipers / heterogeneous.swift
Created December 8, 2015 20:44
Heterogeneous List in Swift
//: Playground - noun: a place where people can play
protocol HList {}
struct HNil: HList {}
struct HCons<Element, List: HList>: HList {
let head: Element
let tail: List
}
infix operator |*| { associativity right }