Skip to content

Instantly share code, notes, and snippets.


Rob Cameron cannikin

View GitHub Profile
View gist:131
// validate all the fields in the form
validateForm:function() {
this.fields.each(function(field) {
return this.hasErrors() ? false : true;
// validate a specific field
View birthday_paradox.rb
# This app proves the Birthday Paradox:
# The Birthday Paradox is counter-intuitive to common sense - select 23 people at random and
# there is a greater than 50% chance that at least two people in the group will have the same
# birthday. With 50 random people the probability goes up to 97%. These solutions ignore leap-years.
# People Probability
# ---------------------
# 10 11.7%
View random_code_generator.rb
# Generates a random string of letters and numbers
letters = ('A'..'Z').to_a
print 'Length of random string? '; length_of_string = gets.chomp.to_i
print 'How many to make? '; number_to_make = gets.chomp.to_i
numbers = []
while numbers.length < number_to_make do
output = ''
View location.rb
class Location
attr_reader :zip, :city, :state
def initialize(values={})
@zip = values[:zip]
@city = values[:city]
@state = values[:state]
def self.parse(text)
View gist:40119
layout: post
title: Convert a MySQL database to a SQLite3 database
<span class="intro">I wanted to convert a</span> <a href="">MySQL</a> database to a <a href="">SQLite3</a> database the other day. I did some searching and found a <a href="">good script on the SQLite3 site</a> . It didn&#8217;t quite work for me, but it was close (left a bunch of random MySQL &#8220;set&#8221; statements everywhere and used MySQL&#8217;s default multiple insert syntax). After some tweaking I got it to create the file without errors. Here&#8217;s my version for anyone that needs to do the same thing (requires <em>mysqldump</em> and <em>perl</em> be installed on your system):
{% highlight bash %}
View poller.rb
class Poller
if env["PATH_INFO"] =~ /^\/poller/
[200, {"Content-Type" => "text/html"}, []]
[404, {"Content-Type" => "text/html"}, ["Not Found"]]
View something.js
<script type="text/javascript">
var since = '<%= @since.to_f %>';
var updater = setInterval( function() {
new Ajax.Updater('notes','/poller', {
onSuccess:function(r) { since = r.responseText; }
}, 4000);
View ruby-rob_cameron.rb
#!/usr/bin/env ruby
require 'digest/md5'
START = 0.to_s(16).rjust(32,'0') # pass a 32 character hash as an argument to start at something other than 0000000000000000000000000000000
before = ''
after = ARGV[0] || START
while before != after
View gist:160810
class Mountain
attr_reader :name, :latitude, :longitude
attr_accessor :country
def initialize(name, latitude, longitude)
@name, @latitude, @longitude = [name, latitude, longitude]
# Usage
k2 ='K2', 35.879314, 76.514283)
View smb.conf
-- smb.conf
# Sample configuration file for the Samba suite for Debian GNU/Linux.
# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options most of which
# are not shown in this example