Skip to content

Instantly share code, notes, and snippets.

View alchemycs's full-sized avatar

alchemycs

View GitHub Profile
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 / 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;
@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 / tones.h
Created December 19, 2012 23:04
Audio tone frequencies expressed as Hz
/*
* File: tones.h
* Author: developer@yrucalling.me
*
* Created on 13 December 2012, 9:01 AM
*
* Audio tone frequencies expressed as Hz
*
*/
@alchemycs
alchemycs / arduino.mk
Created December 6, 2012 07:12
Makefile for CLI compilation on arduino code modified for default ArduinoIDE install on a Mac. Make sure you set BOARD as appropriate.
#_______________________________________________________________________________
#
# edam's Arduino makefile
#_______________________________________________________________________________
# version 0.4
#
# Copyright (C) 2011, 2012 Tim Marston <tim@ed.am>.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@alchemycs
alchemycs / gist:4222258
Created December 6, 2012 06:42
Additions to boards.txt to use the Freetronics Leostick effectively with the Arduino IDE
##############################################################
leostick12.name=Freetronics LeoStick V1.2
leostick12.upload.protocol=arduino
leostick12.upload.maximum_size=28672
leostick12.upload.speed=1200
leostick12.bootloader.low_fuses=0xde
leostick12.bootloader.high_fuses=0xd8
leostick12.bootloader.extended_fuses=0xcb
leostick12.bootloader.path=diskloader
leostick12.bootloader.file=DiskLoader-LeoStick.hex
@alchemycs
alchemycs / create-drop-database-sql.sh
Created September 16, 2012 11:22
Create an SQL file that will drop all non-system databases
# Create an SQL file that will drop all non-system databases
mysql -u root -p -e "show databases" | grep -v Database | grep -v mysql| grep -v information_schema| grep -v test | grep -v OLD |gawk '{print "drop database " $1 ";select sleep(0.1);"}' > drop_all_databases.sql
@alchemycs
alchemycs / ls2csv.sh
Created May 10, 2012 04:18
List files in a directory terminated by comma (,) and enclosed by quotes (")
# Useful if you need a list of files in CSV or for pasting into a dictionary
ls |sed 's/\(.*\)/"\1",/'
@alchemycs
alchemycs / uuid-v4.js
Created April 26, 2012 23:22
Generate RFC 4122 Version 4 Compliant UUID
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
@alchemycs
alchemycs / dateextension.js
Created April 17, 2012 13:28
A dead easy way to get unix style timestamp from any javascript Date object
/*
Extends the Date object to get number of seconds since UNIX epoch
instead of milliseconds as with .getTime()
*/
Date.prototype.getTimestamp = function() {
return Math.round(this.getTime()/1000);
}