This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'mysql' | |
require 'sqlite3' | |
def with_mysql | |
db_object = Mysql.init() | |
db_object.real_connect('localhost','things','1234','things') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The below Sinatra code works with URLs like: | |
/c/blahblah | |
and | |
/c/http://blah.com/something.php | |
or | |
/c/google.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p "Oh I see, a Gist is a bit like a Pastie." |
NewerOlder