Skip to content

Instantly share code, notes, and snippets.

View justincase's full-sized avatar

Justin Case justincase

View GitHub Profile
@justincase
justincase / gist:5469009
Created April 26, 2013 17:45
Print struct with field names and values. From http://blog.golang.org/2011/09/laws-of-reflection.html
type T struct {
A int
B string
}
t := T{23, "skidoo"}
s := reflect.ValueOf(&t).Elem()
typeOfT := s.Type()
for i := 0; i < s.NumField(); i++ {
@justincase
justincase / gist:4690368
Created February 1, 2013 09:36
BCrypt's 72 char limit
require 'bcrypt'
char71 = "a" * 71
char72 = char71 + "b"
BCrypt::Password.create(char71) == char72 # => false
char72 = "a" * 72
char73 = char72 + "b"
?attempt=&filename=nope
@justincase
justincase / gist:871758
Created March 15, 2011 23:58
Net HTTPS without callback
require 'net/http'
require 'net/https'
require 'uri'
url = URI.parse("https://github.com/") # OK
#url = URI.parse("https://etutorials.org/") # Hostname mismatch
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
request = Net::HTTP::Get.new(url.path)
require 'net/http'
require 'net/https'
require 'openssl'
url = URI.parse("https://github.com/") # OK
#url = URI.parse("https://etutorials.org/") # Hostname mismatch
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
@justincase
justincase / gist:850966
Created March 2, 2011 13:59
Set terminal title

Change terminal (tab) title to something meaningful instead of just 'ruby'

system("printf \"\033]0;Rails\007\"")

GitHub Javascript Strategy

Unless otherwise necessary (such as mobile development), the GitHub javascript codebase is based off jQuery. You can safely assume it will be included on every page.

File naming

  • All jquery plugins should be prefixed with jquery, such as jquery.facebox
  • All github-specific jquery plugins should be prefixed with jquery.github. Like jquery.github.repo_list.js
  • All page-specific files (that only run on ONE page) should be prefixed with page. page.billing.js
@justincase
justincase / auth.mdown
Created April 1, 2010 00:06
Authlogic Multiple Sessions / Session Identifiers

Authlogic Multiple Sessions / Session Identifiers

This explanation seems to be lost in the current README

You’re asking: "why would I want multiple sessions?". Take this example:

You have an app where users login and then need to re-login to view / change their billing information. Similar to how Apple’s me.com works. What you could do is have the user login with their normal session, then have an entirely new session that represents their "secure" session. But wait, this is 2 users sessions. No problem:

# regular user session
@user_session = UserSession.new

@user_session.id

@justincase
justincase / Result
Created December 31, 2008 05:35 — forked from flavorjones/Result
XML Document parsing benchmark
user system total real
hpricot:xml:doc 10.160000 0.950000 11.110000 ( 11.144462)
hpricot2:xml:doc 0.950000 0.000000 0.950000 ( 0.953266)
nokogiri:compat:doc 0.220000 0.020000 0.240000 ( 0.238401)
nokogiri:xml:doc 0.170000 0.030000 0.200000 ( 0.200283)
XML XPath benchmarks (//status/text, //user/name)
user system total real
hpricot:xml:xpath 7.580000 1.150000 8.730000 ( 8.728314)