Skip to content

Instantly share code, notes, and snippets.

Adrien Rey-Jarthon jarthod

Block or report user

Report or block jarthod

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jarthod
jarthod / mongo-hang-monitoring.rb
Created Nov 8, 2019
Ruby script which tries to detect when mongo is up but super slow (for example due to IO issue) and stop it to allow fallback to secondary
View mongo-hang-monitoring.rb
#!/usr/bin/env ruby
# Tries to detect when mongo is up but super slow (ex: IO issue)
THRESHOLD = 20_000 # ms
def test_mongo tries: 5
out = `echo -e "db.isMaster()\ndb.getReplicationInfo()" | mongo mongodb://localhost/?socketTimeoutMS=#{THRESHOLD} 2>&1`
res = $?
if res != 0 && !out['Connection refused']
@jarthod
jarthod / process_semaphore.rb
Created Apr 17, 2019
Provides a system wide file lock to ensure no more than X process is running at the same time.
View process_semaphore.rb
#!/usr/bin/env ruby
# Provides a system wide file lock to ensure no more
# than X process is running at the same time.
# Example:
#
# process_semaphore!({
# prefix: "/tmp/my_process",
# limit: 2
@jarthod
jarthod / compressed.rb
Last active Feb 23, 2019 — forked from romanbsd/compressed.rb
Compressed fields in Mongoid 6.4
View compressed.rb
require 'zlib'
class CompressedString < String
def mongoize
BSON::Binary.new(Zlib::Deflate.deflate(self))
end
class << self
# Get the object as it was stored in the database, and instantiate
# this custom class from it.
@jarthod
jarthod / set_nf_conntrack_max.sh
Created Oct 16, 2016
Fix synology DS414 nf_conntrack: table full issue
View set_nf_conntrack_max.sh
echo 500000 | sudo tee /proc/sys/net/netfilter/nf_conntrack_max
@jarthod
jarthod / server_benchmark.md
Last active Jul 27, 2019
Server benchmark
View server_benchmark.md

Results

Server Price* CPU (1 thread) CPU (4 threads) IO
Scaleway Start1-XS
Atom C3955, 25G NVMe
$4 21 sec
P₉₅ = 2.1ms
21 sec
P₉₅ = 14ms
🚗 653 IO/s, 10 Mb/sec
P₉₅ = 0.40ms
Scaleway VC1-S
Atom C2750, 50G SSD
$4 46 sec ⚠️
P₉₅ = 4.6ms
23 sec
P₉₅ = 14ms
🚲 289 IO/s, 4.5 Mb/sec
P₉₅ = 0.39ms
AWS t2.micro 1G
Intel E5-2676 v3 2.4GHz, EBS
$6 29 sec
P₉₅ = 3.1ms
29 sec
P₉₅ = 15ms
🚤 1150 IO/s, 17 Mb/sec
P₉₅ = 1.01ms
Digital Ocean 1G
Xeon E5-2650, 25G SSD
$6 31 sec
P₉₅ = 3ms
31 sec
P₉₅ = 19ms
✈️ 3412 IO/s, 53 Mb/sec
P₉₅ = 0.52ms
OVH VPS SSD2
Xeon E3-12xx, 20G SSD
@jarthod
jarthod / application_helper.rb
Last active Feb 14, 2016
Rails helper to render time using client's browser locale
View application_helper.rb
# Use this in place of `time_tag`
# Ex: <%= local_time_tag user.created_at %>
def local_time_tag time, opts = {}
opts[:data] = (opts[:data] || {}).merge format: 'local'
opts[:title] ||= time
time_tag(time, opts) + content_tag(:script, raw(<<-JAVASCRIPT))
var nodes = document.querySelectorAll('time[data-format=local]');
if (nodes.length > 0) {
var elem = nodes[nodes.length - 1];
@jarthod
jarthod / deploy.rb
Created Sep 20, 2015
Capistrano local assets compile
View deploy.rb
# Rewrite precompile tasks to do it locally
Rake::Task["deploy:compile_assets"].clear
task :compile_assets => [:set_rails_env] do
# invoke 'deploy:assets:precompile'
invoke 'deploy:assets:precompile_local'
invoke 'deploy:assets:backup_manifest'
end
namespace :assets do
task :precompile_local do
@jarthod
jarthod / git_cleanup.rb
Last active Aug 29, 2015
Ruby script to cleanup large files from your git repository
View git_cleanup.rb
#!/usr/bin/env ruby
# Ruby shows you the largest objects in your git repo's pack file & offers you to remove them automatically
# Based on http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/ by Antony Stubbs
# Use this to fetch all branches locally first:
# for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do
# git branch --track ${branch##*/} $branch
# done
@jarthod
jarthod / ffmpeg_cheat_sheet.md
Last active Jun 30, 2019
ffmpeg cheat sheet
View ffmpeg_cheat_sheet.md

base encode to H265 (HEVC)

ffmpeg -i in.mts -c:a copy -c:v libx265 out.mp4

base encode to H264

ffmpeg -i in.mts -c:a copy -c:v h264 out.mp4

scale to 720p

You can’t perform that action at this time.