Skip to content

Instantly share code, notes, and snippets.

View djbender's full-sized avatar
🕵️‍♂️

Derek Bender djbender

🕵️‍♂️
View GitHub Profile
@danielberlinger
danielberlinger / performance.rb
Created March 27, 2012 20:10
A Rails initializer for using Rails 3 notifications and statsd
require 'statsd'
$statsd = Statsd.new('your_host_here')
ActiveSupport::Notifications.subscribe /process_action.action_controller/ do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
controller = event.payload[:controller]
action = event.payload[:action]
format = event.payload[:format] || "all"
format = "all" if format == "*/*"
status = event.payload[:status]
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active May 11, 2025 00:12
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'

Core ideas

  • An Object is a set of instance variables and a pointer to a 'singleton class'.
  • Properties are looked up in the instance variables, methods are dispatched via the singleton class.
  • Module is a subtype of Object. A Module is a set of methods and an ordered list of zero-or-more 'parent' modules.
  • Module A becomes a parent of module B via B.include(A).
  • Method lookup works by doing a depth-first right-to-left search of a module tree.
  • Class is a subtype of Module. A Class is a Module that can be instantiated.
  • A Class has only one 'superclass'. A class includes its superclass as its first parent module for the purposes of method dispatch. A class's singleton class includes the superclass's singleton class as its first parent.
  • The default superclass of all classes is Object.
@michaelkoper
michaelkoper / gist:5007636
Last active January 25, 2018 18:25
Handling with money in Mongoid
class Product
include Mongoid::Document
field :price, type: Money
end
Money.class_eval do
# Converts an object of this instance into a database friendly value.
def mongoize
@justincampbell
justincampbell / after.sh
Created March 1, 2013 17:45
Jenkins + GitHub Commit Status API
if [[ $BUILD_STATUS == "success" ]]
then
export STATUS="success"
else
export STATUS="failure"
fi
curl "https://api.github.com/repos/justincampbell/my_repo/statuses/$GIT_COMMIT?access_token=abc123" \
-H "Content-Type: application/json" \
-X POST \
@neerajsingh0101
neerajsingh0101 / with_published_versions.rb
Last active December 15, 2015 02:28
How to write Active Record bug report when you are using published versions of gems. More details at https://gist.github.com/neerajdotname/5187216 .
gem 'activerecord', '3.2.12'
require 'active_record'
require "minitest/autorun"
require 'minitest/pride'
require 'logger'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
static LINES: [ &'static str, ..20 ] = [
"..............3.85..1.2.......5.7.....4...1...9.......5......73..2.1........4...9 near worst case for brute-force solver (wiki)",
".......12........3..23..4....18....5.6..7.8.......9.....85.....9...4.5..47...6... gsf's sudoku q1 (Platinum Blonde)",
".2..5.7..4..1....68....3...2....8..3.4..2.5.....6...1...2.9.....9......57.4...9.. (Cheese)",
"........3..1..56...9..4..7......9.5.7.......8.5.4.2....8..2..9...35..1..6........ (Fata Morgana)",
"12.3....435....1....4........54..2..6...7.........8.9...31..5.......9.7.....6...8 (Red Dwarf)",
"1.......2.9.4...5...6...7...5.9.3.......7.......85..4.7.....6...3...9.8...2.....1 (Easter Monster)",
".......39.....1..5..3.5.8....8.9...6.7...2...1..4.......9.8..5..2....6..4..7..... Nicolas Juillerat's Sudoku explainer 1.2.1 (top 5)",
"12.3.....4.....3....3.5......42..5......8...9.6...5.7...15..2......9..6......7..8",
"..3..6.8....1..2......7...4..9..8.6..3..4...1.7.2.....3....5.....5...6..98.....5."
diff --git a/app/views/devise/shared/_links.erb b/app/views/devise/shared/_links.erb
dissimilarity index 99%
index 414904b..0b0b21d 100644
--- a/app/views/devise/shared/_links.erb
+++ b/app/views/devise/shared/_links.erb
@@ -1,19 +1,15 @@
-<%- if controller_name != 'sessions' %>
- <%= link_to "Sign in", new_session_path(resource_name) %><br />
-<% end -%>
-
@perplexes
perplexes / buildpacks.md
Last active November 25, 2021 02:29
Heroku custom compiled library .bundle/config

Buildpacks

Heroku uses buildpacks to compile your application into a slug that is used across dynos for scaling horizontally quickly. A slug is a tar.gz archive of your app’s repository with certain pre-deploy features baked into the filesystem. Since everything to run your application is included in the archive, scaling becomes a simple matter of transferring it to a dyno, unpacking, and running the appropriate process. This is how Heroku achieves scaling-by-moving-a-slider.

For example, the Ruby buildpack will:

  • install ruby locally
  • install the jvm/jruby (if you’re using it)
  • install/run bundler and install your gems to Rails.root/vendor
  • create your database.yml (which ends up reading from your app’s environment variables)