Skip to content

Instantly share code, notes, and snippets.

View ocean's full-sized avatar
Ahoy there 🚢

Drew Robinson ocean

Ahoy there 🚢
View GitHub Profile
#!/usr/bin/ruby
require 'rubygems'
require 'mysql'
require 'sqlite3'
def with_mysql
db_object = Mysql.init()
db_object.real_connect('localhost','things','1234','things')
The below Sinatra code works with URLs like:
/c/blahblah
and
/c/http://blah.com/something.php
or
/c/google.com
def html_entity_escape(string)
fixed = string.to_s.gsub(/&/, "&").gsub(/½/, "½").gsub(/¼/, "¼").gsub(/¾/, "¾").gsub(/“/, "“").gsub(/”/, "”").gsub(/’/, "’").gsub(/‘/, "‘")
#fixed = string.to_s.gsub(/38/, "&").gsub(/189/, "½").gsub(/188/, "¼").gsub(/190/, "¾").gsub(/8220/, "“").gsub(/8221/, "”").gsub(/8217/, "’").gsub(/8216/, "‘")
return fixed
end
blahblah = "only 3 breaks of ½ hour, worked for 16 ¼ hours, had a break of 8 ¼ hours"
puts html_entity_escape(blahblah)
#results.each do |row|
results.each_hash do |row|
# 'collect' enables handling of NULL/nil values
row = row.collect { |v| v.nil? ? "" : v }
#fname = row[0] + ".html"
fname = row["ID"] + ".html"
open(fname, 'w') do |f|
f.puts "<strong>Defendant</strong><br>"
#f.puts row[1] + "</p>"
I got the idea, and most of this code, from this post at The Killswitch Collective:
http://www.killswitchcollective.com/articles/45_legacy_data_migration_with_activerecord
I'm sure that other bits of the code aren't going to work either, like the "if" statement
in the "publish" boolean field, I suppose there will be another way to make that work.
p "Oh I see, a Gist is a bit like a Pastie."