Skip to content

Instantly share code, notes, and snippets.

@pcreux
pcreux / railsmv.rb
Last active June 14, 2017 18:27
railsmv - Rename rails services, models etc - railsmv app/services/create_user.rb app/services/user/create.rb
#!/usr/bin/env ruby
#
# Rename rails services, models etc as well as their test or spec files!
#
# Example: railsmv app/services/create_user.rb app/services/user/create.rb
#
require 'optparse'
dry_run = false
@pcreux
pcreux / size.rb
Last active May 11, 2020 21:27
Sizes - Use ruby's comparable to compare clothe's sizes (XS, S, M, L, XL, etc)
class Size
include Comparable
def initialize(str)
unless ALL_STRS.include? str
raise ArgumentError, "#{str} is not a valid size"
end
@str = str
end
@pcreux
pcreux / pipable.rb
Last active June 12, 2018 17:08
*nix has pipes, Elixir has pipes, Ruby deserves pipes.
# Elixir has pipes `|>`. Let's try to implement those in Ruby.
#
# I want to write this:
#
# email.body | RemoveSignature | HighlightMentions | :html_safe
#
# instead of:
#
# HighlightMentions.call(RemoveSignature.call(email.body)).html_safe
#
require 'virtus'
class User
include Virtus.model
attribute :confirmed_at, Time
attribute :subscribed, Boolean, default: false
end
class Screencast
@pcreux
pcreux / 000_postgresql_fancy_datatypes
Last active March 18, 2022 16:51
Postgresql fancy datatypes with Rails / ActiveRecord. Run it with `rake`!
# Postgresql fancy datatypes!
* array
* hstore (=~ hash)
* json
* jsonb
Philippe Creux - [@pcreux](http://twitter.com/pcreux)
@pcreux
pcreux / postgres-is-not-happy.md
Created May 1, 2014 22:49
Repair postgres (homebrew) after a system crash

When my mac crashes and Postgres doesn't boot properly I see the following errors in /usr/local/var/postgres/server.log

FATAL:  lock file "postmaster.pid" already exists

# and / or

lock file "/var/pgsql_socket/.s.PGSQL.5432.lock" already exists

Here are the commands to put Postgres back on track:

@pcreux
pcreux / 0-gourmet-service-objects.md
Last active August 21, 2022 15:32
Gourmet Service Objects - Lightning Talk - http://vanruby.org - Feb 27, 2014

Gourmet Service objects

 @pcreux

 Feb 27, 2014
 http://vanruby.org
@pcreux
pcreux / import-sepa-mandates-to-ca.rb
Last active August 29, 2015 13:56
Hack to import SEPA mandates from a CSV file to the Crédit Agricole bank. Fun times...
#encoding: utf-8
# This HACK imports SEPA Mandates from a CSV file to
# Crédit Agricole SEPA System via their HTML API. :)
#
# Good luck with this!
#
require 'mechanize'
require 'virtus'
@pcreux
pcreux / postgresql.conf
Last active August 29, 2015 13:56
Speed up Rails test suite!
fsync = off
synchronous_commit = off
full_page_writes = off
" Quick cycling between windows
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" cycle between quickfix entries
map <C-n> :cn<CR>
map <C-p> :cp<CR>