Skip to content

Instantly share code, notes, and snippets.

View clowder's full-sized avatar

Chris Lowder clowder

  • London
View GitHub Profile
@clowder
clowder / spaces_controller.rb
Created July 16, 2015 11:03
Admin preview user content
class Admin::SpacesController < AdminController
def preview
space = Space.find(params[:id])
prepend_view_path 'app/views/spaces' # Ensures our `:template` is found.
lookup_context.prefixes = ['spaces', 'application'] # Ensures that our templates partials are pulled from the right places.
render template: 'show', layout: 'application', locals: { space: space }
end
end
# implementation at http://gist.github.com/3350
require 'spec_helper'
describe HoptoadErrors do
describe '.find :all' do
before(:each) do
@errors = HoptoadErrors.find :all
end
commit 0f2b9f95b905cbebb9573e36f9ff0ef78a0b8024
Author: Chris Lowder <clowder@gmail.com>
Date: Mon Apr 4 17:46:17 2011 +0100
A failing example
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..08a8ac9
--- /dev/null
@clowder
clowder / gist:1451644
Created December 9, 2011 14:04 — forked from mudge/gist:263139
Polymorphic has_many :through in Rails 2.3
# A polymorphic has_many :through relationship in Rails 2.3
# based on Josh Susser's "The other side of polymorphic :through associations"
# http://blog.hasmanythrough.com/2006/4/3/polymorphic-through
class Authorship < ActiveRecord::Base
belongs_to :author
belongs_to :publication, :polymorphic => true
end
class Author < ActiveRecord::Base
has_many :authorships
@clowder
clowder / crawler.yml
Created December 14, 2011 09:59
Settings for Nature/Crawler
:redis: redis://172.25.13.95:6379
@clowder
clowder / gist:1528966
Created December 28, 2011 18:14
Creating a new user and table in Postgres
createuser --password USERNAME
createdb --owner=USERNAME DATABASE_NAME
Gem::Specification.new do |gem|
gem.name = ''
gem.version = ''
gem.date = Date.today.to_s
# gem.add_dependency 'hpricot', '~> 0.8.2'
# gem.add_development_dependency 'rspec', '~> 1.2.9'
gem.summary = ""
gem.description = ""
@clowder
clowder / creating-custom-exporters-for-foreman.md
Created January 18, 2012 17:28
Creating custom exporters for Foreman

Creating custom exporters for Foreman

Creating the exporter

To start with you should subclass [Foreman::Export::Base] and your subclass should exist within the [Foreman::Export] namespace.

class Foreman::Export::MyRunitExporter < Foreman::Export::Base
end
@clowder
clowder / rescue_demo.c
Created March 18, 2012 23:23
How to rescue your Rubies in C!
static void i_fail(VALUE self)
{
rb_raise(rb_eRuntimeError, "Oh knowz!");
}
static void rescue(VALUE self, VALUE exception)
{
/* This function _is not_ in <ruby.h>
* http://clalance.blogspot.co.uk/2011/01/writing-ruby-extensions-in-c-part-5.html
*/
@clowder
clowder / hack.sh
Created May 20, 2012 17:26 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#