Skip to content

Instantly share code, notes, and snippets.

View joshuacerbito's full-sized avatar
🔥
🎸🎛🎛🎚🔊

Joshua Cerbito joshuacerbito

🔥
🎸🎛🎛🎚🔊
View GitHub Profile
@joshuacerbito
joshuacerbito / shell_unhide.sh
Created September 10, 2016 11:41
Unhide all files from a directory; A fix for the common Windows virus. (Change the Volume and Directory name)
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
# set me
FILES=/Volumes/DATA/Drive/*/
for f in $FILES
do
chflags nohidden "$f"
done
# restore $IFS
IFS=$SAVEIFS
@joshuacerbito
joshuacerbito / array_from_polyfill.js
Created September 20, 2016 06:30
Array.from Polyfill
if (!Array.from) {
console.log('adding polyfill for "Array.from"');
Array.from = (function () {
var toStr = Object.prototype.toString;
var isCallable = function (fn) {
return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
};
var toInteger = function (value) {
var number = Number(value);
if (isNaN(number)) { return 0; }
@joshuacerbito
joshuacerbito / get_set_data_attribute.js
Created September 28, 2016 05:33
IE-compatible data attribute getter/setter
Object.prototype.data = function (prop, val) {
var _return,
notIE = ( this.dataset !== undefined );
return ( notIE )? // not IE
( typeof val === "undefined" ) ? // get data value
this.dataset[prop] : this.dataset[prop] = val
: // is IE
( typeof val === "undefined" ) ? // get data value
this.getAttribute('data-' + prop) : this.setAttribute('data-' + prop, val);
@joshuacerbito
joshuacerbito / html5-dataset.js
Created September 28, 2016 06:30 — forked from brettz9/html5-dataset.js
Dataset Shim
/**
* Add dataset support to elements
* No globals, no overriding prototype with non-standard methods,
* handles CamelCase properly, attempts to use standard
* Object.defineProperty() (and Function bind()) methods,
* falls back to native implementation when existing
* Inspired by http://code.eligrey.com/html5/dataset/
* (via https://github.com/adalgiso/html5-dataset/blob/master/html5-dataset.js )
* Depends on Function.bind and Object.defineProperty/Object.getOwnPropertyDescriptor (polyfills below)
* All code below is Licensed under the X11/MIT License
@joshuacerbito
joshuacerbito / .htaccess
Created October 20, 2016 13:22 — forked from ScottPhillips/.htaccess
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
@joshuacerbito
joshuacerbito / MessageBus.js
Last active March 3, 2021 14:20
A topic-based subscribe-publish library written in JavaScript.
/*
* Observer.js
*
* SYNTAX:
* const EventHandler = new MessageBus( context );
* ---
* context: identifier for the event handler
* ---
* USAGE:
* var handler = new MessageBus( document );
@joshuacerbito
joshuacerbito / module-exporter.js
Created May 18, 2017 16:37
JS Module Exporter (AMD, CommonJS, Globals)
(function(globals){
// module name
const MODULE_NAME = 'moduleName';
// define your functions here
const functions = {
fn1: alert,
fn2: console.log
};
@joshuacerbito
joshuacerbito / Contract Killer 3.md
Created June 10, 2017 14:10 — forked from malarkey/Contract Killer 3.md
The latest version of my ‘killer contract’ for web designers and developers

Contract Killer

The popular open-source contract for web professionals by Stuff & Nonsense

  • Originally published: 23rd December 2008
  • Revised date: March 15th 2016
  • Original post

@joshuacerbito
joshuacerbito / pubsub.js
Last active January 11, 2023 08:05
Publish/Subscribe Snippet 2023
const PubSub = (() => {
const topics = {};
const hOP = topics.hasOwnProperty;
return {
subscribe(topic, listener) {
// Create the topic's object if not yet created
if(!hOP.call(topics, topic)) topics[topic] = [];
// Add the listener to queue
@joshuacerbito
joshuacerbito / array_shuffle.js
Last active January 16, 2018 17:39
An extension to the Array class that returns a shuffled version of an array
/*
* Array.shuffle
*
* Usage:
* const arr1 = [1, 2, 3, 4, 5];
* const arr2 = Array.shuffle(arr1);
* const arr3 = arr1.shuffle();
*
* @TODO:
* - Add callback functionality to Array.prototype.shuffle