Skip to content

Instantly share code, notes, and snippets.

@argshook
argshook / clickOutsideHideEl.js
Last active December 28, 2015 05:29
Click outside the element to hide it. I was always having difficulties with this, here's a nice tip. This depends on jQuery, just follow the same logic for any other framework or even vanilla JS.
// change selectors as you need
var selector = '.selector';
$(document).ready(function() {
$(selector).click(function(e) {
$(selector).show();
e.stopPropagation();
});
@argshook
argshook / detectIE.js
Created November 14, 2013 10:00
Super tiny IE browser detection in javascript. Works as expected with IE 4, 5, 5.5, 6, 7, 8, 9 & 10. Also makes you warm inside.
var isMSIE = /*@cc_on!@*/0;
if (isMSIE) {
document.body.style.background = "red"; //it's IE :(
} else {
document.body.style.background = "green"; //it's not IE!
}
@argshook
argshook / repeatString.js
Created November 14, 2013 13:23
Repeat string as many times as you need without any loops.
String.prototype.repeat = function(times) {
return (new Array(times + 1)).join(this);
};
var str = "1".repeat(3);
console.log(str); // 111
@argshook
argshook / shuffleArray.js
Created December 11, 2013 09:44
Two ways of shuffling arrays in javascript
// a simple and efficient way to shuffle
// a relatively small array. Doesn't work well
// with a lot of indices. See: http://stackoverflow.com/a/18650169/2104866
var numbers = [1,2,3,4,5,6];
numbers.sort(function() {
return .5 - Math.random();
});
@argshook
argshook / matchEmail.js
Created May 5, 2014 16:49
regexp for matching a valid email and populating an array with its parts
// regexp for matching a valid email and populating an array with its parts
'[email protected]'.match(/([a-z|0-9]{2,})+\@([a-z|0-9]+)\.(.{2,})/) // <= ['[email protected]', 'email', 'domain', 'com']
@argshook
argshook / jsbin.mejim.html
Last active August 29, 2015 14:02
This is a relatively small tabbed content boilerplate (no styling, no bullshit). IE8+. See example here: http://jsbin.com/mejim/2/edit?output
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div class="tabbed">
@argshook
argshook / newEvenIfNotNew
Created October 15, 2014 18:02
If you want to make sure your object is always instantiated with `new` keyword
function myObject(options) {
if(!(this instanceOf myObject))
return new myObject(options);
}
var object = myObject({}); // acts as if was instantiated with new
@argshook
argshook / fail.js
Last active November 26, 2015 09:30
var wtf = (''+![])[0]+(''+![])[1]+([][0]+'')[0b101]+(''+![])[2]
console.log(wtf);
set linkanimations
set sortlinkhints
set noautofocus
set smoothscroll
let scrollstep = 100
let blacklists = ["http://devdocs.io/*","https://inbox.google.com/*","https://mail.google.com/*","http://vim-adventures.com/*"]
let hintcharacters = 'asdfghjkl'
getIP() -> {{
httpRequest({url: 'http://api.ipify.org/?format=json', json: true},
function(res) { Status.setMessage('IP: ' + res.ip); });
@argshook
argshook / 0_reuse_code.js
Created April 6, 2016 13:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console