Skip to content

Instantly share code, notes, and snippets.

@pcreux
pcreux / rtt
Last active March 30, 2021 22:27
Run tests for all changed app, lib and test files
#!/usr/bin/env ruby
# Run unit test for all added or changed app, lib and test files.
# Ex:
# * `rtt` will run tests for all files changed since the last commit
# * `rtt master` will run tests for all files different from master
if ARGV[0]
files = `git diff --name-only $(git merge-base HEAD #{ARGV[0]})..$(git rev-parse --abbrev-ref HEAD)`.split("\n")
else
files = `git status -s`.split("\n").map { |f| f.split(' ').last }
@pcreux
pcreux / mktest
Created June 14, 2017 18:26
Generate a test file. `mktest app/models/user.rb` => `test/models/user_test.rb`
#!/usr/bin/env ruby
DESC = "
Generate test file
Example: mktest app/services/user/create.rb will generate test/services/user/create_test.rb
"
@pcreux
pcreux / 000_robust_rails_apps.md
Last active May 14, 2018 04:38
Robust Rails Apps - VanRuby - March 29, 2017

Robust Rails Apps

Philippe Creux - @pcreux

#vanruby - March 29th, 2017

@pcreux
pcreux / 99bottles.rb
Last active January 16, 2020 21:12
99bottles in 15 minutes. Feeling a bit dizzy now... 🍻 `git clone --depth=1 --branch=exercise https://github.com/sandimetz/99bottles.git`
class Bottles
def verse(current)
<<-VERSE
#{bottles(current).capitalize} of beer on the wall, #{bottles(current)} of beer.
#{take_one_down(current)}, #{bottles((current - 1) % 100)} of beer on the wall.
VERSE
end
def verses(start, finish)
(finish..start).to_a.reverse.map { |number| verse(number) }.join("\n")
#!/usr/bin/env ruby
require 'json'
# 1. Generate new access key
new_access_key_json = `aws iam create-access-key`
new_access_key_attributes = JSON.parse(new_access_key_json).fetch("AccessKey")
new_access_key_id = new_access_key_attributes.fetch("AccessKeyId")
@pcreux
pcreux / index.sql
Created July 5, 2016 22:52
Postgresql rank() with LIMIT 1 = 10x speed up?
CREATE INDEX "index_patrons_on_amount_raised_in_cents" ON "patrons" ("amount_raised_in_cents" DESC)
@pcreux
pcreux / data-object-with-time-parsing.rb
Last active November 6, 2015 18:59
Are data objects slow?
require 'time'
require 'virtus'
require 'benchmark/ips'
PARAMS = {
id: "123",
title: "Hello",
content: "Lorem ipsum" * 100,
created_at: Time.now.to_s,
updated_at: Time.now.to_s
@pcreux
pcreux / mkspec.rb
Last active April 26, 2016 17:51
mkspec - Generate spec file (in vim: `:!mkspec %`)
#!/usr/bin/env ruby
DESC = "
Generate spec file
Example: mkspec app/services/user/create.rb will generate spec/services/user/create_spec.rb
"
@pcreux
pcreux / dependencies.rb
Last active August 29, 2015 14:22
Generate graph of dependency for scss stylesheets
#!/usr/bin/env ruby
#
# Generate a graph of dependencies for your stylesheets.
#
# Requires graphviz
#
# Run `ruby dependencies.rb | fdp -Tpng > out.png; open out.png`
PATH = "app/assets/stylesheets/"
@pcreux
pcreux / this-week-in-rails-sample
Last active August 29, 2015 14:13
Output for latest this week in rails
---
layout: post
title: "This week in Rails: 4.2.0 Final, autoload explained, deep_munge and more!"
categories: news
author: chancancode
published: true
date: 2015-01-09 14:04:54 -0800
---
Welcome to _This week in Rails_, your weekly inside scoop of interesting commits, pull requests and more from [Rails](https://github.com/rails/rails).