Skip to content

Instantly share code, notes, and snippets.

@LukeChannings
LukeChannings / runrandom.sh
Created July 15, 2011 17:58
A script to start a random Application in OS X
#!/bin/bash
##
# RunRandom
# - A script to run n random applications.
#
# Copyright 2011 Luke Channings
#
# Usage:
# To run a single app: ./runrandom.sh
@LukeChannings
LukeChannings / check_for_film.sh
Created August 25, 2011 21:07
A script to check for films in a directory, and move them to another directory.
#!/bin/bash
##
# Check for Film
# - A script to check for films in a directory,
# - and move them to another directory.
#
##
CHECKDIR="/Volumes/Media/Downloads" # Directory to check for videos.
@LukeChannings
LukeChannings / fetch_content.js
Created August 26, 2011 18:03
fetch_content
function fetch_content(e)
{
// Put the element into a variable.
target = e.srcElement;
if ( target.classList.contains("expanded") ){
target.classList.remove("expanded");
}
else {
@LukeChannings
LukeChannings / mount_msdos
Created September 7, 2011 15:55
Synchronise USB Stick when inserted OS X.
#!/bin/bash
# Mount the volume.
/sbin/mount_msdos.real "$@"
# MODIFY TO FIT YOUR NEEDS.
LABEL="HUBBLE" # USB Stick Label.
USBFOLDER="College Work" # Name of the folder on the USB Stick. (Can be a relative path.)
DESTINATION="/Volumes/Media/Dropbox/College Work" # Folder to which the USB Stick will be synchronised.
@LukeChannings
LukeChannings / load.js
Created May 19, 2012 20:47
stylesheet injector
var load = function(url, callback) {
if ( ! window.registeredStylesheets ) window.registeredStylesheets = [];
if ( window.registeredStylesheets.indexOf(url) == -1)
{
(document.head || document.getElementsByTagName("head")[0]).appendChild(function(){
var link = document.createElement('link');
@LukeChannings
LukeChannings / expand.js
Created August 15, 2012 16:32
expand method
// expands an item to show its inner box.
// @param e {Event} the event that triggered the expansion.
var expand = function(e) {
e.preventDefault()
if ( ! opened ) {
open()
}
@LukeChannings
LukeChannings / printPrototypeChain.js
Last active December 20, 2016 08:42
prints the prototype chain for a constructed object.
/**
* prints the prototype chain for a constructed object.
* @param {Object} a constructed object.
* @param asArray {Boolean} if true, the chain will be returned as an array.
*/
function printPrototypeChain(instance, asArray) {
var chain = []
while (instance = Object.getPrototypeOf(instance)) {
@LukeChannings
LukeChannings / getScaledDimensions.js
Created March 5, 2013 14:36
computes the dimensions for an element to fully cover the viewport.
/**
* computes the dimensions for an element to fully cover the viewport.
* @param vw {Number} the width of the viewport
* @param vh {Number} the height of the viewort
* @param a {Number} the aspect ratio of the element being displayed.
*/
function getScaledDimensions(vw, vh, a) {
// variables to contain the width and height results.
var w, h, ox, oy;
@LukeChannings
LukeChannings / eventemitter2-listenerCount.js
Created March 15, 2013 12:13
Counts the number of listeners attached to a pubsub listener tree.
function countListeners(tree) {
var count = 0
for (var i in tree) {
if (tree.hasOwnProperty(i) && typeof tree[i] === "object") {
count += countListeners(tree[i])
}
if (typeof tree._listeners === "function") {
@LukeChannings
LukeChannings / id3v1.js
Last active December 23, 2015 22:49
Simple function to read ID3V1 tags.
module.exports = {
/**
* reads ID3v1 tags from a buffer.
* @param buffer {Buffer} a file buffer containing the tag. (Does not have to be the entire file.)
* @returns {Object} with properties for {String}"title" {String}"artist" {String}"album" {Number}"year" {Number}"track" {String}"comment" {String}"genre".
*/
getID3v1Tags: function(buffer) {
// who thought of this? it's stupid.