Skip to content

Instantly share code, notes, and snippets.

View gacha's full-sized avatar

Gatis Tomsons gacha

View GitHub Profile
@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 / 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 / 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
#!/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 / 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
@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 / tinymce_fill_in.rb
Created November 1, 2012 19:23
Fill in text into tinymce for capybara, using native input for selenium and JS for other
# used as example https://groups.google.com/d/msg/ruby-capybara/XhDAHGjZSjA/VwiW0-2nOIEJ
# IMPORTANT! To do the real simulation you need chrome driver - http://code.google.com/p/selenium/downloads/list, download and add to PATH
def tinymce_fill_in name, options = {}
if page.driver.browser.browser == :chrome
page.driver.browser.switch_to.frame("#{name}_ifr")
page.find(:css, '#tinymce').native.send_keys(options[:with])
page.driver.browser.switch_to.default_content
else
page.execute_script("tinyMCE.get('#{name}').setContent('#{options[:with]}')")
end
@gacha
gacha / mute.rb
Created September 4, 2012 14:46
Mute ruby output block
# Example
# mute do
# puts "Foo"
# end
# puts "Bar"
#
# Only Bar will be printed
def mute &block
orig_stdout = $stdout
$stdout = File.new('/dev/null', 'w')
@gacha
gacha / merger.rb
Created August 24, 2012 06:53
Merge rails i18n YAML files
# LOAD RAILS ENV ...
def returning(value)
yield(value)
value
end
def convert_hash_to_ordered_hash_and_sort(object, deep = false)
# from http://seb.box.re/2010/1/15/deep-hash-ordering-with-ruby-1-8/
if object.is_a?(Hash)
@gacha
gacha / colorbox_fix.js
Created May 4, 2011 18:08
Colorbox title for long lines
$(document).bind('cbox_complete', function(){
$("#cboxTitle").hide();
$("<div>"+$("#cboxTitle").html()+"</div>").css({color: $("#cboxTitle").css('color')}).insertAfter(".cboxPhoto");
$.fn.colorbox.resize();
});