Skip to content

Instantly share code, notes, and snippets.

@txus
txus / delegate_matcher.rb
Created February 2, 2011 09:19
RSpec matcher for delegations
# RSpec matcher to spec delegations.
#
# Usage:
#
# describe Post do
# it { should delegate(:name).to(:author).with_prefix } # post.author_name
# it { should delegate(:month).to(:created_at) }
# it { should delegate(:year).to(:created_at) }
# end
@rbxbx
rbxbx / incrudable.rb
Created March 3, 2011 14:35
CRUD with decent_exposure
# pulled out of a project authored by tpope && rbxbx
# not generic enough for general use, but a decent example of
# an application specific restful crud abstraction
module Incrudable
extend ActiveSupport::Concern
included do
expose(controller_name) { controller_name.classify.constantize.scoped }
expose(controller_name.singularize)
@nruth
nruth / gist:1049494
Created June 27, 2011 18:50
testing devise password recovery email with email_spec and capybara / rspec request spec
require 'spec_helper'
describe "member password recovery" do
# As a member who forgot my password
# I want to recover my site access easily
#
attr_accessor :current_email_address
specify "email recovery of a new password" do
member = make_activated_member
@jc00ke
jc00ke / nginx.conf
Created August 23, 2011 21:52 — forked from pogodan/tunnel.thor
thor/pow reverse SSH tunnel
server {
listen [YOUR IP]:80;
server_name *.dev.jc00ke.com;
location / {
if ($host ~* "(.*)\.dev\.jc00ke\.com" ) {
set $tunnel_app $1.lvh.me;
}
proxy_set_header X-Real-IP $remote_addr;
@chrisroos
chrisroos / gpg-import-and-export-instructions.md
Created September 9, 2011 10:49
Instructions for exporting/importing (backup/restore) GPG keys

Every so often I have to restore my gpg keys and I'm never sure how best to do it. So, I've spent some time playing around with the various ways to export/import (backup/restore) keys.

Method 1

Backup the public and secret keyrings and trust database

cp ~/.gnupg/pubring.gpg /path/to/backups/
cp ~/.gnupg/secring.gpg /path/to/backups/
cp ~/.gnupg/trustdb.gpg /path/to/backups/

or, instead of backing up trustdb...

@mxriverlynn
mxriverlynn / 1-has_image.rb
Created September 27, 2011 21:30
capybara has_image? matcher
module Capybara
class Session
def has_image?(src)
has_xpath?("//img[contains(@src,\"/images/#{src}\")]")
end
end
end
@jamiehodge
jamiehodge / gist:1327195
Created October 31, 2011 09:38
Warden and Sinatra example
require 'sinatra/base'
require 'rack/flash'
require 'warden'
require 'slim'
require 'sequel'
require 'sqlite3'
DB = Sequel.sqlite
DB.create_table :users do
primary_key :id
@gmarik
gmarik / !README.md
Created November 21, 2011 15:36
Disable Gem deprecation spam

How to disable Gem deprecation warnings

Just copy content to corresponding files

@jc00ke
jc00ke / dnsd.rb
Created December 2, 2011 23:49 — forked from peterc/dnsd.rb
Simple, scrappy UDP DNS server in Ruby (with protocol annotations)
# Simple, scrappy UDP DNS server in Ruby (with protocol annotations)
# By Peter Cooper
#
# MIT license
#
# * Not advised to use in your production environment! ;-)
# * Requires Ruby 1.9
# * Supports A and CNAME records
# * See http://www.ietf.org/rfc/rfc1035.txt for protocol guidance
# * All records get the same TTL
@jc00ke
jc00ke / maglev-peek-inside-proc.txt
Created December 6, 2011 21:04 — forked from timfel/gist:1439913
Want to look at the code a block would run when called?
~ maglev ✔ maglev-irb -f
irb(main):001:0> b = proc { p 1 }
=> #<Proc>
irb(main):002:0> b.instance_variable_get("@_st_block")
=> #<ExecBlock:0x561a6201
irb(main):003:0> block = b.instance_variable_get("@_st_block")
=> #<ExecBlock:0x561a6201
irb(main):004:0> block.class
=> ExecBlock
irb(main):005:0> block.class.primitive '_sourceString', '_sourceString'