Skip to content

Instantly share code, notes, and snippets.


Siarhei Kavaliou serg-kovalev

View GitHub Profile
serg-kovalev / gist:8487870b128b093721e4
Last active Aug 29, 2015 — forked from mikegrassotti/gist:2247065
FactoryGirl upgrade from version 2.* to 3.*
View gist:8487870b128b093721e4
# FactoryGirl3ForYouAndMe
# The new syntax:
# Where to learn sed?
# What needs to change?
find . -type f -name "*.rb" -print0 | xargs -0 grep "Factory.create"
find . -type f -name "*.rb" -print0 | xargs -0 grep ""
serg-kovalev / script_passenger_monitor.rb
Created Aug 1, 2014
Monitor your Phusion passenger instances. This script allows you to automatically gracefully reload passenger instances (if they ate too much memory). See the required library:
View script_passenger_monitor.rb
#!/usr/bin/env ruby
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'passenger_monitor'))
# Set logger to log into Rails project /log directory and start monitoring
:log_file => File.join(File.dirname(__FILE__), '..', 'log', 'passenger_monitor.log'),
:memory_limit => 400, # this is in MB
:wait_time => 10, # this in seconds (timeout before attempts)
:attempts => 5 # number of attempts
serg-kovalev / lib_passenger_monitor.rb
Last active Aug 29, 2015
Phusion Passenger Monitor library: it allows you to automatically gracefully kill/reload passenger instances, the end user will not see any errors. See another gist that shows how to use it:
View lib_passenger_monitor.rb
# Finds bloating passengers and try to kill them gracefully.
# @example:
require 'logger'
class PassengerMonitor
# How much memory (MB) single Passenger instance can use
# Log file name
DEFAULT_LOG_FILE = 'passenger_monitoring.log'
serg-kovalev /
Created Aug 1, 2014
How to upgrade PostgreSQL server from 8.4 to 9.1 or above
sudo add-apt-repository ppa:pitti/postgresql
sudo apt-get update
# stop apache server if you need
# sudo /etc/init.d/apache2 stop
sudo -i -u postgres
pg_dumpall > dumpall_$(date +"%Y%m%d").pgdump
sudo mv /var/lib/postgresql/dumpall_$(date +"%Y%m%d").pgdump ~/
sudo cp -r /etc/postgresql/8.4 /etc/postgresql/old
sudo apt-get install postgresql-9.1 -y
serg-kovalev /
Last active Aug 29, 2015
This shell script checks if process exists and removes pid file if not. I use this script with monit to be sure that process exist before killing it
#!/usr/bin/env bash
# the first argument should be a path to pid file
if [[ -f "$1" ]] ; then
if [ $(ps -p $(cat $1) | wc -l) -gt 1 ] ; then
# process exists - do nothing
#echo "OK"
exit 0
#echo "will do rm $1"
rm $1
serg-kovalev /
Last active Aug 29, 2015
RVM wrapper that loads needed environment in CRON tasks
#!/usr/bin/env bash
# usage
# rvm_env_wrapper /path/to/project some_ruby_file.rb
# rvm_env_wrapper /path/to/project some_comand arg1 arg2 arg3 etc
# OR
# rvm_env_wrapper --use ruby_version@gemset_name some_comand_or_file
# Permissions:
# sudo chown user:group rvm_env_wrapper
# sudo chmod 774 rvm_env_wrapper
View gist:1ed5ba2cff523eef67bf

Sublime Text 2 – Useful Shortcuts (Ubuntu)


Ctrl+KB toggle side bar
Ctrl+Shift+P command palette
Ctrl+` python console
Ctrl+N new file