Skip to content

Instantly share code, notes, and snippets.

View scottatron's full-sized avatar

Scott Arthur scottatron

View GitHub Profile
@lwille
lwille / application_helper.rb
Created March 4, 2010 22:46
Single DB query tree generation with awesome_nested_set
module ApplicationHelper
# Mixin for tree generation based on a nested set, just place this in your application_helper.rb
module TreeMethods
attr_accessor :child_nodes
attr_accessor :parent_node
def after_initialize
@child_nodes = []
@parent_node = nil
end
def recursive_tree nodes=nil, level=0
@reu
reu / edit.html.erb
Created May 12, 2010 19:06
Custom attributes using serialization
<% form_for(@user) do |f| %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<% f.fields_for :custom, @user.custom do |custom_form| %>
<% custom_form.object.marshal_dump.each_key do |custom_field| %>
<p>
<%= custom_form.label custom_field %><br />
@markbates
markbates / watchr script
Created July 20, 2010 15:25
A Watchr script for rails, rspec, and cucumber
ENV["WATCHR"] = "1"
system 'clear'
def growl(message)
growlnotify = `which growlnotify`.chomp
title = "Watchr Test Results"
puts message
image = message.match(/\s0\s(errors|failures)/) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
system %(#{growlnotify} #{options} &)
@ddgromit
ddgromit / fisheryates.coffee
Created March 8, 2011 01:56
CoffeeScript Implementation of the Fisher-Yates array sorting algorithm
# Adapted from the javascript implementation at http://sedition.com/perl/javascript-fy.html
# Randomizes the order of elements in the passed in array in place.
fisherYates = (arr) ->
i = arr.length;
if i == 0 then return false
while --i
j = Math.floor(Math.random() * (i+1))
tempi = arr[i]
@squarism
squarism / watchr_rspec.rb
Created March 25, 2011 16:20
Watchr file for use with spork, rails, rspec2 and growl
# sometimes watchr freaks out when you view this file in textmate (hits timestamp?)
# ie: it prints "Watching..." over and over
# just hit Ctrl-\ to run all tests and it calms down
ENV["WATCHR"] = "1"
puts "Watching..."
def growl(result)
result_lines = result.split("\n")
message = result_lines[result_lines.size - 1]
@jeffkreeftmeijer
jeffkreeftmeijer / OpenCV.h
Created March 27, 2011 17:59
OpenCV MacRuby
#import <Cocoa/Cocoa.h>
#import "opencv2/imgproc/imgproc_c.h"
#import "opencv2/highgui/highgui_c.h"
#import "opencv2/objdetect/objdetect.hpp"
@interface OpenCV : NSObject {
int scale;
CvCapture* camera;
@rtomayko
rtomayko / optparse-template.rb
Last active June 3, 2023 03:16
Ruby optparse template
#!/usr/bin/env ruby
#/ Usage: <progname> [options]...
#/ How does this script make my life easier?
# ** Tip: use #/ lines to define the --help usage message.
$stderr.sync = true
require 'optparse'
# default options
flag = false
option = "default value"
@henrik
henrik / luhn_checksum.rb
Created November 30, 2011 17:02
Luhn checksum/check digit generation in Ruby.
class Luhn
def self.checksum(number)
digits = number.to_s.reverse.scan(/\d/).map { |x| x.to_i }
digits = digits.each_with_index.map { |d, i|
d *= 2 if i.even?
d > 9 ? d - 9 : d
}
sum = digits.inject(0) { |m, x| m + x }
mod = 10 - sum % 10
mod==10 ? 0 : mod
@futuremill-ltd
futuremill-ltd / gist:2318876
Created April 6, 2012 11:00
Building Ruby 1.9.3 package for Debian Squeeze
# From a fresh install of squeeze
apt-get install ruby rubygems # Need ruby to use fpm
gem1.8 install fpm --no-ri --no-rdoc
apt-get install build-essential openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev ncurses-dev libyaml-dev
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar -zxvf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125
rm -rf /tmp/ruby193
@kasparsd
kasparsd / wordpress-plugin-svn-to-git.md
Last active July 6, 2024 15:54
Using Git with Subversion Mirroring for WordPress Plugin Development