Skip to content

Instantly share code, notes, and snippets.

@morganp
morganp / east_lothian_timber.md
Last active August 29, 2015 14:26
Timber suppliers in East Lothian and the rest of Scotland

East Lothian

Not East Lothian

Berwickshire

Dunfermline

@morganp
morganp / links.md
Created August 3, 2015 10:25
Building Links
@morganp
morganp / chrome_ext.md
Created August 25, 2015 07:09
Chrome Extensions

uBlock Origin : Add blocker (Faster less resource intensive than adblock)

Lazarus: Form Recovery (just started using) http://lazarus.interclue.com/

Add to Amazon Wishlist (occasional use)

#!/usr/bin/env ruby
#A way of including local functions in sub folders
path = File.expand_path $0
path = File.dirname(path)
require "#{path}/SubDir/function_1.rb"
require "#{path}/SubDir/function_2.rb"
require "#{path}/SubDir/function_3.rb"
#Or change working dir of script
#Small function to run a command and output return values
def do_and_report(command)
f = open("| #{command}")
g = Array.new
while (foo = f.gets)
g << foo
end
g.each do |element|
puts element
end
## Command line to apply Migration
#sequel -m ./db/migrate/ -M 4 sqlite://db/blog.db
## Command to roll back
#sequel -m ./db/migrate/ -M 3 sqlite://db/blog.db
Class.new(Sequel::Migration) do
def up
DB.alter_table :aTable do
rename_column :old, :new
#Small function to generate a comma delimited dictionary on a unix system
def gen_dictionary
f = open("| cat /usr/share/dict/words")
g = Array.new
while (foo = f.gets)
g << foo
end
g.each do |element|
element = element.strip
print element + ","
# Sinatra method for handling file uploads
# based on http://pastie.caboo.se/134681
require 'rubygems'
require 'sinatra'
get '/upload' do
erb '<form action="upload" method="post" enctype="multipart/form-data" accept-charset="utf-8">
<input type="file" name="uploaded_data" id="uploaded_data">
<p><input type="submit" value="Continue"></p>
</form>'
#!/usr/bin/env ruby
## Command Line tools can now be portable while working on static folders.
if ENV['MEDIA_FOLDER'].nil?
puts "Add this to ~/.bashrc"
puts "Or Windows variables"
puts "export MEDIA_FOLDER='[\"/user/name/Movies\", \"/user/name/TV Shows\"]'"
else
puts ENV['MEDIA_FOLDER']