Skip to content

Instantly share code, notes, and snippets.

View mezis's full-sized avatar

Julien Letessier mezis

View GitHub Profile
#!/usr/bin/env ruby
#
# Thread, fork, and try to trigger deadlocks
#
def make_noise
$stdout.write("\000")
end
[1,2].each do
@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;
@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/), '')
@mezis
mezis / gist:6967407
Created October 13, 2013 21:02
Rubinius 2.0.0 with RBenv + ruby-build plugin
# in ~/.rbenv/rbenv.d/rehash/rbx-2.0.0.bash
make_shims "~/.rbenv/versions/rbx-2.0.0/gems/bin/*"
# in ~/.rbenv/rbenv.d/which/rbx-2.0.0.bash
if [ ! -x "$RBENV_COMMAND_PATH" ] && [[ $RBENV_VERSION =~ rbx-2 ]]; then
export RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/gems/bin/${RBENV_COMMAND}"
fi
require 'benchmark'
number_of_rails_methods = 300
@rails = Class.new do
number_of_rails_methods.times do |i|
class_eval <<-RUBY
def call#{"%02d" % i} # def call01
end # end
RUBY
diff --git a/app/models/booking/messaging_trait.rb b/app/models/booking/messaging_trait.rb
index 7bec914..355cc0f 100644
--- a/app/models/booking/messaging_trait.rb
+++ b/app/models/booking/messaging_trait.rb
@@ -82,7 +82,7 @@ module Booking::MessagingTrait
self.host_conversation.all_messages.detect{|m| m.is_a?(Message::WithGuestBooking)}
guest_message = self.tenant_info_sheet.andand.message
- if guest_message && !created_already
+ if guest_message.present? && !created_already
diff --git a/lib/tasks/gettext_rails.rake b/lib/tasks/gettext_rails.rake
index 28da8a4..ce63757 100644
--- a/lib/tasks/gettext_rails.rake
+++ b/lib/tasks/gettext_rails.rake
@@ -3,7 +3,10 @@ namespace :gettext do
task :updatepo do
require 'gettext_rails/tools'
require 'preprocessing_erb_parser'
- GetText.update_pofiles("housetrip", Dir.glob("{app,lib,assets}/**/*.{rb,erb,rjs}").sort, "housetrip 1.0.0")
+ paths = Dir.glob("{app,lib,assets}/**/*.{rb,erb,rjs}").reject { |path|
@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)
@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