Skip to content

Instantly share code, notes, and snippets.

Avatar
🐈‍⬛
Codes with cats

Paul Armstrong paularmstrong

🐈‍⬛
Codes with cats
View GitHub Profile
@paularmstrong
paularmstrong / Preloader.js
Created May 13, 2009
Preloader class for jQuery
View Preloader.js
$.extend(Function.prototype, {
use: function() {
var method = this, args = Array.prototype.slice.call(arguments), object = args.shift();
return function() {
return method.apply(object, args.concat(Array.prototype.slice.call(arguments)));
}
},
useEL: function() {
var method = this, args = Array.prototype.slice.call(arguments), object = args.shift();
return function(event) {
View gist:468228
function password_strength(password, username) {
var p = password
, u = username
;
if(
/^[a-z]*$/.test(p)
|| /^[A-Z]*$/.test(p)
|| /^[0-9]*$/.test(p)
) {
@paularmstrong
paularmstrong / Timezone.js
Created Jul 24, 2010
JavaScript GMT offsets by TZ code
View Timezone.js
TZ = {
getTimezoneOffset: function(timezone)
{
var dst = (TZ.isDSTObserved()) ? 'dst' : 'std';
return TZ.zones[timezone][dst];
},
isDSTObserved: function()
{
// 2nd sunday of march
View gist:576589
#!/bin/bash
DIR=$1
ACTION='backup'
if [ $# -eq 2 ]; then
ACTION=$2
fi
if [ $ACTION = 'delete' ]; then
rsync -rv --delete --size-only backup@files::$DIR/ /mnt/group1/media/$DIR/
else
@paularmstrong
paularmstrong / runtests.js
Created Sep 19, 2010
simple nodejs script to work with nodeunit to find all *.test.js files and execute them
View runtests.js
#!/usr/bin/env node
/*
Run nodeunit tests
Simple node.js script to find all *.test.js files and execute them through nodeunit.
Without arguments, will search recursively through the current directory for tests.
Supply arguments of directories or specific tests to run.
Sample Usage:
$ ./runtests.js
@paularmstrong
paularmstrong / pre-commit
Created Nov 25, 2010
Pre-Commit Hook for Git to add the SHA to a file in your working directory.
View pre-commit
#!/usr/bin/env node
var child_process = require('child_process'),
fs = require('fs'),
root = __dirname + '/../../',
configFile = root + 'config/config.js',
jslint = require(root + 'lib/jslint/jslint.js');
function setPushVersion() {
child_process.exec('git rev-parse HEAD', { cwd: root }, function (error, stdout, stderr) {
@paularmstrong
paularmstrong / installClang.sh
Created Mar 11, 2011
Installs Clang Static Analyzer
View installClang.sh
#!/bin/bash
installonly=no
while [ $# -gt 0 ]
do
case "$1" in
(-i) installonly=yes;;
(-*) echo "$0: error - urecognized option $1" 1>&2; exit 1;;
(*) break;;
View brainbuster.js
// What does this return?
(function() {
function f() { return 1; }
return f();
function f() { return 2; }
})();
// What is x?
var y = 1, x = y = typeof x;
@paularmstrong
paularmstrong / a_star.js
Created May 12, 2011 — forked from jminor/a_star.js
A* path finding algorithm for impactjs game engine
View a_star.js
// A* path finding algorithm for impactjs game engine
// adapted from http://stormhorse.com/a_star.js
// via http://46dogs.blogspot.com/2009/10/star-pathroute-finding-javascript-code.html
// impact-ified by jminor - http://pixelverse.org/
/* Example:
this.pathFinder = new PathFinder();
var start = [((this.pos.x+this.size.x/2) / tilesize).floor(), ((this.pos.y+this.size.y/2) / tilesize).floor()];
var destination = [((target.pos.x+target.size.x/2) / tilesize).floor(), ((target.pos.y+target.size.y/2) / tilesize).floor()];
@paularmstrong
paularmstrong / a_star.js
Created May 27, 2011 — forked from jminor/a_star.js
A* path finding algorithm for impactjs game engine
View a_star.js
/**
* AStar
*
* Created by Paul Armstrong on 2011-05-26.
* Copyright (c) 2011 Paul Armstrong Designs. All rights reserved.
*
* Based on: https://gist.github.com/827899
*/
ig.module('plugins.a-star')