Skip to content

Instantly share code, notes, and snippets.

View masuidrive's full-sized avatar

Yuichiro MASUI masuidrive

View GitHub Profile
--
-- expire record and memcached record
--
require('Memcached') -- http://luamemcached.luaforge.net/
-- http://mixi.jp/view_bbs.pl?id=33263045&comm_id=3528783 #20
connect_memcache()
function expire()
local args = {}
require 'rbconfig'
ruby_path = File.join(Config::CONFIG["bindir"],
Config::CONFIG["RUBY_INSTALL_NAME"]+
Config::CONFIG["EXEEXT"])
/*
* Take screen capture on AS2
*/
ExternalInterface.addCallback("take_snap", null,
function():Void {
var width:Number = Stage.width;
var height:Number = Stage.height;
var snap:BitmapData = new BitmapData(width, height);
# Cucumber email_steps.rb for Merb
Given /^clear mailbox$/ do
Merb::Mailer.deliveries.clear.should == []
end
Then /^I should receive (an|\d+) emails?$/ do |amount|
amount = 1 if amount == "an"
Merb::Mailer.deliveries.size.should == amount
end
var funcs = [];
for(var i=0; i<10; ++i) {
funcs[i] = function() { console.log(i); }
}
i = -1;
for(var ii=0; ii<10; ++ii) funcs[ii]();
// -1が10回表示
@masuidrive
masuidrive / build-adhoc.rb
Created August 31, 2009 13:31
Automatic to build iPhone app package for AdHoc distribution
#!/usr/bin/env ruby
#
# build AdHoc package
#
# Install:
# sudo gem install mechanize
#
# Usage:
# ruby build-adhoc.rb adhoc.yaml
require 'open3'
require 'rubygems'
require 'zip/zipfilesystem'
require 'fileutils'
module Tempdir
def self.path(&block)
result = path = nil
begin
path = File.join((ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] || '/tmp'), "temp.#{$$}.#{Time.now.to_f}")
@masuidrive
masuidrive / geohash.rb
Created October 18, 2009 03:18
Geohash encode for pure ruby
=begin
geohash.rb
Geohash library for pure ruby
(c) 2009 Yuichiro MASUI
Distributed under the MIT License
move to http://github.com/masuidrive/pr_geohash
=end
@masuidrive
masuidrive / gist:212597
Created October 18, 2009 08:48
東京付近のGeoHashの精度
=begin
東京付近のGeoHashの精度
|文字数| 南北 | 東西 |
| 6| 609.08m| 988.77m|
| 7| 152.27m| 123.60m|
| 8| 19.03m| 30.90m|
| 9| 4.76m| 3.86m|
| 10| 0.59m| 0.97m|
# リファクタリング前
def encode(latitude, longitude, precision=12)
lat = [-90.0, 90.0]
lng = [-180.0, 180.0]
is_even = true
bit = ch = 0
geohash = ""
while geohash.length < precision do
point = is_even ? lng : lat