Skip to content

Instantly share code, notes, and snippets.

View justincase's full-sized avatar

Justin Case justincase

View GitHub Profile
@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 / 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:5492212
Created April 30, 2013 21:48
Enable mgo debug log
mgo.SetDebug(true)
var aLogger *log.Logger
aLogger = log.New(os.Stderr, "", log.LstdFlags)
mgo.SetLogger(aLogger)
@justincase
justincase / net-http-debug.rb
Created September 17, 2019 18:37 — forked from ahoward/net-http-debug.rb
a simple way to debug tons of libs that use ruby's net/http
BEGIN {
require 'net/http'
Net::HTTP.module_eval do
alias_method '__initialize__', 'initialize'
def initialize(*args,&block)
__initialize__(*args, &block)
@justincase
justincase / list.md
Last active April 6, 2017 18:23
List of PDF Producers found in the wild

PDF Producers

  • Acrobat Distiller 9.3.2 (Windows)
  • Adobe LiveCycle Designer ES 8.2
  • Adobe PDF Library 7.0
  • Apache FOP Version 1.0
  • Crystal Reports
  • EvoPdf HTML to PDF Converter 2.2
  • FPDF 1.6
  • FPDF 1.7
@justincase
justincase / gist:6054172
Last active December 20, 2015 02:09
Spying on Spotlight with fs_usage. http://superuser.com/a/46381

To see what mds and more importantly its child mdworker is actually doing - use fs_usage to log what files it is opening:

sudo fs_usage -w -f filesys mdworker

Though there is a lot of unintelligable stuff in there, it does tell you when it opens a file to begin reading from it. Copying a PDF into my filesystem shows mdworker opening the file then immediately after lots of activity...

p.s. if you want a little less detail, this will just list the open file points:

sudo fs_usage -w -f filesys mdworker | egrep "open"
@justincase
justincase / gist:5762948
Created June 12, 2013 05:06
awesome_print: Storing output in a variable
# https://github.com/michaeldv/awesome_print/issues/89
arr = [1,2,3].ai # short for awesome_inspect
@justincase
justincase / gfm.rb
Created June 12, 2013 00:28 — forked from mojombo/gfm.rb
require 'digest/md5'
def gfm(text)
# Extract pre blocks
extractions = {}
text.gsub!(%r{<pre>.*?</pre>}m) do |match|
md5 = Digest::MD5.hexdigest(match)
extractions[md5] = match
"{gfm-extraction-#{md5}}"
end
@justincase
justincase / gist:5737137
Created June 9, 2013 00:48
Python try/else example
# http://stackoverflow.com/questions/855759/python-try-else
try:
from EasyDialogs import AskPassword
except ImportError:
getpass = default_getpass
else:
// 20 other lines
getpass = AskPassword
@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"