Skip to content

Instantly share code, notes, and snippets.

@ktheory
ktheory / chef_workflow.md
Created December 14, 2012 19:14
Chef workflow

Cookbook workflow

Prereqs:

Install chef gem (for knife command):

gem install chef

Create a new cookbook:

knife cookbook create my_cookbook

@ktheory
ktheory / bsearch.gemspec
Created July 31, 2012 19:48
Binary search gem
# -*- encoding: utf-8 -*-
$:.unshift '.'
require 'bsearch'
Gem::Specification.new do |s|
s.name = 'bsearch-ruby'
s.version = BSearch::VERSION
s.authors = ["Aaron Suggs"]
s.description = "A binary search implementation in ruby"
@ktheory
ktheory / rack-attack.rb
Created July 25, 2012 14:31
rack-attack DSL
# NB: `req` is a Rack::Request object (basically an env hash with friendly accessor methods)
# Throttle 10 requests/ip/second
# NB: return value of block is key name for counter
# falsy values bypass throttling
Rack::Attack.throttle("req/ip", :limit => 10, :period => 1.second) { |req| req.ip }
# Block cloud IPs from accessing PATH regexp
Rack::Attack.block "bad_ips from logging in" do |req|
@ktheory
ktheory / 0001-Whitespace-tabs-to-spaces.patch
Created June 25, 2012 13:36
Patch to unicorn example init script: better upgrade task
From 233f504a39aca6e8b2d9332ef324b4c5cc397eca Mon Sep 17 00:00:00 2001
From: Aaron Suggs <[email protected]>
Date: Fri, 6 Apr 2012 18:35:38 -0400
Subject: [PATCH 1/2] Whitespace: tabs to spaces
---
examples/init.sh | 90 +++++++++++++++++++++++++++---------------------------
1 files changed, 45 insertions(+), 45 deletions(-)
diff --git a/examples/init.sh b/examples/init.sh
@ktheory
ktheory / 0001-Whitespace-tabs-to-spaces.patch
Created May 9, 2012 19:56
Patch to unicorn example init script: better upgrade task
From 130b610b4e67bcad522a268f1d3f221e8d12ebb0 Mon Sep 17 00:00:00 2001
From: Aaron Suggs <[email protected]>
Date: Fri, 6 Apr 2012 18:35:38 -0400
Subject: [PATCH 1/2] Whitespace: tabs to spaces
---
examples/init.sh | 90 +++++++++++++++++++++++++++---------------------------
1 file changed, 45 insertions(+), 45 deletions(-)
diff --git a/examples/init.sh b/examples/init.sh
Gem::Specification.new do |s|
s.name = 'bang'
s.version = '0.1.0'
s.platform = Gem::Platform::RUBY
s.author = 'Jeff Kreeftmeijer'
s.email = '[email protected]'
s.summary = 'Bang!'
s.description = 'Bangs existing model methods'
s.files = ['bang.rb']
@ktheory
ktheory / query_trace.rb
Created February 29, 2012 16:58 — forked from belt/query_trace.rb
QueryTrace... ported to rails3
require 'term/ansicolor'
# yeilds a stacktrace for each SQL query
# put this file in config/initializers
class QueryTrace < ActiveSupport::LogSubscriber
include Term::ANSIColor
attr_accessor :trace_queries
def sql(event) #:nodoc:
return unless QueryTrace.enabled? && logger.debug? && Rails.env.development?
@ktheory
ktheory / enumerable_pluck.rb
Created February 15, 2012 22:54
An Enumerable#pluck method for ruby
module Enumerable
def pluck(key)
map {|obj| obj[key] }
end
end
@ktheory
ktheory / shit_ror_devs_say.txt
Created February 13, 2012 15:22
Shit Ruby on Rails Developers Say
Did you upgrade to rails 3 yet?
I made a rake task for that.
1.8.7, or 1.9.3?
Did you know there's a rake task for that?
Did you upgrade to rails 3.1 yet?
Did you see my pull request?
Did you upgrade to rails 3.2 yet?
I commented on your pull request.
You need to run bundle install first
rb-env or rvm?
@ktheory
ktheory / git_io.gemspec
Last active March 15, 2016 14:25
A ruby helper for making git.io short urls
Gem::Specification.new do |s|
s.name = 'git_io'
s.version = '1.0.0'
s.platform = Gem::Platform::RUBY
s.author = 'Aaron Suggs'
s.email = '[email protected]'
s.summary = 'Shorten urls with git.io'
s.description = 'GitIo.shorten(url)'
s.homepage = 'https://gist.github.com/1762136'