Skip to content

Instantly share code, notes, and snippets.

View soutaro's full-sized avatar

Soutaro Matsumoto soutaro

View GitHub Profile
@soutaro
soutaro / resize_and_crop.rb
Created November 26, 2010 08:12
resize and crop using using MiniMagick
def resize_and_crop(blob, w0, h0, w1, h1)
image = MiniMagick::Image.read(blob)
rw = w1.to_f / w0
rh = h1.to_f / h0
unless rw > 1 or rh > 1
w,h = w1, h1
sx, sy = 0, 0
@soutaro
soutaro / gist:1111375
Created July 28, 2011 11:00
Ensure your remote branch is up to date
set :deploy_via, :remote_cache
set :branch, "release"
namespace :git do
namespace :ensure do
desc "Check if your local branch is synched with remote branch"
task :pushed do
local = `git rev-parse #{branch}`.chomp
remote = `git rev-parse remotes/origin/#{branch}`.chomp
@soutaro
soutaro / gist:1785761
Created February 10, 2012 02:38
Testing structures with meta variables, as unification.
# Testing two structures if they are unifiable.
#
module UnifierAssertion
def unify(es, s = {}, &block)
return s if es.empty?
e = es.shift
a,b = e
a = s[a] || a
@soutaro
soutaro / gist:1785776
Created February 10, 2012 02:42
Test codes for unification
require "test_helper"
require "unifier_assertion"
class UnifierAssertionTest < ActiveSupport::TestCase
include UnifierAssertion
test "unifier" do
assert_equal({:"'a" => 1 },
unify([[
[1,2,3],
class AjaxQ
initialize: (options) ->
_.extend(this, Backbone.Events)
@options = _.clone(options)
_.extend(@options, max:3)
@waiting = []
@requests = []
enqueue: (k) ->
1) Failure:
JsonIO::API3::Form::CheckoutTest#test_update_checkout_from_open_to_close [/Users/soutaro/src/ubiregi-server/test/unit/json_io/api3/form/checkout_test.rb:342]:
=> {:id=>76,
:guid=>"checkout_guid_1",
:account_id=>1743,
:paid_at=>2013-09-01 13:05:00 UTC,
:closed_at=>Sun, 01 Sep 2013 22:05:00 JST +09:00,
:deleted_at=>nil,
:created_at=>2014-06-02 06:26:38 UTC,
:updated_at=>2014-06-02 06:26:38 UTC,
@soutaro
soutaro / gist:e96d883bf31ce599ef4c
Last active August 29, 2015 14:16
remove_const
module A
module B
module C
def self.f()
puts "X = #{X}"
end
end
end
end
import Foundation
class A0 { }
class A1: A0 { }
class A2: A1 { }
class Array<X> {
func get() -> X { fatalError() }
func set(x: X) -> () { fatalError() }
}
@soutaro
soutaro / ruby -cw
Last active June 15, 2016 02:23
ruby -cw
$ cat -n w.rb
1 a = [1]
2
3 a.each do |a|
4 a = 3
5 end
6
7 p a
$ ruby -cw w.rb
w.rb:3: warning: shadowing outer local variable - a
class ['a] rbarray = object method map : 'b . ('a -> 'b) -> 'b rbarray = Obj.magic () end;;
(* Error: The universal type variable 'b cannot be generalized:
it escapes its scope. *)