Skip to content

Instantly share code, notes, and snippets.

View ssaunier's full-sized avatar

Sébastien Saunier ssaunier

View GitHub Profile
@thbar
thbar / maintenance.rake
Created November 28, 2013 10:10
Quick, slow, dirty way to verify how aged your gems are.
task :outdated => :environment do
include ActionView::Helpers::DateHelper
regexp = /\* ([^ ]+) \((\S+) > ([^)]+)\)/
outdated = `bundle outdated`.scan(regexp)
outdated.each do |gem_name, available, current|
data = JSON.parse(`curl --silent https://rubygems.org/api/v1/versions/#{gem_name}.json`)
version = data.find { |e| e['number'] == current }
age = distance_of_time_in_words_to_now(Time.parse(version['built_at']))
puts " * #{gem_name}: (#{available} > #{current}, built #{age} ago)"
end
@matthewlein
matthewlein / Gruntfile.js
Last active April 8, 2020 07:54
The simplest way to have grunt run a server, watch all the files for changes, and livereload on change. Set up to compile SASS and livereload the css on changes.Using the package.json, all you need to do is npm install and then it should work.
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-sass');
// don't watch node_modules
// used in watch files below
var excludes = [
'!**/node_modules/**'
@dhh
dhh / test_induced_design_damage.rb
Last active June 22, 2023 06:18
This is an extraction from Jim Weirich's "Decoupling from Rails" talk, which explained how to apply the hexagonal design pattern to make every layer of your application easily unit testable (without touching the database etc). It only seeks to extract a single method, the EmployeesController#create method, to illustrate the design damage that's …
# Original Rails controller and action
class EmployeesController < ApplicationController
def create
@employee = Employee.new(employee_params)
if @employee.save
redirect_to @employee, notice: "Employee #{@employee.name} created"
else
render :new
end
class Users::RegistrationsController < Devise::RegistrationsController
before_action :configure_permitted_parameters
# Handles editing when provider is facebook
def update_resource(resource, params)
if current_user.provider == "facebook"
params.delete("current_password")
resource.update_without_password(params)
else
resource.update_with_password(params)
@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
#
@apneadiving
apneadiving / before.rb
Last active August 29, 2015 14:07
The before is some standard code, `with_waterfall` presents another way to write it (fully chainable)
# In controller
result = TaxCalculator.new(order).call
if result[:success]
render json: { value: result[:value] }
else
render json: { errors: result[:errors] }, status: 422
end
# The service
class TaxCalculator
@ssaunier
ssaunier / db.rake
Last active January 8, 2021 11:46 — forked from abstractcoder/import.rake
Rake task to back up heroku database and restore it locally.
namespace :db do
desc "Backs up heroku database and restores it locally."
task import_from_heroku: [ :environment, :create ] do
HEROKU_APP_NAME = nil # Change this if app name is not picked up by `heroku` git remote.
c = Rails.configuration.database_configuration[Rails.env]
heroku_app_flag = HEROKU_APP_NAME ? " --app #{HEROKU_APP_NAME}" : nil
Bundler.with_clean_env do
puts "[1/4] Capturing backup on Heroku"
`heroku pg:backups capture DATABASE_URL#{heroku_app_flag}`
@ssaunier
ssaunier / heroku-checklist.md
Last active March 22, 2018 08:03
Heroku Checklist
  • Buy a domain and map a CNAME to your Heroku app. Use www.example.com, not example.com
  • Register to Uptime Robot and set up a monitor on your website (keeps dyno alive!)
  • Use Unicorn as the Webserver
  • Add the Heroku add-on PG Backups with automatic backups and monthly retention
  • Install NewRelic (provision the add-on and skip to the Ruby section)
  • Add SPF and DKIM records to your Mandrill account if you send email with @yourdomain.com
  • If your website uses Devise, buy a SSL certificate and set it up to get a https:// URL. Otherwise passwords are in cl

#cargo, docker hub without docker, how to

18 Jan 2015

###Background

I have been using linux containers for almost 2 years now. It started during an internship at Applidget, a startup in Paris. My job was to integrate linux containers technology in their private PaaS. At this time, there where no doubt, the technology to use was LXC. One week or so after I started digging into LXC, one of my co-worker talked to me about this new thing called docker. He told me "isn't it what you are supposed to do during your internship ?". And it was kind of it.

At this time I already highlighted a big challenge of containers in PaaS: creation time. Waiting for bundle install to complete is already long enough to have to wait for another 40 secondes to create a container :). Docker landed just in time !

@Papillard
Papillard / rails-kickoff.md
Last active December 1, 2021 02:07
Kick-off cheat sheet to set your Rails app @lewagon

This is a kick-off roadmap for the lead-developer, in charge of setup / deployment / collaboration.

Rails new

Create the project locally and on Github

$ rails new YOUR_APP_NAME -T --database=postgresql
$ cd YOUR_APP_NAME
$ git init