Skip to content

Instantly share code, notes, and snippets.

🔨
Woodworking

Rob Cameron cannikin

🔨
Woodworking
Block or report user

Report or block cannikin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:131
// validate all the fields in the form
validateForm:function() {
this.resetForm();
this.fields.each(function(field) {
this.validateField(field);
}.bind(this));
return this.hasErrors() ? false : true;
},
// validate a specific field
View birthday_paradox.rb
#!/usr/bin/ruby
# This app proves the Birthday Paradox: http://en.wikipedia.org/wiki/Birthday_problem
#
# 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]
end
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="http://mysql.org">MySQL</a> database to a <a href="http://sqlite.org">SQLite3</a> database the other day. I did some searching and found a <a href="http://www.sqlite.org/cvstrac/wiki?p=ConverterTools">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 %}
#!/bin/sh
View poller.rb
class Poller
def self.call(env)
if env["PATH_INFO"] =~ /^\/poller/
[200, {"Content-Type" => "text/html"}, [Time.now.to_f]]
else
[404, {"Content-Type" => "text/html"}, ["Not Found"]]
end
end
end
View something.js
<script type="text/javascript">
var since = '<%= @since.to_f %>';
var updater = setInterval( function() {
new Ajax.Updater('notes','/poller', {
method:'get',
parameters:"since="+since,
insertion:'top',
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]
end
end
# Usage
k2 = Mountain.new('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
You can’t perform that action at this time.