Skip to content

Instantly share code, notes, and snippets.

View iansheridan's full-sized avatar

Ian Sheridan iansheridan

View GitHub Profile
@iansheridan
iansheridan / watch.rb
Created December 16, 2011 16:30
Watcher script for Ruby
#!/usr/bin/ruby -w
# Ruby implementation of the GNU watch command line utility for Mac OS X.
# Written by: Ian Sheridan. December 2011.
# Email: ian.sheridan[@]gmail.com
if ARGV.length == 0
puts 'Syntax: watch.rb <unix commands>'
puts 'If command contains parameters, make sure to enclose them with single quotes'
exit
@iansheridan
iansheridan / example.js
Created December 9, 2011 19:45
sample of selecting 5 random items from an array in javascript without any duplications
a = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","aa","bb","cc","dd"];
b = [];
while(b.length<5){
t = Math.round(Math.random() * (a.length-1));
console.log(t,$.inArray(a[t],b));
if($.inArray(a[t],b) == -1){
b.push(a[t]);
}
}
console.log(b[0]);
@iansheridan
iansheridan / .tmux.config
Created September 29, 2011 22:26
a sample config file for Tmux
# Last modified: 2011 Sep 14
# Author: Florian CROUZAT <contact@floriancrouzat.net>
# Feel free to do whatever you want with this file.
# Just make sure to credit what deserve credits.
# Binds {{{
# Prefix
unbind C-b
set-option -g prefix C-a
bind a send-prefix
@iansheridan
iansheridan / api.feature
Created July 20, 2011 11:59 — forked from adamstrickland/api.feature
Cucumber Example for testing a RESTful API
Scenario: Get List of My Hitchhiking Items via API
Given the existing things:
|name|
|The Guide (duh)|
|A towel|
|Sub-Etha Sens-O-Matic|
|Pan Galactic Gargle Blaster|
|Kill-o-Zap blaster pistol|
And the existing accounts:
|email|name|password|
<%= javascript_include_tag 'jquery' %>
<script>
jQuery.noconflict();
</script>
<%= javascript_include_tag :defaults %>
@iansheridan
iansheridan / article-result.html
Created May 16, 2011 20:28
Example of a way to move a DIV to anywhere in the DOM with jQuery
<div id="article">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla faucibus semper diam quis suscipit. Sed at eros et est scelerisque hendrerit. Nam sagittis tortor vel orci convallis vel tempor nisl suscipit. Fusce at mauris risus, a adipiscing mauris. Nunc nunc erat, luctus id suscipit sed, lacinia sed ligula. In imperdiet, metus nec mattis molestie, odio dui sollicitudin augue, at blandit velit enim vitae nisl. Maecenas id enim eu nunc luctus congue. Sed tempus tellus quis quam ultrices et aliquet arcu porta. Vivamus pretium ipsum sit amet nisl pulvinar consequat. Fusce elementum, lectus in lacinia ultrices, ante tellus euismod urna, gravida cursus augue est id lacus.
</p>
<p>
Quisque vestibulum pellentesque eros, a pharetra nibh elementum vestibulum. Mauris fringilla tortor sed dui egestas dictum. Sed ac velit eu sapien dapibus mollis. Vestibulum volutpat nunc at enim ultrices egestas congue purus gravida. In sed elit sed erat auctor sagittis id nec tellus. Proin iaculis lobortis lac
@iansheridan
iansheridan / git-cheat-sheet.md
Created March 15, 2011 14:25
A cheat sheet for GIT

Setup

git clone <repo>

clone the repository specified by ; this is similar to "checkout" in some other version control systems such as Subversion and CVS

Add colors to your ~/.gitconfig file:

@iansheridan
iansheridan / role.rb
Created November 20, 2010 22:53
a user class with dynamic 'has role' methods
class Role
include DataMapper::Resource
has n, :users, :through => Resource
property :id, Serial
property :name, String
property :short_name, String
property :description, Text
property :created_at, DateTime
property :updated_at, DateTime
default_scope(:default).update(:order => [:id]) # set default order
class Keygroup
include DataMapper::Resource
has n, :keywords, :through => Resource
has n, :categories, :through => Resource
property :id, Serial
property :name, String
property :description, Text
property :created_at, DateTime
# output and array sorted
def ian_sort(a)
c = false # change
a[0...-1].each_with_index { |v, i|
if v > a[i+1] then
a[i], a[i+1] = a[i+1], a[i]
c = true
end
}
ian_sort(a) if c