Skip to content

Instantly share code, notes, and snippets.

View cato's full-sized avatar
😐

Cato Johnston cato

😐
View GitHub Profile
@cato
cato / nz-break.js
Created November 2, 2011 06:39
Insert a non-breaking space between the words "New Zealand", so that they are never orphaned
var nz = $('p,h1,h2,h3,h4,h5,h6').filter(":contains('New Zealand')");
nz.each(function(){
$(this).html( $(this).html().replace("New Zealand", "New Zealand"));
});
@cato
cato / gist:1098909
Created July 22, 2011 04:43
JS: Bulletproof Logging
var logger = function(e){
if(console){
console.log(e);
} else{
alert(e);
}
}
class Tree
attr_accessor :children, :node_name
def initialize(node_name, strucutre={})
@node_name = node_name
@children = []
strucutre.each_pair do |k,v|
@children.push(Tree.new(k,v))
end
end
#!/usr/bin/env ruby
q = ARGV[0]
File.open('search.txt', 'r') do |infile|
i = 0
while(line = infile.gets)
i = i + 1
puts "#{i}: #{line}" if line.index(q) != nil
end
#!/usr/bin/env ruby
a = (1..16).to_a
# without each_slice
a.each do |i|
puts i.to_s
if i % 4 == 0 then
puts ','
end
#!/usr/bin/env ruby
a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
a.each do |i|
puts i.to_s
if i % 4 == 0 then
puts ','
end
end
h.each_pair do |k,v|
puts k
puts v
end
a = ['abc', 'def', 'ghi']
h = {}
a.each {|i| h[a.index(i).to_s => i}
"Hello Ruby".index("Ruby")
puts "Hello, world"