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
@duderamos
duderamos / delayed_job.service
Created January 1, 2017 19:38
Systemd unit file for delayed_job
[Unit]
Description=delayed_job
After=syslog.target
After=postgresql.service
[Service]
Type=forking
User=netengine
Environment=RAILS_ENV=production
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

MySQL commands

  • Show table collation from a database:
show table status from <database>;
  • Show collation from an entire database;
# 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);
}