Skip to content

Instantly share code, notes, and snippets.

@sTiLL-iLL
sTiLL-iLL / objProtaddl.js
Created August 26, 2014 09:11
extend, toggleClass, and equals methods
// functional additions to the Object prototype
Object.prototype.extend = function() {
if (arguments.length === 0)
return this;
for (var i = 0; i < arguments.length; i++) {
for (var property in arguments[i]) {
if (arguments[i].hasOwnProperty(property))
@sTiLL-iLL
sTiLL-iLL / thepool.js
Last active August 29, 2015 14:05
simple and effective object / worker / connection pool implimentation in javascript
function PoolFactory() {
var createPool = function (options) {
var wrkrs = [], freeWrkrs = [],
opts = options || {},
wCnt = options.maxWorkers || 4,
wrkrPth = options.path || 'whateveryouwant.js';
@sTiLL-iLL
sTiLL-iLL / condyLoad.js
Created August 26, 2014 07:06
basic conditional loading (loads when specified elements are present)
/*
The arguments against this practice will be (1) concatenating into existing JS and CSS to save on the number of requests and (2) flash of content style changes. The first argument needs to be judged on a per-case basis; if the required CSS and JS is small, it should be concatenated to a file used throughout the site or site subsection. The second argument can always be hushed with a bit of transition magic!
*/
$('article pre').length && (function() {
var mediaPath = '/assets/';
$('<link>').attr({
type: 'text/css',
rel: 'stylesheet',
href: mediaPath + 'css/syntax.css'
@sTiLL-iLL
sTiLL-iLL / seshCache.js
Last active August 29, 2015 14:05
Simple caching inside of session storage...
// session storage caching
define(function() {
var cacheObj = window.sessionStorage || {
getItem: function(key) {
return this[key];
},
setItem: function(key, value) {
@sTiLL-iLL
sTiLL-iLL / debounce.js
Created August 25, 2014 01:33
A load balancing function.... debounce()
/*
The debounce method returns a function which wraps your callback,
limiting its execution rate to the limit specified in the second argument.
Now your frequent callbacks can't brick the user's browser!
*/
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
@sTiLL-iLL
sTiLL-iLL / frag.js
Created August 25, 2014 01:28
Fastest way to add new nodes to the DOM
var frag = document.createDocumentFragment();
ajaxResult.items.forEach(function(item) {
// Create the LI element
var li = document.createElement('li');
li.innerHTML = item.text;
// Do some normal node operations on the LI here,
// like add classes, modify attributes,
// add event listeners, add child nodes, etc.
@sTiLL-iLL
sTiLL-iLL / dialogz.html
Last active August 29, 2015 14:05
html5 dialog snips
<!doctype html>
<html>
<head>
<title>Dialog Test</title>
<style>
dialog::backdrop {
background: rgba(255, 0, 255, 0.25);
}
</style>
</head>
@sTiLL-iLL
sTiLL-iLL / dilogSnippet.html
Created August 19, 2014 07:28
Dialog tag example
<dialog>
<p>This is da dialog!</p>
<button id="close">Close</button>
</dialog>
<button id="show">Open Dialog!</button>
<script>
var dialog = document.querySelector('dialog');
document.querySelector('#show').onclick = function() {
dialog.show();
};
@sTiLL-iLL
sTiLL-iLL / EventEmitterPattern.js
Last active August 29, 2015 14:05
An example of inheriting from event emitter
// Require our emitter
var Emitter = require('events').EventEmitter;
// Our main constructor
var myEmitter = function (config) {
// extend with emitter
Emitter.call(this);
};
@sTiLL-iLL
sTiLL-iLL / ajaxRequest.js
Created August 19, 2014 01:59
ajax request
var r = new XMLHttpRequest();
r.open("POST", "webservice", true);
r.onreadystatechange = function () {
if (r.readyState != 4 || r.status != 200) return;
console.log(r.responseText);
};
r.send("a=1&b=2&c=3");