Skip to content

Instantly share code, notes, and snippets.

View drewtempelmeyer's full-sized avatar
👋

Drew Tempelmeyer drewtempelmeyer

👋
View GitHub Profile
class Funko
# Add these scopes to your model
scope :for_user, ->(user) { where(user: user) }
scope :for_category, ->(category) { joins(:category).where(categories: { name: category }) }
scope :newest, -> { order(created_at: :desc) }
end
def index
category = params[:category]
@funkos = Funko.newest
@drewtempelmeyer
drewtempelmeyer / array-detect-hash.rb
Created February 11, 2020 21:22
Array#detect vs Hash#[]
# This benchmark assumes we're consistently looking for the last
# item in the array.
#
# If you want to use a random number, use i = rand(1..20) in both
# reports.
require "benchmark"
n = 500_000
arr = (1..20).map { |i| { id: i } }
@drewtempelmeyer
drewtempelmeyer / main.go
Created July 27, 2020 20:52
super simple url shortener #golang
package main
import (
"context"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"