Skip to content

Instantly share code, notes, and snippets.

View gotar's full-sized avatar
🏠
Working from home

Oskar Szrajer gotar

🏠
Working from home
View GitHub Profile
@gotar
gotar / README.md
Created March 18, 2014 13:43 — forked from rantav/README.md

A few show tricks to find slow queries in mongodb

Enable profiling

First, you have to enable profiling

> db.setProfilingLevel(1)

Now let it run for a while. It collects the slow queries ( > 100ms) into a capped collections, so queries go in and if it's full, old queries go out, so don't be surprised that it's a moving target...

---------------------------------------------------------------------------------------------------------
0,01 0,00 0,00 203/203 Mongoid::Fields::Validators::Macro.validate_name
0% 0% 0,01 0,00 0,00 203 Mongoid.destructive_fields
0,00 0,00 0,00 203/875 BasicObject#__send__
---------------------------------------------------------------------------------------------------------
0,00 0,00 0,00 2/149 NewRelic::Control::InstanceMethods.init_plugin
0,00 0,00 0,00 1/149 Module#alias_method_chain
0,00 0,00 0,00 74/149 Hash#inspect
0,00 0,00 0,00 72/149 Array#to_default_s
0% 0% 0,01 0,01 0,00 149 String#ins
Verifying that +gotar is my openname (Bitcoin username). https://onename.io/gotar
require 'lotus/validations'
module UserValidations
include Lotus::Validations
attribute :login, presence: true, format: /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/
attribute :password, presence: true, confirmation: true, size: 8..64
end
class User
Sequel.migration do
up do
run 'CREATE EXTENSION "uuid-ossp"'
create_table :products do
column :id, :uuid, :default => Sequel.function(:uuid_generate_v4), :primary_key => true
end
end
end
require 'transproc/all'
require 'addressable/uri'
##
# Convert string keys to symbols
#
transform = Transproc(:symbolize_keys)
data = {
'name' => 'Mark Rickerby',
@gotar
gotar / json_api.rb
Created August 12, 2015 17:22
Mapping raw tuple to jsonapi using rom-mapper and yaks
require 'anima'
require 'rom-mapper'
require 'yaks'
class User
include Anima.new(:id, :first_name, :last_name, :posts)
end
class Post
include Anima.new(:id, :title)
ruby-1.9.2-p180 :006 > y CheapestFlight.collect_data(json)
---
- :stops: "0"
:faretype: AMADEUS_PUBLISHED
:farebase: "[[\"USALE\"]]"
:airlines: CY
:is_mixed: "0"
:roundtrip: false
:arr: SKG
:dep: ATH
ruby-1.9.2-p180 :006 > y CheapestFlight.collect_data(json)
---
- :stops: "0"
:faretype: AMADEUS_PUBLISHED
:farebase: "[[\"POWA3\"]]"
:airlines: A3
:is_mixed: "0"
:roundtrip: false
:arr: SKG
:dep: ATH
require_relative '../../../models/partner'
require_relative 'global_set'
describe Partner do
it_should_behave_like "global set" do
let(:key) { 'partners' }
end
before do
Redis::List.stub(:new => stub(:unshift => nil))