Skip to content

Instantly share code, notes, and snippets.

View mateuszkocz's full-sized avatar
✌️

Mateusz Kocz mateuszkocz

✌️
View GitHub Profile

CTRL + SHIFT + -> - expand selection

CMD + D - Select the word

F8 - show the error info

CMD + Shift + L - select all words

SHIFT + CMD + K - delete line

@mateuszkocz
mateuszkocz / 10.js
Created February 17, 2014 20:31
Bye, fail, "10". Something about it: http://tmik.co.uk/?p=672. Also +!+[] works as that: (1) +[] converts falsy epmty array to number (+ operator) and it's 0, then (2) the bang makes it true (!0 === true), and finally (3) true is converted to number (+true), so the outcome is 1. List of characters that can be used with this strangeness: http://s…
++[[]][+[]]+[+[]]
@mateuszkocz
mateuszkocz / text-select.html
Created December 8, 2013 20:33
Text select in an input or textarea. Demo: http://jsbin.com/umEjuKu/1/edit
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<form id="form">
<label>name:
<input type="text" id="txtname" value="Example name" tabindex="1" autocomplete="off"></label>
@mateuszkocz
mateuszkocz / scroll-painting
Created December 8, 2013 17:22
Avoid paints on scroll. Source: http://www.thecssninja.com/javascript/pointer-events-60fps . Instead of document.body you might want to use document.documentElement if you're using html adn body as a free div.
CSS
.disable-hover {
pointer-events: none;
}
JS
var body = document.body,
timer;
window.addEventListener('scroll', function() {
@mateuszkocz
mateuszkocz / safe-constructor.js
Created December 1, 2013 12:13
Safe constructor.
var Constructor = function() {
if (!(this instanceof Constructor)) {
return new Constructor();
}
// Properties and methods...
this.something = 'something';
// ...
}
var arrayObject = ["What", "is", "going", 0,"on", 111,"..", "here"];
String.prototype.slice.call(arrayObject);
//"What,is,going,0,on,111,..,here"
String.prototype.concat.call(arrayObject);
//"What,is,going,0,on,111,..,here"
String.prototype.substring.call(arrayObject,1,10)
//"hat,is,go"
String.prototype.indexOf.call(arrayObject, "n,111")
//17
var listener = node.addEventListener("click", function(event) {
let _target = event.target;
this.handleClick(_target);
}.bind(this));
//Inside we call a local method called handleClick() with the event’s target property. Nothing too exciting.
//With Fat Arrow Functions, that becomes:
var listener = node.addEventListener("click", (event) => {
let _target = event.target;
this.handleClick(_target);
var slice = Array.prototype.slice;
// slice is now "unbound". As Array.prototype.slice usually
// acts on the context it is given, or "this", it will
// no longer work.
slice(0, 1); // => TypeError: can't convert undefined to object
slice([1,2,3], 0, 1); // => TypeError: ...
// But if we recall apply and call, they let us supply a context.
slice.call([1,2,3], 0, 1); // => [1]
@mateuszkocz
mateuszkocz / unicode.js
Created November 1, 2013 18:04
Unicode characters
'\uD83D\uDCA9' // => '💩'
'\u2661'// => '♡'
@mateuszkocz
mateuszkocz / bind.js
Created October 27, 2013 21:18
Bind with anonymous function. Source: http://dailyjs.com/2012/06/25/this-binding/
Shape.prototype = {
move: function(x, y) {
this.x += x;
this.y += y;
var checkBounds = function(min, max) {
if (this.x < min || this.x > max) {
console.error('Warning: Shape out of bounds');
}
}.bind(this);