Skip to content

Instantly share code, notes, and snippets.

View alchemycs's full-sized avatar

alchemycs

View GitHub Profile
@alchemycs
alchemycs / tones.h
Created December 19, 2012 23:04
Audio tone frequencies expressed as Hz
/*
* File: tones.h
* Author: [email protected]
*
* Created on 13 December 2012, 9:01 AM
*
* Audio tone frequencies expressed as Hz
*
*/
@alchemycs
alchemycs / jsloc.sh
Created January 31, 2013 02:47
Count JS app lines of code, exclude stuff you didn't write..
#!/bin/sh
find . -iname '*.js'|grep -v -E "^./(dev|node_modules|components|(public/js/((angular|bootstrap|jquery|underscore|modernizr|tiny_mce))))"|xargs wc -l|less
@alchemycs
alchemycs / dbsize.sql
Created May 15, 2013 10:00
Get the size of a mysql database
SELECT table_schema "DB Name",
Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB"
FROM information_schema.tables
GROUP BY table_schema;
app.config(function($httpProvider) {
$httpProvider.interceptors.push(function($rootScope, $location, $q) {
return {
'request': function(request) {
// if we're not logged-in to the AngularJS app, redirect to login page
$rootScope.loggedIn = $rootScope.loggedIn || $rootScope.username;
if (!$rootScope.loggedIn && $location.path() != '/login') {
$location.path('/login');
}
return request;
@alchemycs
alchemycs / gist:8193961
Created December 31, 2013 08:14
Enable Android adb on Mac OS X to work with Telstra T-Hub 2. Probably works for other OS by updating the equivalent file with the correct vendor id.
# This works for my model anyway, use
echo 0x069b >> ~/.android/adb_usb.ini
adb kill-server
adb devices
@alchemycs
alchemycs / fakemail.sh
Created February 25, 2014 04:58
Don't accidentally send emails when testing email function from PHP (*nix including OS X)
#!/bin/bash
#
# 1. Put this somewhere like /usr/local/bin/fakemail.sh
# 2. Set the permissions with: chmod a+x /usr/local/bin/fakemail.sh
# 3. Edit your php.ini and set: sendmail_path=/usr/local/bin/fakemail.sh
#
# Now your email will not be sent but logged to unique files that are timestamped.
# We use $RANDOM just to try and reduce collissions in case multiple emails are sent at the same time.
#
@alchemycs
alchemycs / injectiontest.js
Created June 4, 2014 04:03
Web input/output sanitisation test script
/*
This file is used to test any input that is also used as an output to ensure sanitisation has occured:
Usage: on any form input enter something like:
<script src="thisfile.js"></script>
*/
alert('If this alert box worked then you need to sanitise your output!');
@alchemycs
alchemycs / take-site-snapshot.sh
Last active August 29, 2015 14:05
AWS Nightly Snapshot
#!/bin/bash
#
# We use this code from cron to automate nightly volume snapshots.
# In our case we have two volumes.
#
#
export EC2_KEYPAIR=MY-KEY-PAIR
export EC2_URL=https://ec2.ap-southeast-2.amazonaws.com
export AWS_ACCESS_KEY=accesskey
export AWS_SECRET_KEY=secretkey
@alchemycs
alchemycs / apache-config-watcher.conf
Created August 15, 2014 00:33
Apache Config Auto-Watch via Upstart
# apache-config-watch - checks config changes and reloads apache if the configs are ok
description "Reload apache when configs have changed."
author "Michael McHugh <[email protected]>"
start on runlevel [2345]
stop on runlevel [016]
respawn
@alchemycs
alchemycs / boxcmd.js
Created August 20, 2014 00:51
Run repository scripts in AWSBOX from cron or shell with environment variables
#!/usr/local/bin/node
//quick and dirty to get my scripts going quickly on awsbox from cron. Will clean this up some other time.
var path = require('path');
var child_process = require('child_process');
var configFile = path.join(process.env['HOME'], 'config.json');
var config = require(configFile);