This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding- utf-8 | |
sum = 2 | |
t = 1 | |
t2 = 2 | |
while (t + t2) < 4000000 | |
tmp = t2 | |
t2 = t + t2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Enable route to __noSuchMethod__ when unknown method calling. | |
* | |
* @param {Object} obj Target object. | |
* @return {Object} | |
*/ | |
function enableMethodMissing(obj) { | |
var functionHandler = createBaseHandler({}); | |
functionHandler.get = function(receiver, name) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sleep(seconds) { | |
var end = Date.now() + 1000 * seconds; | |
var now = Date.now(); | |
while (now < end) { now = Date.now(); } | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
class Class | |
self.private_methods.grep(/^attr_/) {|m| puts m} | |
class << self | |
self.private_methods.grep(/^attr_/) {|m| puts m} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
require 'data_mapper' | |
require File.expand_path('../schema', __FILE__) | |
if __FILE__ == $0 | |
db_path = File.expand_path('../test.db', __FILE__) | |
DataMapper.setup(:default, 'sqlite://'+db_path) | |
DataMapper.auto_upgrade! | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
require 'data_mapper' | |
class Post | |
include DataMapper::Resource | |
property :id, Serial | |
property :title, String | |
property :body, Text | |
property :created_at, DateTime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Customise Backbone.sync to work with Titanium rather than jQuery | |
var getUrl = function(object) { | |
if (!(object && object.url)) return null; | |
return _.isFunction(object.url) ? object.url() : object.url; | |
}; | |
Backbone.sync = (function() { | |
var methodMap = { | |
'create': 'POST', | |
'read' : 'GET', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Hoge | |
def self.included(base) | |
base.extend ClassMethods | |
end | |
module ClassMethods | |
# class methods... | |
end | |
# instance methods... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
require 'minitest/unit' | |
MiniTest::Unit.autorun | |
class FooTest < MiniTest::Unit::TestCase | |
def test_return_100 | |
@total = '100' | |
assert_equal 100, @total.to_i | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# be rake SPEC_OPTS="-fd -c" | |
require 'rspec/core/rake_task' | |
RSpec::Core::RakeTask.new(:spec) | |
# 試していないがこれでオプションをつけれるかも | |
#RSpec::Core::RakeTask.new(:spec) do |t| | |
#t.rspec_opts = %w[--color] | |
#t.pattern = 'spec/*_spec.rb' | |
#end |