Skip to content

Instantly share code, notes, and snippets.

@tonycoco
tonycoco / controller_spec.rb
Last active May 25, 2023 06:04
The Greatest Hits of Rspec Testing: Volume 1
require "spec_helper"
describe ExampleController do
context "GET #index" do
let(:resources) { FactoryGirl.create_list(:resource) }
before do
get :index
end
@martincr
martincr / gist:8463613
Created January 16, 2014 21:17
PostgreSQL Cheat Sheet
PostgreSQL Cheat Sheet
======================
CREATE DATABASE
CREATE DATABASE dbName;
CREATE TABLE (with auto numbering integer id)
CREATE TABLE tableName (
id serial PRIMARY KEY,
name varchar(50) UNIQUE NOT NULL,
@qrush
qrush / mr_freeze.rb
Last active December 30, 2015 15:49
REVENGE IS A DISH BEST SERVED COLD
class String
def ❄︎
freeze
end
end
puts "foo".❄︎.frozen?
# => true
@txus
txus / transients.rb
Created September 19, 2013 10:54
Transients in Ruby. Transients are a way to mutate an immutable object for a limited scope of changes and then make it immutable again.
class Object
def transient(&block)
dup.tap(&block).freeze
end
end
str = "hey".freeze
new_str = str.transient do |mutable_str|
mutable_str.upcase!
@mindjiver
mindjiver / git from scratch
Last active December 19, 2015 07:59
Git from scratch. How to create a git repository and a first commit by only using plumbing commands.
$ mkdir git-from-scratch
$ cd git-from-scratch
$ mkdir -p .git/refs/{heads,tags}
$ mkdir -p .git/objects/
$ echo "ref: refs/heads/master" >> .git/HEAD
$ git status
# On branch master
#
# Initial commit
#
@jedisct1
jedisct1 / bench results
Last active December 19, 2015 02:09
msgpack benchmark results
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.4.0]
user system total real
YAML 29.190000 1.150000 30.340000 ( 31.303681)
JSON 1.780000 0.050000 1.830000 ( 2.357544)
Marshal 1.300000 0.020000 1.320000 ( 1.781964)
MessagePack 0.520000 0.160000 0.680000 ( 0.692523)
jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on Java HotSpot(TM) 64-Bit Server VM 1.7.0_17-b02 +indy [darwin-x86_64]
####################################
# BASIC REQUIREMENTS
# http://graphite.wikidot.com/installation
# http://geek.michaelgrace.org/2011/09/how-to-install-graphite-on-ubuntu/
# Last tested & updated 10/13/2011
####################################
cd
sudo apt-get update
sudo apt-get upgrade
@ideasasylum
ideasasylum / pre-commit
Created March 7, 2013 21:49
A pre-commit Git hook for preventing commits containing focus: true, debugger, binding.pry etc Based on a blog post I wrote http://jamie.ideasasylum.com/2013/02/preventing-the-stupid-mistakes-like-committing-focustrue/ (which in turn was based on someone else's script). This version allows you to easily setup new rules at the head of the script
#!/usr/bin/env ruby
spec_hits = []
checks = {
'_spec\.rb$' => ['focus:[:space:]*true'],
'\.rb$' => ['binding\.pry', 'debugger']
}
# Find the names of all the filenames that have been (A)dded (C)opied or (M)odified
filenames = `git diff --cached --name-only --diff-filter=ACM`.split("\n")
Capybara.add_selector :record do
xpath { |record| XPath.css("#" + ActionController::RecordIdentifier.dom_id(record)) }
match { |record| record.is_a?(ActiveRecord::Base) }
end
@alexbevi
alexbevi / pre-commit.sh
Created August 23, 2012 12:05
Git pre-commit hook that checks ruby source files for Pry breakpoints
# Git pre-commit hook to check all staged Ruby (*.rb/haml/coffee) files
# for Pry binding references
#
# Installation
#
# ln -s /path/to/pre-commit.sh /path/to/project/.git/hooks/pre-commit
#
# Based on
#
# http://codeinthehole.com/writing/tips-for-using-a-git-pre-commit-hook/