Skip to content

Instantly share code, notes, and snippets.

namusyaka namusyaka

Block or report user

Report or block namusyaka

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@namusyaka
namusyaka / gist:16019a9fb929a3efe4c3
Created Jun 21, 2015
ruby-2.1.1と2.2.2で**の扱いが異なる件
View gist:16019a9fb929a3efe4c3
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 Aug 29, 2015
Builds trie-ized regexp
View gist:c92501557afb498ab7d3
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 Aug 29, 2015
Converts your movie into gif animation
View gist:ff945a5fe47b8e91faad
require 'fileutils'
require 'RMagick'
require 'streamio-ffmpeg'
class Turmeric
DEFAULT_OPTIONS = {
tmp_dir: "./tmp/",
resolution: "200x100",
duration: ->(movie){ movie.duration.to_i.times }
}.freeze
View gist:2652d0ce30b32870f376
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
View gist:fff3080403e1ebd4f0af
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
View gist:87c6cd9d4904dfad95b2
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 Dec 15, 2017
BetterErrors with Padrino 0.12
View gist:8265452
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
....
View gist:7322812

Upgrade from 0.11.x to 0.12.

Moneta

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

and, change the syntax.

# before
View gist:6209519
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|
View gist:6048717
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
You can’t perform that action at this time.