Skip to content

Instantly share code, notes, and snippets.

Avatar

iori matsumonkie

View GitHub Profile
View gist:90c079d2ee5798ea7f03
function ConvertGoogleDocToCleanHtml() {
var body = DocumentApp.getActiveDocument()//.getBody();
var numChildren = body.getNumChildren();
var output = [];
var images = [];
var listCounters = {};
var toc = {}
for (var i = 0; i < numChildren; i++) {
var p = body.getChild(i);
@matsumonkie
matsumonkie / result_callback.rb
Created Aug 12, 2014
return value method callback
View result_callback.rb
class Result
def self.success
Result.new
end
def self.error(error)
Result.new(error)
end
View null_object.rb
class NullObject
def method_missing(*)
self
end
def respond_to_method_missing?(name)
true
end
def nil?
@matsumonkie
matsumonkie / dci.rb
Created Jun 15, 2014
dci benchmarks
View dci.rb
require 'benchmark'
require 'delegate'
#---------------------------------------------------------------
# ruby normal implementation
#---------------------------------------------------------------
module Mover
def accelerate(speed:)
@speed += speed
end
View registry.rb
module Registry
class << self
def logger
# some default logger...
end
def server
# some server
end
View fallback.rb
#------------------------------------------------------------------------
def Fallback(lambda, &fallback)
fallback ||= -> { raise }
begin
lambda.call()
rescue
fallback.call()
end
end
View singleton_object.rb
# singleton object are usefull if you
# want an object that is stateless
class << (FERRARI = Object.new)
def to_s
"Ferrari from Maranello"
end
end
case FERRARI
when FERRARI then puts FERRARI # "Ferrari from Maranello"
View delegator.rb
require 'forwardable'
class Vehicle
extend Forwardable
def_delegators :@vehicle, :name, :power, :color
def to_s
"#{name} with #{power} HP"
View module_functions.rb
#----------------------------------------------------------------------
module Util
module StringFormatter
module_function
def prettry_string(string)
"-> [#{string}] <-"
end
end
View decorator.rb
require 'delegate'
#----------------------------------------------------------------------
class Logger
DEFAULT_FORMATTER = '%d'
def initialize(formatter)
@formatter = formatter || DEFAULT_FORMATTER