Skip to content

Instantly share code, notes, and snippets.

@yevrah
yevrah / db-user-setup.sh
Created March 19, 2015 00:34
MySQL: User Setup Script
#!/bin/bash
# Create db - if it doesnt exist, and setup user ready to
# read and write
#
# Usage: db-user-setup.sh <database> <user> <password>
EXPECTED_ARGS=3
E_BADARGS=65
@yevrah
yevrah / centos.repo
Last active April 7, 2017 00:42
LINUX: Add Centos Packages to Redhat 5.8
# vim /etc/yum.repos.d/centos.repo
#
# Adding the following contents, note the ‘5’ has to be hardcoded to either 5 or 6 depending on your RHEL version.
#
[centos]
name=CentOS $releasever - $basearch
baseurl=http://ftp.heanet.ie/pub/centos/5/os/$basearch/
enabled=1
gpgcheck=0
@yevrah
yevrah / mysql_inserts.sh
Created December 3, 2014 05:03
MySQL: Streaming log of insert statements
#!/bin/bash
tail -f /var/run/mysqld/mysqld.log | grep 'insert'
@yevrah
yevrah / mysql_table_sizes.sql
Created December 3, 2014 04:49
MySQL: Table Size States
-- Get Table Sizes
SELECT NOW(),
TABLE_SCHEMA,
TABLE_NAME,
ENGINE,
TABLE_ROWS,
DATA_LENGTH / 1024 / 1024,
INDEX_LENGTH / 1024 / 1024,
DATA_FREE,
AUTO_INCREMENT
@yevrah
yevrah / mysql_processlist.sh
Last active August 29, 2015 14:10
MySQL Watch Processlist
#!/bin/bash
watch -n 1 --differences "mysql -u mon -e 'show processlist' | grep -v Sleep"
@yevrah
yevrah / print_env.pl
Created November 21, 2014 00:07
Perl: print environment variables
#!/usr/bin/env perl
foreach $key (keys(%ENV)) {
printf("%-30.30s: $ENV{$key}\n", $key);
}
@yevrah
yevrah / fixnames.sh
Created November 12, 2014 04:10
Bash: Repair case in source files when migrating from windows to linux
#!/bin/sh
# Replace filenames found in code and create a backup of original
find . -type f \( -name "*.php" -or -name "*.jpg" \) -exec bash -c 'gsed -i.bak "s/(\W`basename {}`\W/)`basename {}`/Ig"/src/ *' \;
########################
# Explanation
# find
# . : Recursively from current directory,
# -type f : files only - not folders,
@yevrah
yevrah / context.pl
Created November 11, 2014 05:16
Perl: Determine application context
#!/usr/bin/env perl
use strict;
use warnings;
# Determine Context
use constant IS_MOD_PERL => exists $ENV{'MOD_PERL'};
use constant IS_PSGI => exists $ENV{'psgi.version'};
use constant IS_CGI => IS_MOD_PERL || IS_PSGI || exists $ENV{'GATEWAY_INTERFACE'};
@yevrah
yevrah / flock.pl
Created November 11, 2014 04:01
Perl: File locking
#!/usr/bin/env perl
use strict;
# import LOCK_* and SEEK_END constants
use Fcntl qw(:flock SEEK_END);
# Open the file
open(my $xml, ">>", "sample.xml") or die "Can't open xml $!";
# Lock the file
@yevrah
yevrah / time.pl
Created November 5, 2014 04:52
Perl: Getting various times, GMT, Local, and Custom Time Zone
use strict;
use feature qw/say/;
use POSIX qw(strftime tzset);
say strftime("%Y %d %m %H:%M:%S GMT", gmtime(time)); # GMT
say strftime("%Y %d %m %H:%M:%S %Z", localtime(time)); # Local Time
# Set to custom timezone
$ENV{TZ} = 'America/Los_Angeles';
tzset;