Skip to content

Instantly share code, notes, and snippets.

View czj's full-sized avatar

Clément Joubert czj

View GitHub Profile
@czj
czj / rails_content_tag_vers_tag_benchmark.rb
Created June 11, 2020 13:01
Benchmarking Rails' `content_tag(:b)` vs `tag.b`
before = Process.clock_gettime(Process::CLOCK_MONOTONIC)
50_000.times { tag.span("hey") }
after = Process.clock_gettime(Process::CLOCK_MONOTONIC)
Rails.logger.debug %(tag.span("hey") } #{after - before}s)
before = Process.clock_gettime(Process::CLOCK_MONOTONIC)
50_000.times { tag.span { "hey" } }
after = Process.clock_gettime(Process::CLOCK_MONOTONIC)
Rails.logger.debug %(tag.span { "hey" } } #{after - before}s)
@czj
czj / gist:1251031
Created September 29, 2011 15:43
.irbrc that runs Pry instead of IRB
# This script comes from Pry Everywhere by Luca Pette
# http://lucapette.com/pry/pry-everywhere/
# https://github.com/carlhuda/bundler/issues/183#issuecomment-1149953
if defined?(::Bundler)
global_gemset = ENV['GEM_PATH'].split(':').grep(/ruby.*@global/).first
if global_gemset
all_global_gem_paths = Dir.glob("#{global_gemset}/gems/*")
all_global_gem_paths.each do |p|
gem_path = "#{p}/lib"
@czj
czj / ruby-benchmark-env.key-or-env.bracket.rb
Created July 1, 2019 16:04
Why is faster : ENV["key"] or ENV.key?("key") ? The answer will surprise you ...
require "benchmark/ips"
HASH = ("a".."zz").to_a.shuffle.to_h { |e| [e, "#{e}#{e}#{e}"] }
KEY = "zz"
def key_fast
HASH.key? KEY
end
def key_slow
# Rewrite all commits without a certain directory
java -jar ~/Downloads/bfg-1.13.0.jar --delete-folders "vcr_cassettes"
# Remove garbage
git reflog expire --expire=now --all && git gc --prune=now --aggressive
# Push to your repo
git remote add origin git@github.com:my-org/my-repo.git
git push -u origin master
@czj
czj / download_attachments.sb
Created May 13, 2019 12:51
Download a Rails application's production attachements to your local machine
#!/usr/bin/env bash
APP_HOME=$( cd ${0%/*} && pwd -P )"/.."
REMOTE_SHARED="railsapp@host.domain.net:~/www/railsapp/shared"
SPEED_LIMIT=""
# Un-comment this line if you want to limit the download speed to un-clog your connexion
# SPEED_LIMIT="--bwlimit=500"
# -l forces copy of symlinks
#
@czj
czj / config.yml
Created May 6, 2019 13:42
Circle CI 2.1 configuration step for Ruby / Rails / Redis / Postgres workflow with tests + system tests running in parallel
# Ruby CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
#
version: 2.1
executors:
my-executor:
docker:
# Main image to be used within this configuration

Keybase proof

I hereby claim:

  • I am czj on github.
  • I am czj (https://keybase.io/czj) on keybase.
  • I have a public key ASA-7J6_QjVmXe6nnNopADEypiIhM1vH2gbdW1hnns-hzAo

To claim this, I am signing this object:

@czj
czj / ydl.sh
Last active September 11, 2018 16:20
Download any YouTube video, channel or playlist using youtube-dl
#!/usr/bin/env bash
# Download a file from a given url
if [ -z "$1" ]; then
echo "Download a video."
echo "Usage: ydl \"url\""
else
youtube-dl --get-filename -o '%(title)s.%(ext)s' --restrict-filenames --yes-playlist --no-mark-watched --all-formats -f 'best[ext=mp4]/best' "$1"
fi
@czj
czj / log_work_to_slack.rb
Created August 4, 2018 09:19
Work log output to local file + to Slack
#!/usr/bin/env ruby
require "bundler/inline"
gemfile { gem "slack-notifier" }
require "slack-notifier"
Slack::Notifier.new("https://hooks.slack.com/services/xxxxxxx").ping("• _#{query}_")
logs_dir = "~/Documents/work_logs"
query = ARGV[0].to_s.delete('\\')
@czj
czj / fake_name_generator.rb
Created June 9, 2018 19:44
Fake name generator (french/France)
#!/usr/bin/env ruby
require "json"
1000.times do
json = `curl --silent --insecure "https://api.namefake.com/french-france/random/"`
data = JSON.parse(json)
puts data["name"]
end