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
@ocean
ocean / custom URI_EXTRA pattern
Last active August 29, 2015 14:10
Logstash WILL NOT parse my files :`-(
# custom regex pattern for our URIs, allowing
# ampersands in the URL and ^s in the query string.
URI_EXTRA %{URIPROTO}://(?:%{USER}(?::[^@]*)?@)?(?:%{URIHOST})?(?:(?:/[A-Za-z0-9$.+!*'(){},~:;=&@#%_\-]*)+(?:\?[A-Za-z0-9$.+!*'|(){},~@#%&\^/=:;_?\-\[\]]*)?)?
@ocean
ocean / keybase.md
Created June 29, 2015 13:41
keybase proof

Keybase proof

I hereby claim:

  • I am ocean on github.
  • I am ocean (https://keybase.io/ocean) on keybase.
  • I have a public key whose fingerprint is FD45 4D63 9596 4B4E 7B4A D156 1C15 4316 3B37 2385

To claim this, I am signing this object:

p "Oh I see, a Gist is a bit like a Pastie."
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.
#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>"
def html_entity_escape(string)
fixed = string.to_s.gsub(/&/, "&amp;").gsub(/½/, "&#189;").gsub(/¼/, "&#188;").gsub(/¾/, "&#190;").gsub(/“/, "&#8220;").gsub(/”/, "&#8221;").gsub(/’/, "&#8217;").gsub(/‘/, "&#8216;")
#fixed = string.to_s.gsub(/38/, "&amp;").gsub(/189/, "&#189;").gsub(/188/, "&#188;").gsub(/190/, "&#190;").gsub(/8220/, "&#8220;").gsub(/8221/, "&#8221;").gsub(/8217/, "&#8217;").gsub(/8216/, "&#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)
The below Sinatra code works with URLs like:
/c/blahblah
and
/c/http://blah.com/something.php
or
/c/google.com
#!/usr/bin/ruby
require 'rubygems'
require 'mysql'
require 'sqlite3'
def with_mysql
db_object = Mysql.init()
db_object.real_connect('localhost','things','1234','things')
<h1>Feeds Checker</h1>
<%
require 'hpricot'
require 'open-uri'
f1 = open("http://www.commerce.wa.gov.au/feeds/feed1.xml")
feed = Hpricot.XML(f1)
<!DOCTYPE html>
<html>
<head>
<title>g.RaphaelJS Graph Testing</title>
<script src='raphael-min.js'></script>
<script src='g.raphael-min.js'></script>
<script src='g.line-min.js'></script>
<script type='text/javascript'>
//<![CDATA[
window.onload = function () {