Skip to content

Instantly share code, notes, and snippets.

@sharshenov
sharshenov / gist:33c0dd55c838ecd5762c
Created November 16, 2015 11:16
Rails middleware for health check endpoint
class HealthCheckResponder
def initialize(app, options = {})
@app = app
end
def call(env)
if env["REQUEST_PATH"] == "/health_check"
return [200, {}, [""]]
else
@sharshenov
sharshenov / 404.html
Created August 20, 2015 09:49
Page not found for RoR
<h1>Page not found</h1>
@sharshenov
sharshenov / .env.production
Created August 20, 2015 06:00
capistrano + foreman deploy for RubyOnRails
SECRET_KEY_BASE=ahsbdjhasbjhdabks # run rake:secret to generate
DATABASE_URL=postgres://user:pass@dbhost/database
@sharshenov
sharshenov / clear_logs.sh
Last active August 31, 2016 09:12
Cleanup log files
#!/bin/bash
cd ~/ror
# remove temporary uploads
find ./ -path "*/uploads/tmp/*" -delete
# null logfiles
for logfile in `find ./ -type f -name "*.log"`
do
@sharshenov
sharshenov / backup_standby.sh
Last active May 20, 2024 08:50
Making PostgreSQL backup from standby server
# 1. Pause replication
sudo -u postgres psql -c 'SELECT pg_xlog_replay_pause();'
# 2. Perform backup
sudo -u postgres pg_dump -Fc DBNAME > /path/to/backup
#3. Resume replication
@sharshenov
sharshenov / gist:a414add41a3bcc219c6e
Created March 24, 2015 07:12
Fix sublimetext closing on Ctrl+W
1. Select Preferences / Key Bindings(user)
2. Paste this:
```json
[
{ "keys": ["ctrl+w"], "command": "close_file" },
]
```
@sharshenov
sharshenov / gist:b494474ae3a0685f6a2f
Created March 22, 2015 06:23
Set postgresql template1 default charset to UTF-8
# open console as postgres user
sudo -u postgres psql
# paste this
update pg_database set datistemplate = FALSE where datname = 'template1';
drop database template1;
create database template1 with owner=postgres encoding='UTF-8' lc_collate='en_US.utf8' lc_ctype='en_US.utf8' template template0;
update pg_database set datistemplate = TRUE where datname = 'template1';

Keybase proof

I hereby claim:

  • I am sharshenov on github.
  • I am sharshenov (https://keybase.io/sharshenov) on keybase.
  • I have a public key whose fingerprint is ED36 8D30 17B6 39F8 B58E 1E7D EDF0 0A21 B208 D134

To claim this, I am signing this object:

@sharshenov
sharshenov / gist:a34db47c2311acd38c92
Last active June 13, 2016 04:24
add swapfile to ubuntu host
#Original article: https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-12-04
dd if=/dev/zero of=/swapfile bs=1M count=1k
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0 ' >> /etc/fstab
echo 1 | tee /proc/sys/vm/swappiness
echo vm.swappiness = 1 | tee -a /etc/sysctl.conf
chown root:root /swapfile
chmod 0600 /swapfile
@sharshenov
sharshenov / gist:b8371f4ea4f09318415d
Last active August 29, 2015 14:06
Logrotate template for rails apps
# save as /etc/logrotate.d/APPNAME
/home/deploy/apps/APPNAME/shared/log/*.log {
su deploy deploy
daily
missingok
rotate 30
compress
delaycompress
notifempty
copytruncate