Skip to content

Instantly share code, notes, and snippets.

View ajokela's full-sized avatar

A.C. Jokela ajokela

View GitHub Profile
@ajokela
ajokela / rackattack.rb
Created June 5, 2012 21:06
Rack::Callbacks
class TimeZone
def initialize(default)
@default = default
end
def call(env)
env['rack.timezone'] = find_timezone(env) || @default
end
end
@ajokela
ajokela / nicebytes.rb
Created June 4, 2012 15:56
Nice Bytes
# encoding: utf-8
module NiceBytes
K = 2.0**10
M = 2.0**20
G = 2.0**30
T = 2.0**40
def nice_bytes( bytes, max_digits=3 )
value, suffix, precision = case bytes
when 0...K
[ bytes, 'B', 0 ]
@ajokela
ajokela / dig.rb
Created April 30, 2012 15:12
'dig' into a Ruby Hash
class Hash
def dig(*path)
path.inject(self) do |location, key|
location.respond_to?(:keys) ? location[key] : nil
end
end
end
@ajokela
ajokela / gist:2242141
Created March 29, 2012 19:01
Shibboleth - Sessions
<Location "/app_path">
AuthType shibboleth
ShibRequireSession On/Off
ShibExportAssertion On
require valid-user
</Location>
@ajokela
ajokela / typo-to-wordpress-rss.rb
Created February 23, 2012 16:35
Typo Blog to Wordpress - RSS
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'environment'
require 'application'
articles = Article.find(:all)
xml = Builder::XmlMarkup.new(:target => STDOUT, :indent => 2)
xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
xml.rss 'version' => "2.0",
@ajokela
ajokela / gist:1887437
Created February 22, 2012 21:26
Photoshop Tilt Shift
http://www.tiltshiftphotography.net/photoshop-tutorial.php
@ajokela
ajokela / gist:1880641
Created February 22, 2012 02:05
MapReduce Example
http://snaggled.github.com/2010/10/29/Fun-with-MapReduce-Hadoop.html
@ajokela
ajokela / gist:1847606
Created February 16, 2012 20:27
Chrome Plugin for GPG
http://thinkst.com/tools/cr-gpg/
@ajokela
ajokela / gist:1846191
Created February 16, 2012 16:22
Decrypt passwords stored in Oracle SQL Developer.
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.*;
/**
* Decrypt passwords stored in Oracle SQL Developer.
* This is intended for password recovery.
*
* Passwords are stored in ~/.sqldeveloper/system2.1.1.64.39/o.jdeveloper.db.connection.11.1.1.2.36.55.30/connections.xml
*/
@ajokela
ajokela / gist:1845100
Created February 16, 2012 14:08
Split a large file with tar
Splitting the File
The two extra command line options you need to use over and above the standard syntax are -M (--multi-volume) which tells Tar you want to split the file over multiple media disks. You then need to tell Tar how big that media is, so that it can create files of the correct size. To do this you use the --tape-length option, where the value you pass is number x 1024 bytes.
The example below shows the syntax used. Lets say the largefile.tgz is 150 Meg and we need to fit the file on two 100 Meg Zip drives.
tar -c -M --tape-length=102400 --file=disk1.tar largefile.tgz
The value 102400 is 1024 x 100, which will create a 100 Meg file called disk1.tar and then Tar will prompt for volume 2 like below :-
Prepare volume #2 for disk1.tar and hit return: