Skip to content

Instantly share code, notes, and snippets.

View alterisian's full-sized avatar

Ian Moss alterisian

View GitHub Profile
@alterisian
alterisian / gitolite_hn.bash
Created June 20, 2011 16:21 — forked from masnick/gitolite_hn.bash
Setting up gitolite (hn)
# Assuming Ubuntu 10.04 with git already installed.
#
# Make sure to secure your server: http://www.andrewault.net/2010/05/17/securing-an-ubuntu-server/
# These instructions are based on:
# http://sitaramc.github.com/gitolite/doc/1-INSTALL.html:
# First, get you id_rsa.pub onto the server as /tmp/YourName.pub
scp ~/ssh/id_rsa.pub [email protected]:/tmp/
@alterisian
alterisian / watch_controller.rb
Created September 14, 2011 12:24
So that we can watch a random railscast.
class WatchController < ApplicationController
def index
max_cast = 222 #todo-fetchMaxCastNumber
base_url = "http://railscasts.com/episodes/"
options = "?autoplay=true"
random_cast = Random.rand(max_cast)
redirect_to base_url + random_cast.to_s + options
end
@alterisian
alterisian / fixnum_ordinalize.rb
Created November 27, 2012 13:07
Adds ordinalize i.e. th,st,rd to a number for use in date string outputs
class Fixnum
def ordinalize
if (11..13).include?(self % 100)
"#{self}th"
else
case self % 10
when 1; "#{self}st"
when 2; "#{self}nd"
when 3; "#{self}rd"
else "#{self}th"
@alterisian
alterisian / rails_list_models.rb
Created June 27, 2013 13:04
List rails Models in an application
#otherwise this list isn't going to contain all models.
Rails.application.eager_load!
ActiveRecord::Base.descendants.each do |model|
puts model.name
end
@alterisian
alterisian / gist:5880195
Last active December 19, 2015 01:59
List all of the factories (idea being to hook it up with a comparison of all the models). Removes the sub factories.
FactoryGirl.factories.each{ |fac| puts fac.name.capitalize unless fac.name.to_s.include? "_" };nil
@alterisian
alterisian / factories_to_make.rb
Last active December 19, 2015 02:29
Test coverage: How many models have factories - not all will need them of course. I'm definately not implying that all of the models are going to need factories!
#for running in the console
require 'factory_girl'
models = []
factories = []
#otherwise this list isn't going to contain all models.
Rails.application.eager_load!
ActiveRecord::Base.descendants.each do |model|
@alterisian
alterisian / gitlg.bash
Created June 16, 2014 09:32
Give Git Log a nicer alias under git lg
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%C(bold blue)<%an>%Creset' --abbrev-commit"
@alterisian
alterisian / survival_panther.rb
Created March 19, 2015 20:57
survival_panther.rb
class Panther < RTanque::Bot::Brain
NAME = 'Survival Panther'
include RTanque::Bot::BrainHelper
def tick!
command.radar_heading = sensors.radar_heading + (RTanque::Heading::ONE_DEGREE * 30)
at_tick_interval(25) do
print_stats
end
@alterisian
alterisian / extract_li_data.js
Created December 19, 2017 16:12
artoo dom example
// Ok. What am I trying to do?
// ===========================
// Extract 3 data values from the li elements in a ul list,
// that are easily identified by classes on the target page.
// Not rocket science.
// Tool: Aartoo. Client Side Javascript. Looks evolved.
// Simple bookmarket run from the extraction page,
rails g model user name:string
rails g model favorite name:string design_id:integer user_id:integer
rails g model design name:string
class User
has_many: favourites
end
class Favorite