Skip to content

Instantly share code, notes, and snippets.

View trevorturk's full-sized avatar

Trevor Turk trevorturk

  • Chicago
View GitHub Profile
@hishma
hishma / CLLocation+Encodable.swift
Created January 16, 2019 23:57
CoreLocation and Codable
extension CLLocation: Encodable {
public enum CodingKeys: String, CodingKey {
case latitude
case longitude
case altitude
case horizontalAccuracy
case verticalAccuracy
case speed
case course
case timestamp
@swalkinshaw
swalkinshaw / tutorial.md
Last active February 26, 2025 21:15
Designing a GraphQL API
@mrrooijen
mrrooijen / README.md
Created May 6, 2018 04:14
How to enable SSL with Redis (Ruby Driver) on RedisLabs.

How to enable SSL with [Redis] ([Ruby Driver]) on [RedisLabs].

Typically, this is how you'd connect to Redis:

Redis.new(url: ENV["REDIS_URL"])

Where REDIS_URL uses the following format:

@maxhis
maxhis / IAPHelper.swift
Created October 9, 2017 09:10
[iOS In App Purchase Helper] #swift #in_app_purchase
//
// IAPHelper.swift
// Bandwagon
//
// Created by Andy on 2017/9/27.
// Copyright © 2017年 Doraemon. All rights reserved.
//
import Foundation
import SwiftyStoreKit
@mmyoji
mmyoji / dynamo_scan_paging_with_ruby_sdk.md
Last active May 15, 2024 05:33
DynamoDB Scan paging w/ Ruby SDK
@theorygeek
theorygeek / association_loader.rb
Last active December 29, 2024 10:50
Preloading Associations with graphql-batch
# frozen_string_literal: true
class AssociationLoader < GraphQL::Batch::Loader
attr_reader :klass, :association
def initialize(klass, association)
raise ArgumentError, "association to load must be a symbol (got #{association.inspect})" unless association.is_a?(Symbol)
raise ArgumentError, "cannot load associations for class #{klass.name}" unless klass < ActiveRecord::Base
raise TypeError, "association #{association} does not exist on #{klass.name}" unless klass.reflect_on_association(association)
@klass = klass

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@iscott
iscott / simple_authentication_rails_5_bcrypt_and_has_secure_password.md
Last active November 14, 2024 10:54
Cheat Sheet: Simple Authentication in Rails 5 with has_secure_password

Cheat Sheet: Simple Authentication in Rails 6 with has_secure_password

The goal of this cheatsheet is to make it easy to add hand-rolled authentication to any rails app in a series of layers.

First the simplest/core layers, then optional layers depending on which features/functionality you want.

Specs
AUTHOR Ira Herman
LANGUAGE/STACK Ruby on Rails Version 4, 5, or 6
module SQLApprovals
def verify_sql(name:, &block)
# List to store executed queries
queries = []
# An event listener to record the normalized queries
subscriber = ->(_name, _start, _finish, _id, payload) do
# You'll likely need to filter unrelated queries,
# this is left as an exercise to the reader
queries << PgQuery.normalize(payload[:sql])
@yossorion
yossorion / what-i-wish-id-known-about-equity-before-joining-a-unicorn.md
Last active April 15, 2025 22:49
What I Wish I'd Known About Equity Before Joining A Unicorn

What I Wish I'd Known About Equity Before Joining A Unicorn

Disclaimer: This piece is written anonymously. The names of a few particular companies are mentioned, but as common examples only.

This is a short write-up on things that I wish I'd known and considered before joining a private company (aka startup, aka unicorn in some cases). I'm not trying to make the case that you should never join a private company, but the power imbalance between founder and employee is extreme, and that potential candidates would