Skip to content

Instantly share code, notes, and snippets.

View jingoro's full-sized avatar

John Nishinaga jingoro

View GitHub Profile
@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)
@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 / 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 / mongoid-ambiguous-relation-bug.rb
Created May 4, 2012 19:43
Mongoid Ambigious Relation Bug?
require 'rubygems'
require 'bundler/setup'
require 'mongoid'
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db("mongoid-test")
end
class Group
include Mongoid::Document
@jingoro
jingoro / gist:2562645
Created April 30, 2012 20:59
start/stop apache on macports
sudo /opt/local/apache2/bin/apachectl start
sudo /opt/local/apache2/bin/apachectl stop
@jingoro
jingoro / gist:2388983
Created April 15, 2012 00:13
Install gmp gem on OS X macports
LIBRARY_PATH=/opt/local/lib C_INCLUDE_PATH=/opt/local/include gem install gmp
@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 / bc_round
Created October 5, 2011 19:11
bc round to nearest integer
define round ( x ) {
auto origscale, result;
origscale = scale;
scale = 0
result = (x + 0.5) / 1;
scale = origscale;
return result;
}
--- botobackend.py.orig 2010-07-25 16:14:39.000000000 +0000
+++ botobackend.py 2010-09-30 15:52:41.000000000 +0000
@@ -146,7 +146,7 @@
else:
self.conn.calling_format = calling_format
- else:
+ elif self.bucket_name is None:
# Duplicity hangs if boto gets a null bucket name.
# HC: Caught a socket error, trying to recover
PRUNEPATHS="/tmp /var/tmp */Backups.backupdb /Users" sudo /usr/libexec/locate.updatedb