Skip to content

Instantly share code, notes, and snippets.

@d4rkr00t
d4rkr00t / JavaScript - Module Template.js
Created October 21, 2013 11:53
JavaScript - Module Template
MYAPP.utilities.array = (function() {
var uobj = MYAPP.utilities.object,
ulang = MYAPP.utilities.lang,
array_string = "[object Array]",
ops = Object.prototype.toString;
return {
inArray: function(needle, haystack) {
for (var i = 0, max = haystack.length; i < max; i += 1) {
if (haystack[i] === needle) {
@d4rkr00t
d4rkr00t / Random between two numbers.js
Created November 2, 2013 17:51
Random between two numbers
Math.floor(Math.random() * (max - min + 1)) + min;
@d4rkr00t
d4rkr00t / Debounce.js
Created February 11, 2014 17:08
Debounce
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
clearTimeout(timeout);
timeout = setTimeout(function() {
@d4rkr00t
d4rkr00t / Pad Zeros.js
Created February 28, 2014 13:46
Pad Zeros
function pad(num){
return ('00'+num).slice(-2);
}
@d4rkr00t
d4rkr00t / Get page query parameters.js
Created February 28, 2014 13:48
Get page query parameters
window.getQueryParameters = function(str) {
return (str || document.location.search).replace(/(^\?)/,'').split("&").map(function(n){return n = n.split("="),this[n[0]] = n[1],this}.bind({}))[0];
}
@d4rkr00t
d4rkr00t / string.trim.js
Created June 8, 2014 07:35
String.trim
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g, '');
};
}
@d4rkr00t
d4rkr00t / curry.js
Created August 12, 2014 17:00
Curry function with any numbers og arguments
var curry = function(fn) {
var _subCurry = function(fn) {
var args = [].slice.call(arguments, 1);
return function () {
return fn.apply(this, args.concat([].slice.call(arguments)));
};
};
@d4rkr00t
d4rkr00t / clearfix.css
Created September 1, 2014 08:00
Clearfix
.clearfix:before,
.clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
@d4rkr00t
d4rkr00t / center-y.css
Created September 4, 2014 06:12
Center Y
.center-xy {
position: relative;
top: 50%;
transform: translateY(-50%);
}
@d4rkr00t
d4rkr00t / hidden-accessible.css
Created September 4, 2014 06:13
The hidden-accessible class has the unique ability to mimic the effects of display: none, yet still be accessible to screen readers and possess the correct metrics. This is useful for retrieving the width and height of an element in JavaScript without it being visible or taking space in the layout.
.hidden-accessible {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}