Skip to content

Instantly share code, notes, and snippets.

@cargowire
cargowire / namespacedAutoOnLoad.js
Created December 17, 2010 12:42
Implements a simple json traverse as the only call in jQuery onReady to find all '_load' methods on classes and call them within their own scope. Allows easy adding of new 'classes' within that known namespace that control their own load and private vars
// Single jquery onload action covers all namespaced items
$(function () { traverse(myNamespace); });
// Identify all _load methods in the namespace and call them within their own object scope
var traverse = function(jsonObj, parentObj, name) {
if (typeof (jsonObj) == "object") {
parentObj = jsonObj;
$.each(jsonObj, function(k,v) {
traverse(v, parentObj, k);
});
@cargowire
cargowire / unreferencedfiles.sh
Created January 20, 2011 13:33
List files within the arg1 folder that are not referenced in any content from files in arg2
# Simple find unreferenced filename script
# Argument 1 is a folder that contains files you are interested in. e.g. an images folder
# Argument 2 is a folder that contains the files to search within. e.g. a css folder
for pattern in `ls $1`; do
if ! grep -rq $pattern $2; then
echo $pattern;
fi
done
@cargowire
cargowire / addsuffix.sh
Created August 17, 2012 15:51
Rename files by adding a suffix after a fixed number of characters from the original string (assumes no '.' in filenames)
for i in *.$1;
do
IFS="." read -ra parts <<< "$i"
mv $i ${parts[0]:0:$3}$2.${parts[1]};
unset IFS
done

Keybase proof

I hereby claim:

  • I am cargowire on github.
  • I am cargowire (https://keybase.io/cargowire) on keybase.
  • I have a public key ASAtuFVcugGTK_Xzq_FHZJbsosuh-R7mRRgNnr6RxdLVWAo

To claim this, I am signing this object:

@cargowire
cargowire / convertphp.sh
Created April 13, 2012 12:06
Export all php files as static html files
# Uses php cli to run all php files in the current directory and write their output to file
# Argument 1 is the extension of the output files e.g. ".html" or ".htm"
# Argument 2 is a prefix for the filenames
for file in *.php; do
php $file | cat > $2${file%.php}$1;
done