Skip to content

Instantly share code, notes, and snippets.

View czj's full-sized avatar

Clément Joubert czj

View GitHub Profile
@czj
czj / Gemfile
Last active August 28, 2022 09:06
Outputting Rails app logs to Logz.io via logstash
gem "lograge"
gem "logstash-event"
gem "logstash-logger"
@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('\\')

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 / 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
@czj
czj / app_config.rb
Created May 6, 2019 14:50
Sample Rack::Attack configuration file
class AppConfig
class << self
# Lookup via
# https://www.ultratools.com/tools/ipWhoisLookupResult
# https://www.whatismyip.com/ip-whois-lookup/
BLOCKED_IPS = Set.new(
[
"6.5.4.3",
"5.4.3.2",
"4.3.2.1",
@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="[email protected]:~/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
#
# 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 [email protected]:my-org/my-repo.git
git push -u origin master
@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
@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 / array_vs_set_performance_test.rb
Created June 23, 2020 10:16
Ruby Array versus Set performance test
# frozen_string_literal: true
require "benchmark"
array = [4, 5, 6, 11, 12, 20, 40, 64, 65, 66, 81, 83].freeze
set = Set.new(array).freeze
n = 10_000_000
Benchmark.bm(7) do |x|
x.report("array found at position 0") { n.times { array.include?(4) } }