Skip to content

Instantly share code, notes, and snippets.

View kevin-cantwell's full-sized avatar
🙃
cOmpUTerZ

Kevin Cantwell kevin-cantwell

🙃
cOmpUTerZ
View GitHub Profile
class BulkPrice
attr_accessor :quantity, :price
def initialize(quantity, price)
@quantity = quantity
@price = price
end
def price_per_item
price / quantity
end
end
@kevin-cantwell
kevin-cantwell / v2_api_mock.json
Last active August 29, 2015 14:03
Update this gist to give yourself whatever api response you wish.
{
"years": [
{
"year_month_day_key": "20130118",
"weather_summary": "86°F ☀️",
"user_contents": [
{
"id": "ftp:1203139203:910239123:912039:9231231",
"share": {
"prefill": "Exactly 1 year ago today! (via timehop.com)",
@kevin-cantwell
kevin-cantwell / goshim.md
Last active August 29, 2015 14:03
Philosophy of a Go dependency management system.

Goshim: Building a Better Go Dependency Management Tool

Go dependency management is essentially non-existent; this is known. It is also a source of frustration for many in the Go community. The standard Go tools are generally awesome, but the closest thing to dependency management Go provides out of the box is that go get will prefer VCS tags corresponding to the current go version. Afaik, nobody respects (or is even aware of) this convention. This is not entirely surprising, as Rob Pike himself has said that depedency management is a problem left for the community to solve. In fact, the reason why import statements are constructed with a string argument is to allow future support for arbitrary syntactic choices in specifying dependencies. I suspect that when the compiler is fully rewritten in Go, the community will jump at the chance to submit pull requests that support package versioning. Until then, we must build tools to help us strictly define our depe

@kevin-cantwell
kevin-cantwell / wedding_push.rb
Created October 18, 2014 16:01
Push to Benny & Laura's friends
four_pm = Time.parse('2014-10-18 20:00:00 +0000') # 4pm
benny = User.find(1)
laura = User.find(26)
friends << benny
friends << laura
friends += benny.friends_on_timehop;0
friends += laura.friends_on_timehop;0
friends.map do |friend|
notif = PushNotification.new(friend, PushReference.new(:blank_ref, :blank_id))
@kevin-cantwell
kevin-cantwell / example.go
Created November 14, 2014 22:31
v2 server example
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"github.com/timehop/services"
)
// Limits concurrent tasks to a limit of n. If limit is
// reached, return error instead of running task
type RateLimiter struct {
MaxConcurrent int
// Add whatever you need
taskChan chan struct{}
}
func (l *RateLimiter) Limit(task func()) error {
select {
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
const workers int 3
@kevin-cantwell
kevin-cantwell / sample_drain.go
Created April 16, 2015 21:28
Drain Sampler. Prints out dynamo keys for items currently in the drain.
package main
import (
"encoding/json"
"fmt"
"time"
"github.com/timehop/jimmy/redis"
)
@kevin-cantwell
kevin-cantwell / pg_idx_cache_hits.sql
Created April 28, 2016 19:01
Postgres Index+Cache Hit Query
-- Index hit rate
WITH idx_hit_rate as (
SELECT
relname as table_name,
n_live_tup,
round(100.0 * idx_scan / (seq_scan + idx_scan),2) as idx_hit_rate
FROM pg_stat_user_tables
WHERE seq_scan + idx_scan > 0
ORDER BY n_live_tup DESC
),
@kevin-cantwell
kevin-cantwell / makemake.txt
Last active May 1, 2016 16:02
Dotmatrix render of Makemake
⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣿⡽⣷⣿⣿⣿⣿⣿⣿⣿⣿⣻⣽⣯⢿⡷⢿⣾⣿⣿⣟⣷⢿⣧⣾⣿⢢⣀⣹⠛⠱⣵⢝⡍⠭⢱⣷⠢⢤⡤⠀⠁⡢⠀⢀⠀⠃⠀⢀⠣⠐⢀⠨⠐⠬⡂⢑⠄⡔⠦⢏⢌⢃⠔⠜⡝⠒⡋⠺⣙⢽⢟⣿⠉⣯⡭⣫⢽⣮⣟⣿⣿⣿⣪⣻⣽⡝⡴⣪⣟⡳⡿⣗⢟⡽⡿⢟⣿⣿⣿⣻⣿⠿⣿⣷⣗⣿⣟⣷⣟⣯⣽⣼⣿⠿⣭⡿⡿⣵⣿⣿⣿⣧⣟⣯⡿⣿⣾⣶⣿⣽⣿⣺⣾⢿⣾
⣿⣾⣿⣿⣿⣿⣹⣿⣷⢿⣿⣾⣿⣿⣷⣿⣿⣛⣷⣿⣿⣾⣾⣿⣿⣟⣿⣿⣿⣿⡿⣿⣿⢿⣿⣿⣿⣷⣧⣾⣷⢿⢧⣿⣽⣌⣼⡼⣵⣒⡡⠀⣤⡃⠀⠄⠀⠀⠒⠀⠀⠀⠀⠀⠀⠠⠀⠢⡄⠙⡠⢜⢖⠀⠊⠩⡙⣿⣪⠞⢿⡾⣯⠌⣽⣭⡷⣫⣰⢿⢭⡫⣿⢿⢯⣽⢯⢾⣷⣮⣗⣯⣾⢑⣿⣶⣍⣾⠯⣷⣿⣯⣷⣟⢿⡾⣿⣷⣿⣽⣳⣷⣿⣗⣟⢽⣿⣻⣿⣿⠯⣟⢿⣿⣿⣿⣿⣿⣿⡹⣿⣾⣿⣿⣻⣯⡽⣿⣿⣾
⣿⢿⣿⣿⡿⣿⣽⣿⣿⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢼⡿⣿⣿⣷⣿⡿⡟⢽⡾⡿⣙⡻⣔⢿⣒⢭⣝⢷⣉⠄⠲⠈⢠⠜⠩⠄⠐⠐⠀⠀⠐⠀⠀⠀⠀⠀⠀⠂⠀⠩⠔⡘⠜⠋⡕⡜⣩⡜⠂⠻⠝⡥⠦⠫⢾⣻⡵⠗⣩⣷⡷⣯⣦⣿⣽⢯⣟⠻⣖⣾⡿⣻⣿⣿⣯⠏⣿⣿⣾⣮⣿⣿⣾⢿⡿⡛⣑⣿⣙⢲⣿⣿⣿⡟⣻⣿⣽⣾⣯⣻⡷⣽⢚⣻⣿⣿⣿⣿⢿⢽⠽⢽⡿⣻⣾⢻⣻⣿⣿⣿⣿
⡯⢯⣿⣿⣿⣻⣿⣿⣿⣿⣿⣿⢷⣿⣯⣻⡷⣿⣾⣿⣻⣿⣿⣿⣿⣿⣿⣿⣿⣟⣿⣿⣿⣿⣿⣿⣺⣟⡏⣽⡹⠰⠧⣻⣖⠣⢸⣇⠤⣞⡫⠐⢈⠆⠀⠂⠀⠀⠀⠈⠀⠀⠀⠈⠀⠀⠀⠀⠎⢫⠉⣂⠕⢬⠑⡉⠙⡀⠋⢳⠳⡤⠗⡰⠟⡱⢦⢴⠟⣵⢟⣔⣿⣽⣧⢻⠆⢺⣿⠏⣬⢵⣩⣿⡏⣽⣶⣿⣙⣯⣿⣫⣯⣷⣉⣽⣟⢻⣿⣿⣿⣾⣿⡿⣿⣯⣿⣿⣽⢿⣻⣽⣼⣿⢻⣿⣷⣿⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣻
⣿⣿⣿⣿⡟⣿⣯⣿⣿⣿⣿⣿⣿⣽⣟⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣿⣿⣯⡻⣿⣿⣿⢪⣭⣷⣥⣛⣿⠠⢰⢾⣄⠎⡠⠞⣉⠀⢈⢐⠠⠀⢠⠁⠀⠀⠀⠅⠀⠀⠀⠀⠀⢀⡀⠢⠯⠒⠁⢎⠈⢆⣝⣀⣞⡂⣏⣛⢎⣦⢾⢿⣿⣼⢺⢩⣾⣹⣯⣯⣳⢯⡷⣷⡥⣻⣫⡿⣽⢜⢿⣽⣿⣿⣿⣟⡾⡿⣿⢴⣿⣿⣦⣿⠿⣿⣿⡻⣿⣭⣿⣭⡟⣿⣏⣿⢟⣿⣿⣿⣥⡫⣴⣿⣿⣿⣿⣞⣟⣿⣿⣽⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⣿⣿⣼⣿⣿⣾⣿⣿⣾⣿⡿⣿⣿⣿⡿⣾⣻⠾⢾⣷⡹⢏⡿⢿⡑⣻⡟⡿⡿⡝⡟⣔⢮⠍⡆⡔⢖⠎⠊⢕⡐⠈⠄⠄⠂⠂⠀⡀⠀⠈⠀⠀⠀⠂⠀⠀⠀⢈⢡⣉⢀⢰⠌⠋⠈⠩⠒⣸⣟⢪⢽⣿⣟⠿⣽⠮⣽⣼⢿⠯⢹⢟⣧⣽⠿⠿⣏⣒⣿⣿⣿⢩⣺⢮⣿⣻⡟⡿⠭⣟⣿⣿⣻⢿⡷⣿⢿⡷⡽⣟⣻⣟⣿⣿⣷⣯⣿⢿⣺⡿⣾⣿⣯⣽⣽⣿⣻⣿⣟⣿⣿⣶⣼⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⡿⣿⣟⣿⣿⣿⡿⣟⣿⣿⣿⣻⣿⣿⣿⣷⣷⣿⣿⢿⣿⣿⣿⣿⣷⣿⣿⡟⣟⣛⣻⣚⡳⣏⣵⣻⣿⣿⡅⣹⢪⠇⡁⠬⣋⢀⠠⡡⠀⠺⢀⠊⠀⠀⠀⠀⠀⢐⠀⠀⠀⠀⠀⠀⡄⠇⠃⠴⠃⢆⠚⢵⠮⡍⡷⢧⢳⠷⡻⣿⣽⣿⣫⠽⡽⡪⣾⠮⠙⣿⡹⣹⡯⢾⣗⡳⣾⣏⣾⣯⣶⣭⡿⣮⣽⣝⣺⣴⣫⣶⣾⣋