Skip to content

Instantly share code, notes, and snippets.

View scotttam's full-sized avatar

Scott Tamosunas scotttam

View GitHub Profile
@scotttam
scotttam / apns.py
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
scotttam / apns.rb
Created January 31, 2012 15:51
Sends an Apple Push Notification with Ruby
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 = File.open("ruby_the_byte_token", "wb")
@scotttam
scotttam / rev_split_num.rb
Created February 10, 2012 02:03
Reverse split a big number
def log(what, str, offset=0)
len = str.length
puts sprintf("| %-25s | %30s | (%-2s) |", what, str << " "*offset, len)
puts "_____________________________________________________________________"
end
def doit(match, buffer_size)
sl = match.slice(-14, 14)
log "14 of first 16", sl, buffer_size
@scotttam
scotttam / runtime.rb
Created February 17, 2012 12:01
Instrument bundler for gem load performance
def require(*groups)
gem_load_times = {}
groups.map! { |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?)
#!/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, encipher.final()]);
return encoded;
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'base64'
require 'digest'
require 'openssl'
def encode(cryptkey, iv, cleardata)
cipher = OpenSSL::Cipher.new('AES-256-CBC')
cipher.encrypt # set cipher to be encryption mode