Skip to content

Instantly share code, notes, and snippets.

View gacha's full-sized avatar

Gatis Tomsons gacha

View GitHub Profile
@gacha
gacha / elasticsearch.monit
Created November 7, 2012 10:33
Elasticsearch monit
check process elasticsearch with pidfile /var/run/elasticsearch.pid
start program = "/etc/init.d/elasticsearch start"
stop program = "/etc/init.d/elasticsearch stop"
if 5 restarts within 5 cycles then timeout
if failed host 127.0.0.1 port 9200 type http then restart
@gacha
gacha / resque.monit
Created November 7, 2012 11:45
Resque monit config with passanger
check process resque-worker-production
with pidfile /home/webmaster/production/shared/pids/resque_worker.pid
start program = "/usr/bin/env HOME=/home/webmaster PATH=/usr/local/bin:/usr/local/ruby/bin:/usr/bin:/bin:$PATH /bin/sh -l -c 'cd /home/webmaster/production/current; nohup bundle exec rake environment resque:work RAILS_ENV=production PIDFILE=/home/webmaster/production/shared/pids/resque_worker.pid >> log/resque_worker.log 2>&1'" as uid webmaster and gid webmaster
stop program = "/bin/sh -c 'cd /home/webmaster/production/current && kill $(cat /home/webmaster/production/shared/pids/resque_worker.pid) && rm -f /home/webmaster/production/shared/pids/resque_worker.pid; exit 0;'"
if totalmem is greater than 300 MB for 10 cycles then
exec "/bin/kill -9 $(cat /home/webmaster/production/shared/pids/resque_worker.pid) && rm -f /home/webmaster/production/shared/pids/resque_worker.pid"
if 5 restarts within 5 cycles then timeout
group resque_workers
check process resque-worker-staging
#!/usr/bin/env bash
apt-get -y update
apt-get -y upgrade
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-gplv2-dev libyaml-dev libffi-dev
apt-get -y install autoconf curl git-core bzip2
apt-get -y autoremove
apt-get -y clean
cd /usr/local/src
wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz
tar -xvzf ruby-2.0.0-p247.tar.gz
@gacha
gacha / puma.rb
Last active March 13, 2017 21:49
puma config for rails
rails_env = ENV['RAILS_ENV'] || 'development'
rails_root = File.expand_path("../", File.dirname(__FILE__))
# threads
threads 0,1
# workers
case rails_env
when 'staging'
workers 1
@gacha
gacha / nginx-proxy
Last active December 21, 2015 08:29
location @web {
proxy_redirect off;
proxy_set_header X-FORWARDED_PROTO http;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://web;
}
@gacha
gacha / secret-santa.rb
Last active December 8, 2021 00:34
Secret santa script for christmas
#!/usr/bin/env ruby
require 'timeout'
members = %w(Gatis Jānis Anna Ilze Ieva Kaspars Juris Klāvs Pēteris)
takers = []
givers = []
exceptions = { 'Gatis' => 'Jānis'}
begin
Timeout::timeout(2) do
@gacha
gacha / stop-screensaver
Created December 20, 2014 19:59
Stop screensaver on linux
#!/bin/sh
export DISPLAY=:0.0
xset s off
xset s noblank
xset -dpms
(2..5).reduce(1){|m,o|y=10**o;m*((1..y).to_a.join[y-1].to_i)}
@gacha
gacha / remove_encoding.sh
Created October 5, 2015 20:06
Remove old ruby encoding comment
find ./ -name *.rb | xargs -I{} ruby -i -ne 'print unless /^#\s?encoding:\s?utf-8/i' {}

PostgreSQL setup

To use lv_LV.UTF-8 locale your unix system should have it, check it:

$ locale -a

If it's not here, then on linux as root uncomment it in /etc/locale.gen and run locale-gen. Then restart PostgreSQL server.

Open postgres shell: