Skip to content

Instantly share code, notes, and snippets.

View ssaunier's full-sized avatar

Sébastien Saunier ssaunier

View GitHub Profile
[
{
"name": "Charm at the Steps of the Sacre Coeur/Montmartre",
"imageUrl": "https://raw.githubusercontent.com/lewagon/flats-boilerplate/master/images/flat1.jpg",
"price": 164,
"priceCurrency": "EUR",
"lat": 48.884211,
"lng": 2.346890
},
{
# Usage: run `ruby buddies.rb`
begin
require "round_robin_tournament"
rescue LoadError
puts "Could not find gem 'round_robin_tournament'"
puts "Install it with:"
puts
puts " gem install round_robin_tournament"
exit 1
@ssaunier
ssaunier / README.md
Created September 6, 2017 13:22
Quick caching in Rails (backed by Redis, with Heroku Redis Cloud add-on)

Add this line to your Gemfile and run bundle install

# Gemfile
gem "redis"

Create a new initializer to have a global $redis variable at hand:

@ssaunier
ssaunier / README.md
Last active December 17, 2019 12:45
Use ES6 in your Rails Asset Pipeline

Rails 5.1 introduces a new way of coding JavaScript. You would use yarn, webpack and a new folder, app/javascript.

Setup

If you want to stick with the "old" way (before 5.1) and use the asset pipeline, you need to do this:

# Gemfile

gem 'sprockets', '>= 3.0.0'
@ssaunier
ssaunier / README.md
Last active July 17, 2018 01:26
Add healthchecks.io to your Rails / Sidekiq project

Depends on the sidekiq-cron gem.

curl https://gist.githubusercontent.com/ssaunier/e2d488bb931b5dc8df0f329c652eac25/raw/health_check_job.rb > app/jobs/health_check_job.rb

You need to set HEALTH_CHECK_URL in the prod ENV.

$ rails s [2.3.1]
=> Booting Puma
=> Rails 5.0.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
/usr/local/Cellar/rbenv/1.1.0/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.9/lib/sidekiq/version.rb:3: warning: already initialized constant Sidekiq::VERSION
/usr/local/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.9/lib/sidekiq/version.rb:3: warning: previous definition of VERSION was here
/usr/local/Cellar/rbenv/1.1.0/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.9/lib/sidekiq/logging.rb:10: warning: already initialized constant Sidekiq::Logging::Pretty::SPACE
/usr/local/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.9/lib/sidekiq/logging.rb:10: warning: previous definition of SPACE was here
/usr/local/Cellar/rbenv/1.1.0/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.9/lib
@ssaunier
ssaunier / subl_add.md
Last active August 4, 2017 14:21
Add a new folder to Sublime current project window, from the command line. (same as Project > Add folder to project)

First check you have sublime as a oh-my-zsh plugin:

$ cat ~/.zshrc | grep plugins=
plugins=(gitfast rbenv last-working-dir common-aliases sublime zsh-syntax-highlighting history-substring-search)
# 👆 that's mine

Restart your terminal.

<!DOCTYPE html>
<html>
<head>
<!-- [...] -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="css/navbar.css">
<link rel="stylesheet" href="css/banner.css">
<link rel="stylesheet" href="css/footer.css">
<link rel="stylesheet" href="css/blog.css">
<link rel="stylesheet" href="css/product.css">
@ssaunier
ssaunier / webpack.config.js
Last active July 11, 2022 12:06
Basic webpack boilerplate
// Webpack 5 default configuration
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
module.exports = {
mode: 'development',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, './dist'),
@ssaunier
ssaunier / cache.rb
Created November 29, 2016 16:33
A simple redis-backed cache to put in your `app/services` Rails app.
module Cache
def from_cache(*args, &block)
return yield(self) if ENV['DISABLE_CACHE'] == 'true'
expire = default_expire
if args.last.is_a?(Hash)
options = args.pop
expire = options.fetch(:expire, expire)
end
the_key = key(*args)