Skip to content

Instantly share code, notes, and snippets.

View jingoro's full-sized avatar

John Nishinaga jingoro

View GitHub Profile
@jingoro
jingoro / gist:3015664
Created June 29, 2012 04:08
Mongoid Callback Sequence
require 'rubygems'
require 'bundler/setup'
require 'mongoid'
Mongoid.configure do |config|
config.master = Mongo::Connection.new('localhost', 27017, :logger => nil).db('mongoid-test')
end
class A
include Mongoid::Document
@jingoro
jingoro / stern-brocot-pi.rb
Created October 3, 2012 00:35
Stern-Brocot Pi
#!/usr/bin/env ruby
require 'rational'
require 'bigdecimal'
PI = BigDecimal.new("
3.141592653589793238462643383279502884197169399375105820974944592307816406286
208998628034825342117067982148086513282306647093844609550582231725359408128481
117450284102701938521105559644622948954930381964428810975665933446128475648233
786783165271201909145648566923460348610454326648213393607260249141273724587006
@jingoro
jingoro / modular_arithmetic.rb
Created April 14, 2012 23:43
Ruby modular arithmetic
# Some modular arithmetic helper methods useful for number theory or
# cryptography.
#
# # Examples
#
# Compute the greatest common denominator of 114 and 48:
#
# gcd(114, 48) #=> 6
#
# Compute `a` and `b` such that `a*x + b*y = gcd(x, y)`:
@jingoro
jingoro / ffx-radix
Created October 3, 2012 00:57
FFX Radis Play
# /usr/bin/env ruby
#
# http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/ffx/ffx-spec.pdf
# http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/ffx/ffx-spec2.pdf
# http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/ffx/ffx-ad-VAES3.pdf
require 'openssl'
def radix_block_prepend(radix, n, block)
alias server='open http://localhost:8000 && python -m SimpleHTTPServer'
#!/bin/bash
#
# Prerequisites: brew install mpg123 vorbis-tools
for fm in "$@"; do
f="${fm%.mp3}"
if [ "$f" != "$fm" ] && [ -a "$fm" ]; then
mpg123 -w - "$f.mp3" | oggenc -o "$f.ogg" -
fi
done
#!/bin/bash
# dependencies:
# sudo port install sox
TITLE="On the hour..."
MESSAGE="...where are you?"
SOUND="/System/Library/Sounds/Hero.aiff"
PLAY="/usr/bin/afplay"
#!/bin/sh
for file in $*; do
advpng -z1 "$file" && optipng -i0 -o7 "$file" && advpng -z4 "$file"
done
#!/usr/bin/env python
# prerequisites
# sudo easy_install markdown
# install https://code.google.com/p/wkhtmltopdf/
WKHTMLTOPDF_PATH = "/usr/local/bin/wkhtmltopdf"
import sys, os, subprocess, re, urllib, tempfile
import markdown
#!/bin/sh
for file in $*; do
jpegtran -optimize -progressive -copy none \
"$file" > "$file.tran"
mv -f "$file".tran "$file"
done