Skip to content

Instantly share code, notes, and snippets.

View namusyaka's full-sized avatar

namusyaka namusyaka

View GitHub Profile
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'
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
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
@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
@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: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:796679
Created January 26, 2011 13:27
HatenaDiary-rssのchannel部分だけ取得&キャッシュ
#!/usr/local/bin/ruby
require 'net/http'
require 'rss'
require 'time'
require 'lib/simple_cgi.rb'
print "Content-Type:text/html\n\n"
query = SimpleCGI::query
require 'rss'
require 'net/http'
require 'uri'
require 'time'
Net::HTTP.version_1_2
class RSSReader
@@http = Net::HTTP
@namusyaka
namusyaka / gist:869501
Created March 14, 2011 17:29
現在開いているページのHTMLに含まれる画像URLを画像化して列挙するスクリプト。
javascript:(function(){
var _d = document;
var array = _d.body.innerHTML.match(/("|')([^"']+?\.)(jpg|gif|png|bmp|jpeg)("|')/ig);
if(!array)
return alert('見つからなかった。');
var exist = {};
for(var i=0; i < array.length; i++) {
if(!exist[array[i]]) {
_d.write('<img src=' + array[i] + '>');
exist[array[i]] = 1
@namusyaka
namusyaka / gist:869512
Created March 14, 2011 17:34
Objectリテラルを定義リスト、配列をリストに再帰的に変換する関数。
function parseObject(obj) {
var _d = document, create = function(element) {return _d.createElement(element)}
switch(obj.constructor) {
case Array:
var list = create('ul');
break
case Object:
var list = create('dl');
break
default: