Skip to content

Instantly share code, notes, and snippets.

@duderamos
duderamos / mysql_rename_db.sh
Created June 16, 2016 00:32
Rename MySQL database
#!/bin/bash
#
# Source: http://serverfault.com/a/369430
mysqlconn="mysql -u XXX -p XXX"
olddb=XXX
newdb=XXX
table_names=$($mysqlconn -N -e "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE table_schema='${olddb}'")
@duderamos
duderamos / unicorn.service
Last active January 1, 2017 22:20
Unit file for unicorn
[Unit]
Description=Unicorn Server
Requires=redis.service
Wants=mysqld.service postgresql.service
After=redis.service mysqld.service postgresql.service
[Service]
Type=forking
User=netengine
WorkingDirectory=/var/www/unicorn/current
[Unit]
Description=Puma Server
[Service]
Type=forking
User=netengine
WorkingDirectory=/var/www/puma/current
Environment=RAILS_ENV=staging
SyslogIdentifier=puma
PIDFile=/var/www/puma/current/tmp/pids/puma.pid
# letsencrypt.service
[Unit]
Description=Renew Letsencrypt certificates
[Service]
Type=simple
ExecStart=/usr/bin/letsencrypt renew -n --no-self-upgrade
# letsencrypt.timer
[Unit]
<!DOCTYPE html>
<head>
<title>autosizing</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<style>
div { border: 1px solid #aaa; }
.w70 { width: 70%; }
.w20 { width: 20%; }
</style>
</head>
# If a second instance of this script starts, it won't run the command and exit with 1.
flock -n /tmp/.process-name.lock <long command with args here>
SELECT
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
WHERE table_schema = "$DB_NAME"
AND table_name = "$TABLE_NAME";
function (user, context, callback) {
var namespace = 'https://example.com/';
context.idToken[namespace + 'first_name'] = user.user_metadata.first_name;
context.idToken[namespace + 'last_name'] = user.user_metadata.last_name;
context.idToken[namespace + 'mobile_number'] = user.user_metadata.mobile_number;
context.idToken[namespace + 'organizations_name'] = user.user_metadata.organizations_name;
callback(null, user, context);
}
sudo ./certbot-auto certonly --manual -d 'example.com' -d '*.example.com' --agree-tos --manual-public-ip-logging-ok --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory
DB_CONTAINER="$(docker-compose ps -q pgsql-10.4)"
DB_NAME=postgres
DB_USER=postgres
LOCAL_DUMP_PATH="eeeff09c-9a4f-498a-8098-f38341fc984d.dump"
docker-compose up -d ${DB_CONTAINER}
docker exec -i "${DB_CONTAINER}" pg_restore -C --clean --no-acl --no-owner -U "${DB_USER}" -d "${DB_NAME}" < "${LOCAL_DUMP_PATH}"
docker-compose stop ${DB_CONTAINER}