Archive

Archive for January, 2009

Storm by Tim Minchin

January 31st, 2009 dkam No comments

Categories: Uncategorized Tags:

1981 Internet story

January 30th, 2009 dkam No comments

Categories: Uncategorized Tags:

OCR and Neural Nets in JavaScript

January 26th, 2009 dkam No comments

Javascript is becoming more and more useful as CPUs get faster and Javascript engines get better – John Resig – OCR and Neural Nets in JavaScript. Solving captcha with neural networks in Javascript. It sounds like a pretty small  neural net, but that’s pretty amazing.

Categories: Uncategorized Tags: , ,

Automating host provisioning

January 26th, 2009 dkam No comments

When testing new stuff for Booko, I sometimes create a new slicehost and build myself a test box. In the past I’ve done this manually, which really isn’t very difficult, but it turns out that Slicehost have an API to allow you to automate this stuff.  With the API you can create, destroy, rebuild and reboot your VPS which is pretty cool.  It also lets you manipulate all your DNS settings. Check out the API for complete details. 

Here’s a script I put together to build a new dev host for me and set it up so it’s ready to use.  It performs the following steps:

  1. Check the Domain name I’ve selected for the host is managed by Slicehost.
  2. Create a new 256MB VPS with Ubuntu 8.04 installed.
  3. Create the domain names for the host (including on the internal interface if required)
  4. Wait for host to build and for Networking and SSH to startup.
  5. Add my SSH key to the root user’s account for passwordless login.
  6. Update and upgrade the host.
  7. Install Puppet  

I plan on having a puppet server setup soon which will take over the rest of the setup, so I’ve installed that. I’ll probably use the Net::SSH stuff to get the host added to puppet (signing certificates and such.)
[sourcecode language='ruby']
#!/usr/bin/env ruby

require ‘rubygems’
require ‘activeresource’
require ‘net/ssh’
require ‘net/scp’

API_KEY=”your_key_goes_here”
SITE=”https://#{API_KEY}@api.slicehost.com/”
DEFAULT_TTL = 300

host_name=”hostname”
int_host_name=”hostname-int”
domain_name=”mydomain.com.au”

fqdn = host_name + “.” + domain_name
origin = domain_name + “.”

##
# Required definitions to access the Slicehost stuff
##
class Slice < ActiveResource::Base
self.site = SITE
end

# Address class is required for Slice class
class Address < String; end

class Zone < ActiveResource::Base
self.site = SITE
end

class Record < ActiveResource::Base
self.site = SITE
end

##
# Create or update a DNS record
##
def create_host_record(zone_id, host_name, ip_address, ttl = DEFAULT_TTL)
host_record = Record.find(:first, :params => { :name => host_name, :zone_id => zone_id } )
unless host_record.nil?
host_record.data = ip_address
host_record.record_type = “A”
else
host_record = Record.new(:ttl => ttl, :record_type => ‘A’, :zone_id => zone_id, :name => host_name, :data => ip_address)
end
host_record.save
end

puts “Getting Zone data for \”#{domain_name}\”.”
dom = Zone.find(:first, :params => { :o rigin => origin } )

raise “Domain \”#{domain_name}\” not found. Won’t be able to create host record.” if dom.nil?

puts “Domain exists. Creating slice.”

slice = Slice.new(:image_id => 10, :flavor_id => 1, :name => host_name)
slice.save

puts “Slice created. Creating DNS records while it builds.”

create_host_record(dom.id, host_name, slice.addresses[0])
create_host_record(dom.id, int_host_name, slice.addresses[1]) unless int_host_name.nil?

puts “DNS created. Waiting for host to build and become active.”

while slice.progress != 100 && slice.status != “active”
puts “Host is #{slice.progress}% complete – host status: #{slice.status}”
sleep 10
slice.reload
end

puts “Host built. Waiting for host to startup.”

begin
Net::SSH.start(slice.ip_address, ‘root’, {:auth_methods => ["password"], :password => slice.root_password}) do |ssh|
puts “Connected to new host. Bootstrapping.”

puts “Creating .ssh directory and uploading public key.”
ssh.exec “/bin/mkdir -p /root/.ssh/”
ssh.scp.upload!(“/Users/dkam/.ssh/id_dsa_omena.pub”, “/root/.ssh/authorized_keys”)
puts “Done!”

puts “Updating apt and upgrading system.”
ssh.exec!(“/usr/bin/aptitude update”)
ssh.exec!(“/usr/bin/aptitude dist-upgrade -y”)
puts “Host has been upgraded and updated.”

  puts “Installing puppet.”
ssh.exec!(“/usr/bin/aptitude install puppet -y”)
puts “Puppet Installed.”
end
rescue Errno::ENETUNREACH
puts “Host network not up. Waiting 10 seconds, then retrying”
sleep 10
retry
rescue Errno::ECONNREFUSED
puts “SSH not ready. Waiting 10 seconds, then retrying”
sleep 10
retry
end

puts “Done! Enjoy your new host #{fqdn}. You can now ssh root@#{slice.ip_address}”

[/sourcecode]

Categories: Booko, Ruby Tags:

LiPo

January 17th, 2009 dkam No comments

Testing my new LiPo battery.  Watch those tyres balloon!  The battery can do 96Amp continuous with 160Amp bursts. It’s a 5350 mAH battery  but at 7.4V, it won’t push those sorts of currents for long.

Flying people

January 5th, 2009 dkam No comments

Awesome!


wingsuit base jumping from Ali on Vimeo.

Categories: Uncategorized Tags: ,