Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
require 'openssl'
=begin
Implements the MAC generation process which needs to be applied to Standard 70
transaction requests and replies. Uses example data to assert correctness at
each step of the process.
This script generates the MAC and MAC residue for the example request message,
$("canvas").remove();
c = document.createElement('canvas');
c.width = c.height = 300;
$(document.body).append(c);
$(c).css("width", "300px");
$(c).css("height", "300px");
$(c).css("position", "absolute");
$(c).css("top", "0px");
$(c).css("left", "0px");
$(c).css("border", "1px solid #000");
Jax.getGlobal().ApplicationHelper = Jax.Helper.create
patch_world: ->
Jax.World.prototype.pick_all_visible = () ->
context = this.context
w = context.canvas.width
h = context.canvas.height
data = new Uint8Array(w*h*4)
data.w = w
data.h = h
data.f = f = 4
@sinisterchipmunk
sinisterchipmunk / install_homebrew.rb
Created February 15, 2012 16:16 — forked from mxcl/install_homebrew.markdown
get the ruby shebang from env so you can use non-standard ruby paths
#!/usr/bin/env ruby
# This script installs to /usr/local only. To install elsewhere you can just
# untar https://github.com/mxcl/homebrew/tarball/master anywhere you like.
module Tty extend self
def blue; bold 34; end
def white; bold 39; end
def red; underline 31; end
def reset; escape 0; end
def bold n; escape "1;#{n}" end
@sinisterchipmunk
sinisterchipmunk / Example 1
Created January 27, 2012 15:17
Code examples for "Understanding REST in Rails 3" - http://thoughtsincomputation.com/understanding-rest-in-rails-3
REST request | CRUD request | Action
----------------|----------------------|-------
POST /posts | /posts/create | Create
GET /posts/1 | /posts/show/colin | Read
PUT /posts/1 | /posts/update/colin | Update
DELETE /posts/1 | /posts/destroy/colin | Delete
@sinisterchipmunk
sinisterchipmunk / dice.rb
Created January 16, 2012 01:33
Code examples for "Welcome to my world!" - http://localhost:3000/mist/posts/welcome-to-my-world
class Dice
def initialize(count, sides)
@count, @sides = count, sides
end
def roll
@count.times.inject(0) { |a,i| a + rand(sides) }
end
end
@sinisterchipmunk
sinisterchipmunk / dungeon.js.coffee
Created November 27, 2011 00:17
example of dungeon model as of section 8.5 of the Jax guides: http://guides.jaxgl.com/getting_started.html#drawing-the-scene
parse = (str) ->
vec = str.split /,\s*/
return [ parseFloat(vec[0]), 0.0, parseFloat(vec[1]) ]
Jax.getGlobal()['Dungeon'] = Jax.Model.create
addTorches: (world) ->
if @map
for z in [0...@map.length]
row = @map[z]
for x in [0...row.length]
@sinisterchipmunk
sinisterchipmunk / LICENSE
Last active October 23, 2024 21:10
tar, gzip, and untar files using ruby in memory without tempfiles
Copyright (C) 2011 by Colin MacKenzie IV
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
@sinisterchipmunk
sinisterchipmunk / assets.rake
Created September 13, 2011 13:53 — forked from shedd/assets.rake
Check asset encoding for valid UTF-8; if not valid, show compatible encodings
namespace :assets do
task :check => :environment do
paths = ["app/assets", "lib/assets", "vendor/assets"]
paths.each do |path|
dir_path = Rails.root + path
if File.exists?(dir_path)
dir_files = File.join(dir_path, "**")
set :deploy_to, "public_html" # the remote path where the gem index lives
set :build_command, "bundle exec rake build" # the command to build the gem locally
set :user, "rubygems" # the user to log in to the server with
# the rubygems server to deploy to
server "gems.example.com", :app
desc "Deploy the gem and rebuild the index"
task :deploy do
build