Skip to content

Instantly share code, notes, and snippets.

View cannikin's full-sized avatar
🔨
Woodworking

Rob Cameron cannikin

🔨
Woodworking
View GitHub Profile
// 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
@cannikin
cannikin / gist:9242443
Created February 27, 2014 01:26
HAML filter example
%h1 Heading 2
:javascript
console.info
%h2 Heading 2
- cache [@user, @user.posts] do
= @user.inspect
- @user.posts.each do |post|
- cache post do
= post.inspect
@cannikin
cannikin / gist:08ab4d8002659d4b3da4
Last active August 29, 2015 14:15
Raspberry Pi 2 overclock benchmark
# Procedure
#
# From a completely fresh restart, ssh'd into the Pi from my mac and then ran the
# sysbench command listed at the top of each section. Copied and pasted the
# output, restarted, and ran the next.
#
# 1000MHz overclock settings:
#
# arm_freq=1000
# sdram_freq=500
positron-2:cal_counter_grape rob$ rake jasmine:ci
[2015-04-07 11:33:05] INFO WEBrick 1.3.1
[2015-04-07 11:33:05] INFO ruby 2.2.1 (2015-02-26) [x86_64-darwin14]
[2015-04-07 11:33:05] INFO WEBrick::HTTPServer#start: pid=21195 port=59830
Waiting for jasmine server on 59830...
jasmine server started.
F
Failures:
Entries sorts entries by ate_at, newest first
#!/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%
# 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 = ''
class Location
attr_reader :zip, :city, :state
def initialize(values={})
@zip = values[:zip]
@city = values[:city]
@state = values[:state]
end
def self.parse(text)
---
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
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