Skip to content

Instantly share code, notes, and snippets.

View kwiest's full-sized avatar

Kyle Wiest kwiest

  • Blue Bottle Coffee
  • Eugene, OR
View GitHub Profile
@kwiest
kwiest / consumer.test.ts
Created January 20, 2022 17:18
Example consumer contract test
import { Pact } from "@pact-foundation/pact";
import { like } from "@pact-foundation/pact/src/dsl/matchers";
import { CartApi } from ".";
const provider = new Pact({
consumer: "MockCartConsumer",
provider: "CartService",
logLevel: "info",
});
@kwiest
kwiest / generated.json
Created November 20, 2019 01:40
Poor Man's PIM
{"idempotency_key":"1475d547-7b0e-48c5-bd28-e74700a9d82a","batches":[{"objects":[{"item_data":{"name":"Kyle's Test Item","variations":[{"item_variation_data":{"pricing_type":"FIXED_PRICING","location_overrides":[{"location_id":"WMYW60XEVK9MD","track_inventory":true,"price_money":{"amount":550,"currency":"USD"}}],"name":"Hayes Valley","price_money":{"amount":450,"currency":"USD"}},"present_at_location_ids":["WMYW60XEVK9MD","S7CWFDJ0Y3PD5"],"present_at_all_locations":false,"id":"#Hayes Valley","type":"ITEM_VARIATION"}]},"id":"#Kyle's Test Item","type":"ITEM"}]}]}
@kwiest
kwiest / MySet.scala
Created June 15, 2019 01:12
Implementing a set as a function
// Traits are like interfaces
trait MySet[A] extends (A => Boolean) {
def apply(element: A): Boolean = contains(element)
def contains(element: A): Boolean
def +(element: A): MySet[A]
def ++(otherSet: MySet[A]): MySet[A]
def -(element: A): MySet[A]
def --(otherSet: MySet[A]): MySet[A]
@kwiest
kwiest / mapVsFor.scala
Last active September 22, 2017 23:55
Understanding flatMap and for comprehentions
// Options can be one of 2 things: Something (Some) or nothing (None)
// Because it is "collection" of 2 outcomes, you can iterate using `map`
// Define a function to pass around that uppercases a String or Char
val up : (Any) => Any = (item) => {
item match {
case item: String => item.toUpperCase
case item: Char => Char.toUpperCase(item)
}
}

Keybase proof

I hereby claim:

  • I am kwiest on github.
  • I am kylewiest (https://keybase.io/kylewiest) on keybase.
  • I have a public key whose fingerprint is 4DAE EBFD D13A BF0E EF6F 7778 3261 4640 F345 24F3

To claim this, I am signing this object:

@kwiest
kwiest / query_playground.rb
Last active August 29, 2015 14:15
Complex queries in ActiveRecord
# Trying to re-create a JOIN on a nested SELECT query first in Arel, and then convert to Rails
# SELECT campers.*, payments.total_paid
# FROM campers
# LEFT OUTER JOIN (
# SELECT payments.source_id, SUM(payments.amount_cents) AS total_paid
# FROM payments
# WHERE payments.source_type = 'Camper' AND payments.state = 'paid'
# GROUP by payments.source_id
# ) payments
@kwiest
kwiest / example.rb
Last active December 21, 2015 08:09
Rails engine does not recognize #layout call in production
# Rails 3.2.12
# Rails engine
# app/controllers/puddy/application_controller.rb
modue Puddy
class ApplicationController < ActionController::Base
layout 'puddy/dashboard'
#...
end
@kwiest
kwiest / after_callbacks_test.rb
Last active December 12, 2015 13:48
Error with lambda variable scope Not retaining local vars on creation Non rails version works as I expect
class EncryptedAttributesWithAfterCallbacksTest < MiniTest::Unit::TestCase
def setup
@password = ''
@ran_callback = false
callback = lambda { |record|
p 'Callback being called...'
@password = record.password
@ran_callback = true
}
@kwiest
kwiest / gist:2845726
Created May 31, 2012 19:38
Redis Cannot Connect Error
# When I run the test when Redis is running, all tests pass
# When I run the test with Redis purposefully off, I get the error at the end of the gist
#
# I've tried manually raising Redis::CannotConnectError instead of calling Redis.new
# and a new instance of SimpleStore is returned, and again all tests pass
# Gemfile
gem 'redis', '~> 3.0.0'
@kwiest
kwiest / gist:2714778
Created May 16, 2012 23:08
Migration example
# Migration (created from Devise)
class DeviseCreateUsers < ActiveRecord::Migration
def self.up
create_table(:users) do |t|
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable
t.string :name