Skip to content

Instantly share code, notes, and snippets.

View mezis's full-sized avatar

Julien Letessier mezis

View GitHub Profile
@mezis
mezis / git-merge-po.sh
Last active November 20, 2023 11:33
Git merge driver for PO files
#!/bin/sh
#
# *******************************************
# WARNING: this does *not* handle 3-way merges properly.
# Anything modified on the local branch since the common base will get ignored.
#
# FOR ANYONE LANDING HERE:
# This script is now updated as part of the git-whistles gem.
# https://github.com/mezis/git-whistles
# *******************************************
@mezis
mezis / query_finder.sql
Last active April 28, 2022 15:17
Finding long-running queries in MySQL
SELECT id,state,command,time,left(replace(info,'\n','<lf>'),120)
FROM information_schema.processlist
WHERE command <> 'Sleep'
AND info NOT LIKE '%PROCESSLIST%'
ORDER BY time DESC LIMIT 50;
--
-- PostgreSQL memory usage
-- Requires the pg_buffercache extension
--
SELECT
n.nspname, c.relkind, c.relname,
COUNT(1) AS buffers,
-- (100 * COUNT(1) * 8192.0 / pg_table_size(c.oid))::INT AS pct_cached,
RPAD(LPAD('', (COUNT(1) * 8192e1 / pg_table_size(c.oid))::INT, '█'), 10, '░') AS pct_cached,
@mezis
mezis / git-list-branches.sh
Created January 19, 2012 12:11
List all remote local or branches in your repo, along with colourful freshness information!
#!/bin/bash
#
# List branch status and age against an integration branch.
#
# Copyright (C) 2012 Julien Letessier
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
@mezis
mezis / git-chop.sh
Created February 9, 2012 15:16
Close a feature branch - removing it from local and remote
#!/bin/bash
#
# Close a feature branch - removing it from local and remote.
#
die() {
echo "$@" ; exit 1
}
head=$(git symbolic-ref HEAD 2> /dev/null || git log -1 --format=%h)
#!/usr/bin/env ruby
puts "Press RETURN when the geocoder cache has been unpacked in tmp/cache/geocoder"
gets
Geocoder.config[:cache] = ActiveSupport::Cache::FileStore.new('tmp/cache/geocoder')
puts "Paste the correct Google API key:"
Geocoder.config[:api_key] = gets.strip
BackfillUserCityAreaService.new.run
@mezis
mezis / results.txt
Created August 23, 2016 07:59
MessagePack, JSON, YAML, Protobuf, BSON, Marshal: Ruby 2.3.1 benchmark results
Encode
======
Date: August 22, 2016
System Information
------------------
Operating System: OS X 10.11.6 (15G31)
CPU: Intel Core i7 2.5 GHz
Processor Count:
Memory: 16 GB
class TunesFillfactor < ActiveRecord::Migration
TABLES = %w[orders restaurant_assignment order_assignment order_item driver zone_metrics]
def up
TABLES.each do |table|
execute %{ALTER TABLE #{table} SET (fillfactor = 85)}
end
end
def down
@mezis
mezis / deploy.rb.diff
Created January 21, 2014 13:23
Restart servers in a staggered manner.
diff --git i/config/deploy.rb w/config/deploy.rb
index 73fc910..594322c 100644
--- i/config/deploy.rb
+++ w/config/deploy.rb
@@ -65,7 +65,7 @@ end
desc 'restart'
deploy.task :restart, :roles => :web do
- run "touch #{current_path}/tmp/restart.txt"
+ run "bash -c 'sleep $(( $RANDOM / 100 ))' ; date ; touch #{current_path}/tmp/restart.txt"
@mezis
mezis / he
Created January 3, 2014 11:15
#!/usr/bin/env ruby
#
# Heroku wrapper
#
require 'pathname'
app_basename = Pathname.new('.').realpath.basename.to_s
head_name = %x(git symbolic-ref HEAD).strip
branch_name = head_name.gsub(%r(^refs/heads/), '')