Skip to content

Instantly share code, notes, and snippets.

View mikeerickson's full-sized avatar

Mike Erickson mikeerickson

View GitHub Profile
@mikeerickson
mikeerickson / js:Anonymous Function
Last active October 1, 2015 13:48
JavaScript: Anonymous Self Invoking Function
(function() {
})();
@mikeerickson
mikeerickson / js:jQuery Anonymous Function
Last active October 1, 2015 13:48
jQuery: Anonymous Self Invoking Function
(function($) {
})(jQuery);
@mikeerickson
mikeerickson / php:howLongAgo
Last active December 17, 2015 04:19
PHP:howLongAgo
/**
* Returns twitter style time ago from supplied timestamp
* @param timestamp $timestamp [description]
* @return string [description]
*/
public static function howLongAgo($timestamp) {
$difference = time() - $timestamp;
if($difference >= 60*60*24*365){ // if more than a year ago
$int = intval($difference / (60*60*24*365));
function throttle( fn, time ) {
var t = 0;
return function() {
var args = arguments, ctx = this;
clearTimeout(t);
t = setTimeout( function() {
fn.apply( ctx, args );
}, time );
};
@mikeerickson
mikeerickson / msToTimeStamp
Created September 2, 2013 22:48
Milliseconds to TimeFormat (hh:mm:ss.tt)
function msToTime(s) {
function addZ(n) {
return (n<10? '0':'') + n;
}
var ms = s % 1000;
s = (s - ms) / 1000;
var secs = s % 60;
s = (s - secs) / 60;
/**
*
* Base64 encode / decode
* http://www.webtoolkit.info/
*
**/
 
var Base64 = {
 
// private property
/**
*
* URL encode / decode
* http://www.webtoolkit.info/
*
**/
 
var Url = {
 
// public method for url encoding
/**
*
* MD5 (Message-Digest Algorithm)
* http://www.webtoolkit.info/
*
**/
 
var MD5 = function (string) {
 
function RotateLeft(lValue, iShiftBits) {
<?php
 
function generatePassword($length=9, $strength=0) {
$vowels = 'aeuy';
$consonants = 'bdghjmnpqrstvz';
if ($strength & 1) {
$consonants .= 'BDGHJLMNPQRSTVWXZ';
}
if ($strength & 2) {
$vowels .= "AEUY";
/**
*
* PHP validate email
* http://www.webtoolkit.info/
*
**/
 
function isValidEmail($email){
return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}