Skip to content

Instantly share code, notes, and snippets.

View colinmollenhour's full-sized avatar

Colin Mollenhour colinmollenhour

View GitHub Profile
@colinmollenhour
colinmollenhour / mongobackup.sh
Created July 30, 2013 21:53
Simple daily dump of mongo databases.
#!/bin/bash
cd /media/dumps
name=$(date +%b-%d)
year=$(date +%Y)
[ -d $year ] || mkdir $year || { echo "Could not create directory '$year'"; exit 1; }
mongodump --db t3_mage --out $name &> mongodump.log
if [ $? ]; then
tar -czf snapshots/$year/$name.tgz $name
if [ $(($(date +%d | sed 's/^0*//') % 10)) == 0 ]; then
@colinmollenhour
colinmollenhour / tunnlr.sh
Created February 8, 2014 00:01
Easily configure and launch your Tunnlr.com SSH tunnel!
#!/bin/bash
#
# A simple function for starting an SSH tunnel (e.g. tunnlr.com)
#
# Add the function to your .bashrc file or use this script standalone
# Takes port to forward to as only parameter
function tunnlr(){
[ -z $1 ] && { echo "You must specify a port to forward to."; return 1; }
if [ -f ~/.tunnlr ]; then
@colinmollenhour
colinmollenhour / tags.php
Last active August 29, 2015 13:56
Test browser performance of using 100 inline script tags with domReadyQueue vs 1 inline script tag.
<?php /* http://screencast.com/t/rFhmw1S2zsh */ ?>
<!DOCTYPE html>
<html>
<head><title>Script Block Test</title></head>
<body>
<?php if (isset($_GET['mode']) && $_GET['mode'] == 'inline'): ?>
<script type="text/javascript">
var domReadyQueue = [];
@colinmollenhour
colinmollenhour / sc-install.sh
Created April 6, 2014 02:57
Install StarCluster on Windows
#!/bin/bash
#
# Requires Python 2.7 64-bit
# Run using Git Bash program from "Git for Windows"
[ -d /c/Python27 ] || {
echo "Oops, I expected Python 2.7 to be installed at C:\Python27";
exit 1;
}
cd /c/Python27/
#!/bin/bash
#
# Store/update the DNS entry locally. Requires unbound install as a local DNS resolver
# and a cron job that runs this script.
#
# Copyright: Colin Mollenhour 2014
#
# Recommended DNS servers for querying:
# OpenDNS: 208.67.222.222 and 208.67.220.220
# Google: 8.8.8.8 and 8.8.4.4
@colinmollenhour
colinmollenhour / log_deadlocks.sh
Last active December 4, 2018 20:51
Record all new deadlocks in separate files
#!/bin/bash
#
# Copyright Colin Mollenhour 2014
dir=/root/deadlocks
[ -d $dir ] || mkdir -p $dir
cd $dir || { echo "Could not cd to $dir"; exit 1; }
mysql -be 'show engine innodb status;' \
| sed 's/\\n/\n/g' \
@colinmollenhour
colinmollenhour / mysqlsnapshot.sh
Last active May 16, 2021 13:32
MySQL Snapshot Script
#!/bin/bash
DBNAME=mydb
SNAPSHOT_DAYS=2
ARCHIVE_DAYS=0
COMPRESS_INPLACE=1
mysqldump='docker exec mysql_mysql_1 mysqldump'
gzip=/bin/gzip
@colinmollenhour
colinmollenhour / Config.php
Last active April 22, 2020 09:45
Stampede-resistant Config Cache
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
@colinmollenhour
colinmollenhour / nginx_error_log
Last active September 10, 2016 15:30
Munin Plugin - nginx error_log
#!/bin/bash
: <<=cut
=head1 NAME
nginx error log - Munin plugin to monitor nginx error_log rates (debug, info, notice, warn, error, crit, alert, emerg).
=head1 APPLICABLE SYSTEMS
Any Linux host, running nginx, with bash version > 4.0
@colinmollenhour
colinmollenhour / server.js
Last active May 9, 2018 16:00
Delays spooling of unrecognized domains (designed for SmarterMail)
/**
* Watch the spool, delay processing of emails from unrecognized domain names.
*
* Installation:
* npm install nedb
* npm install node-windows
* node server.js --install {spool_dir}
* net start SpamDelayer
*
* @Author Colin Mollenhour