Skip to content

Instantly share code, notes, and snippets.

@Ptico
Ptico / gems.rb
Created October 6, 2015 14:42
My default rails gemfile
source 'https://rubygems.org'
BUNDLE_RAILS_VERSION = '~> 4.2.4'
# Rails
gem 'railties', BUNDLE_RAILS_VERSION
gem 'activesupport', BUNDLE_RAILS_VERSION
gem 'actionpack', BUNDLE_RAILS_VERSION
gem 'actionmailer', BUNDLE_RAILS_VERSION
gem 'activejob', BUNDLE_RAILS_VERSION
@Ptico
Ptico / basic.sql
Created December 13, 2019 16:50 — forked from nesquena/basic.sql
PostgreSQL Common Utility Queries
/* How to calculate postgreSQL database size in disk ? */
SELECT pg_size_pretty(pg_database_size('thedbname'));
/* Calculate size of a table including or excluding the index */
SELECT pg_size_pretty(pg_total_relation_size('big_table'));
SELECT pg_size_pretty(pg_relation_size('big_table')); /* without index */
/* See indexes on a table with `\d tablename` */
require 'benchmark'
require 'benchmark/ips'
require 'benchmark/memory'
require 'faker'
class Bench
attr_reader :benchmarks
attr_accessor :bmbm_iters
@Ptico
Ptico / problem.rb
Last active October 22, 2019 13:29
dry-schema partial
AddressSchema = Dry::Schema.Params do
required(:street).filled(:string)
required(:city).filled(:string)
required(:zipcode).filled(:string)
required(:email).filled(:string)
end
# ...
# CREATE { street: 'Baker Street', city: 'London', zipcode: 'NW1/W1', email: 'sherlock@holmes.co.uk' }
@Ptico
Ptico / shoulda_am.rb
Created September 22, 2011 12:41
Shoulda activemodel matchers cheatsheet
# Shoulda activemodel cheatsheet
# DB
should have_db_column(:title).of_type(:string).with_options(default: 'Untitled', null: false)
should have_db_index(:email).unique(:true)
# Associations
should belong_to :company
should have_one(:profile).dependent(:destroy)
should have_many(:posts).dependent(:nullify)
class Parts
def initialize(parts)
@parts = parts
end
def join(part_divider, word_divider='')
@parts.map do |word|
word.join(word_divider)
end.join(part_divider)
end
@Ptico
Ptico / .babelrc
Last active June 22, 2016 12:49
Hanami gulp assets with digests
{
"plugins":
[
"transform-undefined-to-void",
"transform-es2015-arrow-functions",
"transform-es2015-block-scoping",
"transform-es2015-block-scoped-functions",
"transform-es2015-constants",
"transform-es2015-destructuring",
"transform-es2015-parameters",

Keybase proof

I hereby claim:

  • I am ptico on github.
  • I am ptico (https://keybase.io/ptico) on keybase.
  • I have a public key ASD84JPGkyH33x0DJUEohQ0xz_lTuCLfGUu9cIAdS9XoIgo

To claim this, I am signing this object:

#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten

URI templates

URI template syntax

But we have RFC6570, why another one?

Current implementation have more questions than answers:

  1. It describes only template expansion, not matching. While URI matching is more common task (routing) - any template standard which doesn't describe matching will fail
  2. The RFC6570 modifiers sometimes is pointless and create more pain than gain for developers