Skip to content

Instantly share code, notes, and snippets.

View thehenster's full-sized avatar

Henry thehenster

  • https://char.gy
  • London
View GitHub Profile
@thehenster
thehenster / gist:9409371
Created March 7, 2014 10:48
Me git tips
# Stash only specific files
# Stage the files you want to keep and run..
git stash --keep-index
@thehenster
thehenster / gist:9555660
Created March 14, 2014 20:03
An /etc/fstab to stop mounting a partition automatically on osx
UUID=1229D978-XXXX-XXXX-827E-0DE28E523720 none hfs rw,noauto
@thehenster
thehenster / gist:183c3efefa6343895452
Created May 19, 2014 16:18
Delegation of class methods through an association..
class Event < ActiveRecord::Base
has_many :artists
end
class Artist < ActiveRecord::Base
def self.make_me_an_artist
create! do |artist|
#!/usr/bin/env ruby
# Give me two arguments.
# 1) the path of the pwsafe xml file to import
# 2) the path of the csv to export
# format of lastpass data
# url,username,password,extra,name,grouping,fav
require 'nokogiri'
source 'https://rubygems.org'
gem 'pg'
gem 'activerecord'
# In rails 3
Post.select(:id, :created_at).count #=> SELECT COUNT(*) FROM posts
# In rails 4
Post.select(:id, :created_at).count #=> SELECT COUNT(id, created_at) FROM posts ... bang
Post.select(:id, :created_at).count(:all) #=> SELECT COUNT(*) FROM posts
@thehenster
thehenster / capybara-cheatsheet.rb
Created March 6, 2015 11:14
Capybara Cheatsheet
# A Capybara Cheatsheet
@thehenster
thehenster / simple_rdoc.rb
Last active April 2, 2020 13:29
A very simple custom RDoc generator
# RDoc can use a custom generator but it isn't that well documentated. Here is a
# sample custom generator to get you going.
#
# Ruby comes with an `rdoc` executable but most of us generate our docs via Rake. To
# use your custom generator with Rake do something like the following in your Rakefile..
#
# require 'rdoc/task'
# require 'simple_rdoc'
#
# RDoc::Task.new('simple_doc') do |i|
@thehenster
thehenster / recipe_form.rb
Last active November 16, 2015 16:18
Pattern for Form Objects in Rails
class RecipeForm
ATTRIBUTES = [:name, :cooking_time_minutes]
attr_reader :recipe
attr_accessor *ATTRIBUTES
def initialize(recipe)
@recipe = recipe
end
@thehenster
thehenster / scripttag.html
Last active November 17, 2015 09:10
script tag in gist
<script>alert('hello');</script>