Skip to content

Instantly share code, notes, and snippets.

View namusyaka's full-sized avatar

namusyaka namusyaka

View GitHub Profile
@namusyaka
namusyaka / gist:16019a9fb929a3efe4c3
Created June 21, 2015 06:20
ruby-2.1.1と2.2.2で**の扱いが異なる件
def a(**options)
options
end
def b(**options)
a(foo: true, **options)
end
# 2.1だと{:foo=>true}, 2.2だと{:foo=>false}が出力される。
# 2.1が正しいように思う。
@namusyaka
namusyaka / gist:c92501557afb498ab7d3
Last active August 29, 2015 14:14
Builds trie-ized regexp
require 'forwardable'
class Regexp
class Trie
def self.union(*patterns)
trie = new
patterns.each { |pattern| trie << pattern }
trie.to_regexp
end
@namusyaka
namusyaka / gist:ff945a5fe47b8e91faad
Last active August 29, 2015 14:13
Converts your movie into gif animation
require 'fileutils'
require 'RMagick'
require 'streamio-ffmpeg'
class Turmeric
DEFAULT_OPTIONS = {
tmp_dir: "./tmp/",
resolution: "200x100",
duration: ->(movie){ movie.duration.to_i.times }
}.freeze
class A
attr_writer :foo
def test(k)
[respond_to?(:"#{k}="), respond_to?("#{k}=")]
end
end
a = A.new
p a.respond_to?(:test) #=> true
p a.respond_to?("test") #=> true
diff --git a/padrino-core/lib/padrino-core/reloader.rb b/padrino-core/lib/padrino-core/reloader.rb
index d157017..f990c6d 100644
--- a/padrino-core/lib/padrino-core/reloader.rb
+++ b/padrino-core/lib/padrino-core/reloader.rb
@@ -223,6 +223,7 @@ module Padrino
files = Set.new
files += Dir.glob("#{Padrino.root}/{lib,models,shared}/**/*.rb")
reloadable_apps.each do |app|
+ next unless app.app_file.start_with?(Padrino.root)
files << app.app_file
diff --git a/Gemfile b/Gemfile
index aa19617..fa847b7 100644
--- a/Gemfile
+++ b/Gemfile
@@ -21,6 +21,7 @@ gem 'slim'
# Padrino Stable Gem
gem 'padrino', '0.12.2'
+gem 'rack-parser'
@namusyaka
namusyaka / gist:8265452
Last active December 15, 2017 16:23
BetterErrors with Padrino 0.12
module Foobar
class App < Padrino::Application
enable :sessions
configure :development do
use BetterErrors::Middleware
BetterErrors.application_root = PADRINO_ROOT
set :protect_from_csrf, except: %r{/__better_errors/\d+/\w+\z}
end
....

Upgrade from 0.11.x to 0.12.

Moneta

Need to delete old cache files. (rm -rf ./tmp/*)

and, change the syntax.

# before
@namusyaka
namusyaka / gist:6209519
Created August 12, 2013 09:36
using mecab
require 'MeCab'
require 'kconv'
class MecabParser
def initialize(param = nil)
@mecab = param ? MeCab::Tagger.new(param) : MeCab::Tagger.new
end
def parse(str)
@mecab.parse(str).split(/\n/).inject([]) do |data, line|
module Sandbox
class App < Padrino::Application
register Padrino::Helpers
register Padrino::Cache
enable :caching
get :test, "/test/:test_id", :cache => true do |test_id|
cache_key test_id
test_id
end