Skip to content

Instantly share code, notes, and snippets.

Siarhei Kavaliou serg-kovalev

Block or report user

Report or block serg-kovalev

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@serg-kovalev
serg-kovalev / readme.md
Created Apr 4, 2019 — forked from hone/readme.md
Private GitHub repos with Bundler on Heroku
View readme.md

Setting Up Private GitHub Repos with Bundler on Heroku

To get a private GitHub repo to work on Heroku, you can leverage the netrc buildpack in conjunction with the Heroku Ruby buildpack.

When setting up the Gemfile, make sure to use the https GitHub URL. This mechanism does not work with git+ssh.

gem "some_private_gem", git: "https://github.com/org/some_private_gem.git"
@serg-kovalev
serg-kovalev / .ebextensions_01-edit-nginx.config
Last active Aug 16, 2018
Elastic Beanstalk nginx configuration tweaks
View .ebextensions_01-edit-nginx.config
#.ebextensions/01-edit-nginx.config
container_commands:
01backup_config:
command: "cp -n /opt/elasticbeanstalk/support/conf/nginx_config.erb /opt/elasticbeanstalk/support/conf/nginx_config.erb.original"
02edit_config:
command: "sh -c \"sed '/string_to_insert_text_after/ i\
\ text_to_be_inserted;' /opt/elasticbeanstalk/support/conf/nginx_config.erb.original > /opt/elasticbeanstalk/support/conf/nginx_config.erb\""
View http_debug_server.sh
ruby -rsocket -e "trap('SIGINT') { exit }; Socket.tcp_server_loop(8080) { |s,_| puts s.readpartial(1024); puts; s.puts 'HTTP/1.1 200'; s.close }
@serg-kovalev
serg-kovalev / rspec_reset_mock.rb
Last active Nov 28, 2017
Reset Mock/Stub in RSpec
View rspec_reset_mock.rb
RSpec::Mocks.space.proxy_for(SomeClass).reset
View .vimrc
" vimrc
" Author: Zaiste! <oh@zaiste.net>
" Source: https://github.com/zaiste/vimified
"
" Have fun!
"
"
set nocompatible
filetype on
filetype off
@serg-kovalev
serg-kovalev / backup_via_email.rb
Last active Aug 29, 2015
Sending database backup in email using core ruby
View backup_via_email.rb
require 'net/smtp'
FROM = 'Some name <name@email.me>'
TO = %w(name@email.me)
SUBJ = "DB backup #{Time.now.strftime('%Y-%m-%d')}"
# find the last (in 60 mins) backup
filename = `find /path/to/backups/*.sql.gz -mmin -60`.chomp
exit if filename.nil? || filename.empty?
View extract_fixtures.rake
# -*- coding: utf-8 -*-
# DBからデータを取り出してYAMLにする。生成したYAMLはtmp/fixturesに保存される
namespace :db do
namespace :fixtures do
desc "Extract database data to tmp/fixtures directory."
task :extract => :environment do
fixtures_dir = "#{Rails.root}/tmp/fixtures/"
skip_tables = ["schema_info", "schema_migrations", "sessions"]
ActiveRecord::Base.establish_connection
FileUtils.mkdir_p(fixtures_dir)
@serg-kovalev
serg-kovalev / postgres_db_backup.sh
Created Feb 24, 2015
How to easily backup PostreSQL database. This script automatically deletes old backups
View postgres_db_backup.sh
#!/bin/bash
CURRDATE=`date +%Y_%m_%d-%H_%M`
SERVERNAME="localhost"
BAK_FILE=/path/to/backups/$SERVERNAME-production-sql-$CURRDATE.sql.gz # change the PATH here
DB_HOST="localhost"
DB_NAME="DB_NAME_HERE" # Change this
function quit {
ERROR_CODE=$1
ERROR_MSG=$2
@serg-kovalev
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: http://robots.thoughtbot.com/post/19412394597/factory-girl-hits-3-0
#
# Where to learn sed?
# http://www.grymoire.com/Unix/Sed.html#uh-6
# http://www.markhneedham.com/blog/2011/01/11/sed-across-multiple-files/
#
# What needs to change?
find . -type f -name "*.rb" -print0 | xargs -0 grep "Factory.create"
find . -type f -name "*.rb" -print0 | xargs -0 grep "Factory.build"
@serg-kovalev
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: https://gist.github.com/serg-kovalev/71af1ccd121fba7ef56e
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
PassengerMonitor.run(
: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
)
You can’t perform that action at this time.