Skip to content

Instantly share code, notes, and snippets.

View joshnesbitt's full-sized avatar

Josh Nesbitt joshnesbitt

View GitHub Profile

Better Git Hooks

Intro

Git hooks are not as widely used as they could be, and I believe is because people new to Git don't want to be messing around with Bash scripts or haven't yet discovered how to use them.

I'd like to propose a new tool for creating and managing Git hooks, and versioning them with the project they reside in. This can benefit everyone on a given project as they can implement the same workflow which Git hooks allow. If a hook is related only to a single developer, simply do not check it in.

Suggested Usage

@joshnesbitt
joshnesbitt / _usage.md
Created May 16, 2014 08:38
Simple Redis pub/sub

Usage

  • Install the redis gem
  • Start subscribe.rb with ruby subscribe.rb, this will not exit
  • Run ruby publish.rb and you should see the message being received in the output of subscribe.rb
function code_highlight(){
style=${1:-zmrok}
pbpaste | highlight --syntax=rb --style=$style -O rtf | pbcopy
}
module BannedWordFilter
class Filter
class << self
BANNED_WORDS = %w(
fuck
shit
banned
)
class Company
TooManyManagingDirectorsError = Class.new(Exception)
class Department
attr_reader :company,
:name,
:employees
def initialize(company, name, &block)
@company = company
@joshnesbitt
joshnesbitt / metaclass.rb
Last active August 29, 2015 14:26
How well do you know Ruby? Can you explain what's going on here? What is MyClass.metaclass returning?
class MyClass
def self.metaclass
class << self; self; end
end
end
puts MyClass.metaclass.inspect
class MyClass
def one_method
puts "Hey!"
end
end
class MyClass
price_list = "orange = 10p apple = 20p bread = £1.10 tomato = 25p cereal = £2.34"
list = <<-LIST
list
orange
apple
apple
orange
tomato
cereal
bread
@joshnesbitt
joshnesbitt / template.rb
Created August 20, 2015 14:51
Example of a simple templating language written in Ruby.
class VariableLang
def initialize(path)
@path = path
@content = File.read(path)
end
def render(locals = {})
locals.inject(@content.dup) do |buffer, vars|
key = vars.first
# 1) Point *.example.com in your DNS setup to your server.
#
# 2) Setup an Apache vhost to catch the star pointer:
#
# <VirtualHost *:80>
# ServerName *.example.com
# </VirtualHost>
#
# 3) Set the current account from the subdomain
class ApplicationController < ActionController::Base