Skip to content

Instantly share code, notes, and snippets.

View stevenshelby's full-sized avatar

Steven Shelby stevenshelby

  • London, Ontario, Canada
View GitHub Profile
@stevenshelby
stevenshelby / email_header_parser.rb
Created February 5, 2021 09:08 — forked from pmarreck/email_header_parser.rb
Superfast email header parser in Ruby, using regular expressions. This solution is 250 times faster than using the "Mail" gem. :O Time with my regex: 0.063965 seconds Time with Mail gem: 16.327161 seconds Note that I included some encoding-fix code. YMMV and encoding fixes are all debatable or fail in some corner case.
require 'ap'
require 'mail'
# String monkeypatch
# This is one of many possible "encoding problem" solutions. It's actually an intractable problem
# but you'd have to read "Gödel, Escher, Bach" to understand why...
class String
def clean_utf8
# self.force_encoding("UTF-8").encode("UTF-16BE", :invalid=>:replace, :replace=>"?").encode("UTF-8")
unpack('C*').pack('U*') if !valid_encoding?
############################
### CDOLLA CDOLLA CDOLLA ###
### CDOLLA CDOLLA CDOLLA ###
### CDOLLA CDOLLA CDOLLA ###
### CDOLLA CDOLLA CDOLLA ###
############################
###
###
@stevenshelby
stevenshelby / gist:029e130224651b3834c2f3a22e4039fd
Last active February 8, 2019 18:13 — forked from tommydunn/gist:6f885cc3efbd505e327a
Setting up Atom for Rails development
brew install caskroom/cask/brew-cask
brew cask install atom
apm install linter # Base linter
apm install linter-ruby
apm install linter-scss-lint
apm install linter-coffeelint
apm install linter-rubocop
apm install linter-haml
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
# p4p1 is WAN interface, #p1p1 is LAN interface
-A POSTROUTING -o p4p1 -j MASQUERADE
# NAT pinhole: HTTP from WAN to LAN
@stevenshelby
stevenshelby / census.rb
Created January 20, 2014 03:29
My solution to a problem seen on http://opengarden.com/careers.html in ruby.
#!/usr/bin/ruby
#The 2010 Census puts populations of 26 largest US metro areas at
#18897109, 12828837, 9461105, 6371773, 5965343, 5946800, 5582170, 5564635, 5268860, 4552402, 4335391, 4296250, 4224851, 4192887, 3439809, 3279833, 3095313, 2812896, 2783243, 2710489, 2543482, 2356285, 2226009, 2149127, 2142508, and 2134411.
#Can you find a subset of these areas where a total of exactly 100,000,000 people live,
#assuming the census estimates are exactly right? Provide the answer and code or reasoning used.
populations = [18897109, 12828837, 9461105, 6371773, 5965343, 5946800, 5582170, 5564635, 5268860, 4552402, 4335391, 4296250, 4224851, 4192887, 3439809, 3279833, 3095313, 2812896, 2783243, 2710489, 2543482, 2356285, 2226009, 2149127, 2142508, 2134411]
target = 100000000
@stevenshelby
stevenshelby / get_html_controller.rb
Last active December 28, 2015 11:08
finally, we can insert the static html into our views.
class MyController < ApplicationController
before_filter :get_small_list
def index
#can now access the @small_list in the index
end
end
def get_small_list
@small_list = fetch_url "http://myurl.com/small-list.html"
end
def fetch_url(url)
r = Net::HTTP.get_response( URI.parse( url ) )
if r.is_a? Net::HTTPSuccess
r.body.force_encoding("UTF-8")
else
nil
end
end
@stevenshelby
stevenshelby / simple_list.html
Created November 15, 2013 20:03
Just a simple HTML list
<ul>
<li>I am the first element in the list</li>
<li>I am the second element in the list</li>
<li>I am the last element in the list</li>
</ul>
@stevenshelby
stevenshelby / tif2group4
Last active December 28, 2015 10:59
Mass convert images with imagemagick and powershell
powershell "dir -recurse -include *.tif | %{mogrify -compress Group4 $_.FullName}"