Skip to content

Instantly share code, notes, and snippets.


Scott Tamosunas scotttam

View GitHub Profile
View aes_256_cbc.rb
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'base64'
require 'digest'
require 'openssl'
def encode(cryptkey, iv, cleardata)
cipher ='AES-256-CBC')
cipher.encrypt # set cipher to be encryption mode
View aes_256_cbc.js
#!/usr/bin/env node
var crypto = require('crypto');
function encode(cryptkey, iv, cleardata) {
var encipher = crypto.createCipheriv('aes-256-cbc', cryptkey, iv),
encoded = encipher.update(cleardata);
encoded = Buffer.concat([encoded,]);
return encoded;
scotttam / runtime.rb
Created February 17, 2012 12:01
Instrument bundler for gem load performance
View runtime.rb
def require(*groups)
gem_load_times = {}! { |g| g.to_sym }
groups = [:default] if groups.empty?
@definition.dependencies.each do |dep|
# Skip the dependency if it is not in any of the requested
# groups
next unless ((dep.groups & groups).any? && dep.current_platform?)
scotttam / rev_split_num.rb
Created February 10, 2012 02:03
Reverse split a big number
View rev_split_num.rb
def log(what, str, offset=0)
len = str.length
puts sprintf("| %-25s | %30s | (%-2s) |", what, str << " "*offset, len)
puts "_____________________________________________________________________"
def doit(match, buffer_size)
sl = match.slice(-14, 14)
log "14 of first 16", sl, buffer_size
scotttam / apns.rb
Created January 31, 2012 15:51
Sends an Apple Push Notification with Ruby
View apns.rb
require "rubygems"
require "yajl"
require "openssl"
require "socket"
device_token = '39cac56f 986a0e66 3c4fd4f4 68df5598 024d2ca3 8b9f307c 741c180e 9fc30c62'
device_token = device_token.gsub(" ", "")
the_byte_token = [device_token].pack("H*")
file ="ruby_the_byte_token", "wb")
scotttam /
Created January 30, 2012 21:21
Sends an Apple Push Notification with Python
import socket, ssl, json, struct
import binascii
# device token returned when the iPhone application
# registers to receive alerts
deviceToken = '39cac56f 986a0e66 3c4fd4f4 68df5598 024d2ca3 8b9f307c 741c180e 9fc30c62'
thePayLoad = {
'aps': {
'alert':'Oh no! Server\'s Down!',
scotttam / apns_test.rb
Created January 28, 2012 20:19
apns test
View apns_test.rb
require "base64"
require "openssl"
require "socket"
require "yajl" #gem install yajl-ruby
# DEVICE_TOKEN = Base64.decode64("4DJXVKUhziWwNihDfraFXXZ4RIJK+dCHoiS3awnh0w0=")
scotttam / gist:1683489
Created January 26, 2012 16:02
failed iOS compilation
View gist:1683489
cd /var/folders/9n/980qyb090qj5xnbvct2z45rm0000gp/T/4f2176bcb2c2097f8b0001e2/1327593542/IOS
setenv LANG en_US.US-ASCII
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/Users/scotttam/.rvm/gems/ruby-1.9.2-p180@katama_server_push/bin:/Users/scotttam/.rvm/gems/ruby-1.9.2-p180@global/bin:/Users/scotttam/.rvm/rubies/ruby-1.9.2-p180/bin:/Users/scotttam/.rvm/bin:/opt/local/bin:/opt/local/sbin:/Xcode4/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/mysql/bin:/Users/scotttam/workspace/users/brightcove/bin:/Applications:/Users/scotttam/ec2/bin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc-4.2 -x objective-c -arch armv7 -fmessage-length=0 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -Os -Wreturn-type -Wunused-variable -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -gdwarf-2 -fvisibility=hidden -mthumb -miphoneos-version-min=4.0 -iquote /var/folders/9n/980qyb090qj5xnbvct2z45rm0000gp/T/4f2176bcb
View gist:1401441
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(git::\1)/'
export PS1="\[\033[00m\]\u@\h\[\033[01;34m\] \w \[\033[31m\]\$(parse_git_branch)\[\033[00m\]$\[\033[00m\] "
alias ss='script/rails server'
alias c='script/rails console'
alias start_resque='rake VVERBOSE=1 QUEUE=* environment resque:work --trace'
alias start_ios='cd ~/workspace/katama_server; ruby script/ios_resque_endpoint.rb'
scotttam / pbkdf2_aes.js
Created August 16, 2011 14:46
Javascript example generating a PBKDF2 key and encrypting/decrypting using AES/256/CBC
View pbkdf2_aes.js
//slowAES (
//pbkdf2 (1.1) by Parvez Anandam (
//sha1 (2.1a) by Paul Johnston (
(function(window, document, $, undefined){
$(document).ready(function() {
var startTime = new Date();