Skip to content

Instantly share code, notes, and snippets.

View PatrickLef's full-sized avatar

Patrick Lef PatrickLef

  • Looking for exciting projects!
  • Stockholm, Sweden
View GitHub Profile
require 'spec_helper'
module Rack
class MockResponse
attr_accessor :data
end
module Test
class Session
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)]}'")
require 'rubygems'
require 'mysql'
require 'benchmark'
db = Mysql.new("localhost", "root", "", "test")
# INNODB - ENUM vs TEXT vs INT
Benchmark.bm do|b|
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)
------------------------------------------------
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|
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
# 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
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
Padrinotest.controller do
controller '/users', :provides => [:json] do
get '/' do
"foo"
end
end
end
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