Skip to content

Instantly share code, notes, and snippets.

View drewtempelmeyer's full-sized avatar
👋

Drew Tempelmeyer drewtempelmeyer

👋
View GitHub Profile
@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"
@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 } }
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 / devmux.sh
Created January 24, 2017 14:30
Automatically set up development environment for Rails/Ember applications
#!/bin/bash
# Set up variables
run_server=true
show_help=false
# Set up the server command
if [ -f 'ember-cli-build.js' ]; then
SERVER_CMD='ember server --proxy http://localhost:3000'
elif [ -f 'bin/rails' ]; then

Keybase proof

I hereby claim:

  • I am drewtempelmeyer on github.
  • I am tempelmeyer (https://keybase.io/tempelmeyer) on keybase.
  • I have a public key whose fingerprint is 9176 E981 1EF3 D6EB 4A79 9C89 3CCE 543A E3CC B9BC

To claim this, I am signing this object:

@drewtempelmeyer
drewtempelmeyer / balanced-validators.js
Created January 11, 2014 20:57
jQuery Validation methods for Balanced.js
/**
* Balanced.js Validators
*
* jQuery Validation methods for use with Balanced.js
*/
;(function($) {
"use strict";
/**
@drewtempelmeyer
drewtempelmeyer / settings.py
Created January 31, 2013 15:20
django-cumulus + easy-thumbnails
DEFAULT_FILE_STORAGE = 'cumulus.storage.CloudFilesStorage'
THUMBNAIL_DEFAULT_STORAGE = DEFAULT_FILE_STORAGE
@drewtempelmeyer
drewtempelmeyer / mixins.py
Created January 30, 2013 01:27
Django SSL Mixin
from django.conf import settings
from django.http import HttpResponseRedirect
class SSLRequiredMixin(object):
def dispatch(self, request, *args, **kwargs):
if settings.DEBUG is False and request.is_secure() is False:
host = request.get_host()
url = 'https://%s%s' % (host, request.get_full_path())
return HttpResponseRedirect(url)
return super(SSLRequiredMixin, self).dispatch(request, *args,**kwargs)
User.limit(1).first # User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`deleted_at` IS NULL LIMIT 1
User.first # User Load (0.6ms) SELECT `users`.* FROM `users` WHERE `users`.`deleted_at` IS NULL LIMIT 1
User.first.class.to_s # => User
User.limit(1).all.class.to_s # => Array
result = @transaction.lookup[:lookup_response][:lookup_result]
cart_item_response = result[:cart_items_response][:cart_item_response]
total_tax = cart_item_response.map { |item| item[:tax_amount].to_f }.inject(:+)