This file contains 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
require 'spec_helper' | |
module Rack | |
class MockResponse | |
attr_accessor :data | |
end | |
module Test | |
class Session |
This file contains 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
require 'rubygems' | |
require 'mysql' | |
db = Mysql.new("localhost", "root", "", "test") | |
words = %w{patrick johan peter niklas} | |
500_000.times do | |
db.query("INSERT INTO innodb SET varcharen='#{words[rand(words.size)]}', inten=#{rand(words.size)}, enumen='#{words[rand(words.size)]}'") | |
db.query("INSERT INTO innodb_index SET varcharen='#{words[rand(words.size)]}', inten=#{rand(words.size)}, enumen='#{words[rand(words.size)]}'") |
This file contains 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
require 'rubygems' | |
require 'mysql' | |
require 'benchmark' | |
db = Mysql.new("localhost", "root", "", "test") | |
# INNODB - ENUM vs TEXT vs INT | |
Benchmark.bm do|b| |
This file contains 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
user system total real | |
INNO DB: VARCHAR 0.260000 0.150000 0.410000 ( 2.522178) | |
INNO DB: ENUM 0.270000 0.150000 0.420000 ( 2.510159) | |
INNO DB: INTEN 0.000000 0.030000 0.030000 ( 1.590618) | |
------------------------------------------------ | |
user system total real | |
INNO DB INDEXED: VARCHAR 0.280000 0.150000 0.430000 ( 8.139827) | |
INNO DB INDEXED: ENUM 0.280000 0.160000 0.440000 ( 8.462467) | |
INNO DB INDEXED: INTEN 0.000000 0.000000 0.000000 ( 0.002502) | |
------------------------------------------------ |
This file contains 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 Padrino | |
module Reloader | |
module Stat | |
class << self | |
def rotation | |
paths = Dir[Padrino.root("*")].unshift(Padrino.root).reject { |path| !File.directory?(path) } | |
files = paths.map { |path| Dir["#{path}/**/*.rb"] }.flatten.uniq | |
files.map{ |file| |
This file contains 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 Utils | |
# Creates a hash from instance vars | |
def attributes | |
vars = {} | |
instance_variables.each do |var| | |
vars[var.gsub("@", "").to_sym] = instance_variable_get(var) | |
end | |
vars | |
end | |
end |
This file contains 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
# A user have methods for login and such | |
class User < Sequel::Model(:users) | |
end | |
# A administrator is a USER but have extra data in | |
# administrators table. | |
class Administrator < User | |
one_to_one :user | |
set_dataset(:administrators) | |
end |
This file contains 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 test_default_guest_gives_login_screen | |
get '/' | |
assert last_response.ok? | |
assert last_response.body.include?('log in to continue') | |
end | |
----------> | |
context "When accessing / guest should see the login screen" do | |
before :all do |
This file contains 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
Padrinotest.controller do | |
controller '/users', :provides => [:json] do | |
get '/' do | |
"foo" | |
end | |
end | |
end |
This file contains 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 provides(*types) | |
types = [types] unless types.kind_of? Array | |
types.map!{|t| mime_type(t)} | |
condition { | |
matching_types = (request.accept & types) | |
unless matching_types.empty? | |
response.headers['Content-Type'] = matching_types.first | |
true | |
else |
OlderNewer