Skip to content

Instantly share code, notes, and snippets.

View tadas-s's full-sized avatar
🍍
( ⚆ _ ⚆ ) ┬───────┬

Tadas Sasnauskas tadas-s

🍍
( ⚆ _ ⚆ ) ┬───────┬
View GitHub Profile
@tadas-s
tadas-s / mysql-rename-db.sh
Created April 18, 2013 08:58
MySQL database rename script
#!/bin/bash
# Disclaimer - make backups, use at your own risk.
#
# Based on this comment: http://stackoverflow.com/a/13944924/843067
# Views and stored procedures have to be done separately.
OLDDB="old_db_name"
NEWDB="new_db_name"
MYSQL="mysql -u root -pyour_password "
@tadas-s
tadas-s / post-update
Created March 1, 2023 14:07
git post-update hook for building Rails app pushed over ssh into a bare VM
#!/usr/bin/sh
project_name="project-name-here"
project_root="${HOME}"
refname=${1}
rev=$(git rev-parse --short ${1})
this_release="${project_root}/${project_name}-${rev}"
mkdir -p ${this_release}
@tadas-s
tadas-s / database.yml
Created February 24, 2023 13:41
Simplified Rails database configuration
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
url: <%= ENV["DATABASE_URL"] %>
development:
<<: *default
test:
@tadas-s
tadas-s / rspec-single-file-scaffold.rb
Created August 6, 2020 08:38
An example of bundler's inline feature used with rspec
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile do
source 'https://rubygems.org'
gem 'rspec'
@tadas-s
tadas-s / Vagrantfile
Created October 27, 2017 12:39
Installing your personal dotfiles on each Vagrant VM you use
# Change this to suit your dotfiles setup and copy to your *HOST* machine: $HOME/.vagrant.d/Vagrantfile
Vagrant.configure(2) do |config|
# Mount your dotfiles to vagrant user's home folder (or wherever you want):
config.vm.synced_folder "#{ENV['HOME']}/dotfiles", '/home/vagrant/dotfiles'
# Install dotfiles on every 'vagrant provision' call.
# For example, let's imagine your your dotfiles have 'install.sh' script:
config.vm.provision 'shell', privileged: false, inline: '/home/vagrant/dotfiles/install.sh'
end
@tadas-s
tadas-s / gearman.md
Last active October 18, 2017 00:55
Compiling Gearman 1.1.6 + PHP module on Centos 5.9

Gearman 1.1.6 on Centos 5.9 + PHP

Please note that this is not a complete-step-by-step solution but rather a set of notes that might help to build Gearman 1.1.6 on Centos 5.9.

Some other helpful notes can be found here: http://gearman.info/build/centos5-8.html

Building Gearman

@tadas-s
tadas-s / debug_recipes.txt
Last active August 8, 2017 07:28
Debug recipes for Linux
# Quick debug network traffic between nginx and php-fpm
# Got from:
# http://systembash.com/content/simple-sysadmin-trick-using-tcpdump-to-sniff-web-server-traffic/
# Just a flow of everything looking like a string
tcpdump -nl -w - -i eth0 -c 500 port 9090 | strings
# Request heads
sudo tcpdump -nl -w - -i eth0 -c 500 port 9090 | strings | grep -E -A5 "^(GET|PUT|POST) "
# strace processes/sub-processes
@tadas-s
tadas-s / irbify.rb
Created September 12, 2013 13:46
Running local ruby scripts on remote Heroku app instance
#!/usr/bin/env ruby
#
# Usage:
# irbify.rb script.rb | heroku run rails console --app=my-app
#
# Why eval and not piping directly? Piping directly would run all lines even if previous line was an invalid statement.
#
script_name = ARGV[0]
@tadas-s
tadas-s / dirty_git.sh
Created September 5, 2013 11:13
A small bash script function to check if local git repository copy has changes. I use it for some deployment automation scripts.
#!/bin/bash
#
# Checks if git repository at $1 does not have modified files
#
function is_dirty {
GIT_DIR="$1/.git" GIT_WORK_TREE="$1" git diff --quiet
if [[ $? == 0 ]]; then
return 1
else
@tadas-s
tadas-s / gist:6316807
Last active December 21, 2015 13:59
average apache process size
# approx apache process count
ps -eLf | grep httpd | wc -l
# total and average memory stats
ps -ylC httpd --sort:rss | awk '{sum+=$8; ++n} END {print "Tot="sum"("n")";print "Avg="sum"/"n"="sum/n/1024"MB"}'