Skip to content

Instantly share code, notes, and snippets.

View bpartridge's full-sized avatar

Brenton Partridge bpartridge

View GitHub Profile
@bpartridge
bpartridge / example-user.js
Created May 4, 2012 11:21 — forked from nijikokun/example-user.js
Beautiful Validation... Why have I never thought of this before?!
var user = {
validateCredentials: function (username, password) {
return (
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' }
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' }
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' }
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' }
: (!/^([a-z0-9-_]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' }
: false
);
@bpartridge
bpartridge / gist:2576202
Created May 2, 2012 12:22
Pet the pony! Go to the address bar of your Reddit window (not this one), delete everything there, type "javascript:" (with the colon, without quotes), then after that paste this (one line)
(function(){var NPETS=3,MAXLEN=100,INTERVAL=100,POS_PROP='background-position',KARMA_POS='-0px -0px',DIS_POS='-55px -0px',$name=$('span.redditname a'),$img=$('#header-img'),initialName=$name.text(),initialAttrib=$img.parent().attr('title');$name.text('pet me please');$img.css(POS_PROP,DIS_POS);$img.parent().removeAttr('title');$img.mouseenter(function(){var buf=[];window.petkarmaint=setInterval(function(){var nmin=0,nmax=0,i=1,indownstroke=true,happy;buf.push(window.petkarmay);while(i<buf.length-1){if(buf[i-1]>buf[i]&&buf[i+1]>=buf[i]){nmin+=1;indownstroke=true;};if(buf[i-1]<buf[i]&&buf[i+1]<=buf[i]){nmax+=1;indownstroke=false;};i+=1;};if(nmin>=NPETS-1){window.petkarmahappy=true;$name.text('HAPPY! coded by btown_brony, vectors by Pinkie_Pi');$img.css(POS_PROP,KARMA_POS);};if(nmin<NPETS-1){window.petkarmahappy=false;$name.text(indownstroke?'pet':'...');$img.css(POS_PROP,DIS_POS);};},INTERVAL);}).mousemove(function(e){window.petkarmay=e.pageY;}).mouseleave(function(){if(window.petkarmaint){clearInterval(window.
From 8a69546552b12261cc40dcfca96fb4d235e7ca0e Mon Sep 17 00:00:00 2001
From: Brenton Partridge <bapartridge@gmail.com>
Date: Tue, 30 Aug 2011 21:43:04 -0700
Subject: [PATCH] Changed interface for ADVANsCEne to compile on OS X
---
src/NDSSystem.cpp | 2 +-
src/mc.cpp | 2 +-
src/mc.h | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
From 8a69546552b12261cc40dcfca96fb4d235e7ca0e Mon Sep 17 00:00:00 2001
From: Brenton Partridge <bapartridge@gmail.com>
Date: Tue, 30 Aug 2011 21:43:04 -0700
Subject: [PATCH] Changed interface for ADVANsCEne to compile on OS X
---
src/NDSSystem.cpp | 2 +-
src/mc.cpp | 2 +-
src/mc.h | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)