Skip to content

Instantly share code, notes, and snippets.

@0x4a
0x4a / CapsMute.ahk
Last active August 29, 2015 14:03
turn capslock into mute button - #ahk
; Turn Caps Lock into Mute
CapsLock::Volume_Mute
@0x4a
0x4a / elementExist.js
Created June 2, 2014 20:47
check if an element exists - #js
//http://appglobe.com/check-if-element-exists-with-jquery/
jQuery.fn.exists = function() {
return this.length > 0;
};
// usage:
/*
if ( $('#element').exists() ) {
// Do something
@0x4a
0x4a / RefreshCSS.js
Created June 1, 2014 20:19
#bookmarklet to reload CSS without refreshing the page - #js #css
//http://www.paulirish.com/2008/how-to-iterate-quickly-when-debugging-css/
javascript:(function(){var%20h,a,f;a=document.getElementsByTagName('link');for(h=0;h<a.length;h++){f=a[h];if(f.rel.toLowerCase().match(/stylesheet/)&&f.href){var%20g=f.href.replace(/(&|%5C?)forceReload=\d+/,'');f.href=g+(g.match(/\?/)?'&':'?')+'forceReload='+(new%20Date().valueOf())}}})()
@0x4a
0x4a / log.js
Created June 1, 2014 18:59
simple wrapper for console.log() - #js #dev
//http://htmltweaks.com/Debugging_JavaScript_with_the_Console
var log = function(msg, force) {
force ? alert(msg) : (window.console && window.console.log ? window.console.log(msg) : null);
};
@0x4a
0x4a / globVar.js
Created June 1, 2014 13:57
list all global variables - #js #dev
console.log(Object.keys(window));
@0x4a
0x4a / geturlparams.js
Created June 1, 2014 11:27
how to get URL Parameters using #jQuery - #js
function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
@0x4a
0x4a / linebreaks.js
Created June 1, 2014 10:34
This javascript code removes all 3 types of line breaks - #js #string
//http://www.textfixer.com/tutorials/javascript-line-breaks.php
someText = someText.replace(/(\r\n|\n|\r)/gm,"");
@0x4a
0x4a / scoping.js
Created June 1, 2014 04:23
scoping function for pseudo-global variables - #js
(function() {
var a = 0; // `a` is NOT a property of `window` now
function foo() {
alert(a); // Alerts "0", because `foo` can access `a`
}
})();
@0x4a
0x4a / escapeSelectors.js
Created June 1, 2014 04:19
escape special characters in #css selectors - #js
/*
https://learn.jquery.com/using-jquery-core/faq/how-do-i-select-an-element-by-an-id-that-has-characters-used-in-css-notation/
The following function takes care of escaping these characters and places a "#" at the beginning of the ID string:
Example:
$( jq( "some.id" ) )
*/
function jq( myid ) {
return "#" + myid.replace( /(:|\.|\[|\])/g, "\\$1" );
}
@0x4a
0x4a / sleep.js
Created June 1, 2014 04:16
javascript sleep function - #js
function sleep(millis, callback) {
setTimeout(function()
{ callback(); }
, millis);
}
/*
Example of usage:
console.log(process.argv);