This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 = '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Location | |
attr_reader :zip, :city, :state | |
def initialize(values={}) | |
@zip = values[:zip] | |
@city = values[:city] | |
@state = values[:state] | |
end | |
def self.parse(text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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’t quite work for me, but it was close (left a bunch of random MySQL “set” statements everywhere and used MySQL’s default multiple insert syntax). After some tweaking I got it to create the file without errors. Here’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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
OlderNewer