Skip to content

Instantly share code, notes, and snippets.

@mralexho
mralexho / jquery.plugin-template.js
Created Jun 16, 2014
a template for creating jQuery plugins
View jquery.plugin-template.js
// remember to change every instance of "pluginName" to the name of your plugin!
(function($) {
// here it goes!
$.fn.pluginName = function(method) {
// plugin's default options
var defaults = {
foo: 'bar'
};
// this will hold the merged default and user-provided properties
// you will have to access the plugin's properties through this object!
View reflection.php
<?php
/**
* PHP Reflection API
* Examines the inner workings of functions, classes, and objects
*/
Reflection::export(new ReflectionClass('class_name'));
@mralexho
mralexho / option-list-us-states.txt
Created Dec 8, 2014
option list for U.S. States
View option-list-us-states.txt
AL|Alabama
AK|Alaska
AZ|Arizona
AR|Arkansas
CA|California
CO|Colorado
CT|Connecticut
DE|Delaware
DC|District Of Columbia
FL|Florida
View anonymous.pattern.js
/**
* Self-executing JavaScript pattern
*/
// undefined = true; works in javascript
// passing undefined as a param guarantees undefined is “undefined”
(function(window, document, undefined) {
// ...
})(this, document); // this = window
@mralexho
mralexho / singleton.pattern.js
Last active Aug 29, 2015
a singleton module
View singleton.pattern.js
var singleton = function() {
var privateVariable;
function privateFunction(x) {
...privateVariable...
}
return {
first method: function (a, b) {
...privateVariable...
},
second method: function (a, b) {
@mralexho
mralexho / inheritPrototype.js
Created Feb 24, 2015
function that makes the child object inherit from parent object
View inheritPrototype.js
function inheritPrototype(childObject, parentObject){
var parentCopy = Object.create(parentObject.prototype);
parentCopy.constructor = childObject;
childObject.prototype = parentCopy;
}
@mralexho
mralexho / relativetime.php
Created Mar 23, 2015
Returns relative time in PHP
View relativetime.php
function relative_time($date, $postfix = ' ago', $fallback = 'F Y')
{
$diff = time() - strtotime($date);
if($diff < 60)
return $diff . ' second'. ($diff != 1 ? 's' : '') . $postfix;
$diff = round($diff/60);
if($diff < 60)
return $diff . ' minute'. ($diff != 1 ? 's' : '') . $postfix;
$diff = round($diff/60);
if($diff < 24)
View linux-version.sh
# find out what version of Linux (distro) you are running
$ cat /etc/*-release
# find out kernel, version number, machine hardware name
$ uname -mrs
View module.pattern.js
var myNamespace = (function () {
var myPrivateVar = 0;
var myPrivateMethod = function (someText) {
console.log(someText); };
return {
myPublicVar: "foo",
myPublicFunction: function (bar) {
myPrivateVar++;
myPrivateMethod(bar);
} };
View sort.js
myArr.sort(function(a, b) {
var aName = a.text.toLowerCase();
var bName = b.text.toLowerCase();
return ((aName < bName) ? -1 : ((aName > bName) ? 1 : 0));
});