Skip to content

Instantly share code, notes, and snippets.

@mcoms
mcoms / Gemfile
Last active August 29, 2015 14:05
How many combinations of 2 grand piano keys are there?
source 'https://rubygems.org'
gem 'midilib', '~> 2.0.4'
@mcoms
mcoms / ubuntu-minimal-installer.ipxe
Last active August 29, 2015 13:56 — forked from robinsmidsrod/ubuntu-amd64-installer.ipxe
Install Ubuntu 12.04 minimal, i386, non-pae
#!ipxe
dhcp
echo Starting Ubuntu 12.04 i386, non-pae installer for ${hostname}
set base-url http://archive.ubuntu.com/ubuntu/dists/precise-updates/main/installer-i386/current/images/netboot/non-pae/ubuntu-installer/i386
kernel ${base-url}/linux
initrd ${base-url}/initrd.gz
boot ||
# If everything failed, give the user some options
echo Boot from ${base-url} failed
prompt --key 0x197e --timeout 2000 Press F12 to investigate || exit
@mcoms
mcoms / Dockerfile
Created February 24, 2014 22:34
Wemux demonstration container
# Wemux demonstration container
# =============================
# docker build -t wemux .
# docker run -t -i -d -p 2255:22 wemux
#
# ssh -p 2255 root@<host>
# root : screencast
# ssh -p 2255 user@<host>
# user : password
#
@mcoms
mcoms / daily_rates.rb
Created February 17, 2014 15:37
Ruby contractor daily rates (London)
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML.parse open('http://www.itjobswatch.co.uk/contracts/london/ruby.do')
# Inside London...
cells = doc.css('table.summary>tr').find {|tr| tr.css('>td').text =~ /Average daily rate/ }.css 'td'
daily_rates = { three_months: cells[1].text, last_year: cells[2].text, two_years_ago: cells[3].text }
# => {:three_months=>"£425", :last_year=>"£400", :two_years_ago=>"£375"}
@mcoms
mcoms / 7.rb
Last active January 1, 2016 23:59
Where's the best place to buy 7?
require 'nokogiri'
require 'open-uri'
require 'json'
doc = Nokogiri::HTML(open('http://www.mysupermarket.co.uk/asda-compare-prices/Spirits/Havana_Club_Rum_Anejo_7_Year_Old_700ml.html'))
prices = doc.css('#PriceComparison .StoreDiv').map {|c| { name: c.css('.ImgSpan img').first['alt'], cheapest: c['class'].include?('Cheapest'), price: c.css('.Price>span.priceClass, .Price>span.Offer').text.strip } }
# => [{:name=>"ASDA", :cheapest=>true, :price=>"£18.00"},
# {:name=>"Tesco", :cheapest=>false, :price=>"£23.30"},
# {:name=>"Ocado", :cheapest=>false, :price=>"£23.30"},
@mcoms
mcoms / ideas.md
Created November 29, 2013 17:28
"What are some neat, small electronics projects for university students?"

Ideas

  • Digital radio transmitter or receiver
  • GPS/GPRS tracker
  • High atmosphere air current tracking using balloons, and a pi/arduino with GPS and recording
  • Launch something that goes out of sight, then track/find it using your favourite protocol
  • Amateur radio beacon hunting using your own equipment
  • SMS remote control
  • 555 timer based signal generator
  • Piezo based floor piano

RTL-SDR tips and tricks

Sample format

The output is IQ (quadrature) sampling. It's interleaved, so first byte is I, second Q and so on. The samples are unsigned bytes, so you subtract 127 from them to get their real ralue (lying between -127 and +127).

rtl_tcp control

Send a command byte followed by a 32-bit big-endian int parameter.

@mcoms
mcoms / keepass2pass.rb
Created January 29, 2013 18:00
This ruby script reads a KeePass XML export (v2) and inserts the entries into pass, the UNIX password manager. It will use a path starting with "KeePass/" so you can manually check the entries.
def find_path(entry)
path = []
until entry.parent.name == 'Root' do
entry = entry.parent
path.insert(0, entry.css('>Name').text)
end
path
end
def insert_entry(entry)
@mcoms
mcoms / wishlist.md
Last active December 10, 2015 21:28
This is a list of random junk which I'm looking for, for various projects.

Wishlist

This is a list of random junk which I'm looking for, for various projects. In the spirit of http://uk.freecycle.org/, I like to recycle things where I can. I also have a box of odds and ends, so if you're looking for something electrical or mechanical, let me know as I might have it :)

  • Fire extinguisher/air tank
    • Doesn't have to work, but should be airtight
      • Ideally not a CO2 extinguisher
      • To be used as a 100psi air compression chamber
  • Arc welder/welding supplies
    • For welding steel, etc.
@mcoms
mcoms / ntwbfswtf.rb
Created December 14, 2012 19:49
Quick script to use WIT (http://wit.wiimm.de/) to move Wii (WBFS) backup files to a standard directory structure. Works with standard .wbfs files on a FAT/NTFS filesystem, for example.
require 'fileutils'
# Set the directory containing your backup files (they can be in sub-directories of this path)
f = Dir.glob './**/*.wbfs'
f.each do |n|
x = `wwt LIST \"#{n}\"`
if $?.success?
# WBFS containers can have multiple games in them. Here, we select just the first one for naming.
# Nearly always, you will have only backed up a single game per container anyway.
(id, name) = x.split("\n")[3].split(/\s{2,}/)
if id && name