Skip to content

Instantly share code, notes, and snippets.

View KKrisu's full-sized avatar
💭
Saving the world, please don't disturb

Kris Kesy KKrisu

💭
Saving the world, please don't disturb
  • Gniezno, Poland
View GitHub Profile
@KKrisu
KKrisu / keybindings.json
Created November 20, 2017 20:45
VS Code settings
// Place your key bindings in this file to overwrite the defaults
[
{ "key": "ctrl+e", "command": "editor.action.deleteLines",
"when": "editorTextFocus && !editorReadonly" },
{ "key": "alt+up", "command": "editor.action.insertCursorAbove",
"when": "editorTextFocus" },
{ "key": "alt+down", "command": "editor.action.insertCursorBelow",
"when": "editorTextFocus" },
{ "key": "alt+shift+up", "command": "editor.action.moveLinesUpAction",
"when": "editorTextFocus && !editorReadonly" },
@KKrisu
KKrisu / maps_sets.js
Created May 12, 2016 19:55
ES6 Maps & Sets
parent.console.clear();
let o1 = {a: 1};
let o2 = {a: 1};
let o = {};
o[34] = 'a';
o['34'] = 'a';
o[o1] = 'b';
o[o2] = 'c';
@KKrisu
KKrisu / promises.js
Created May 12, 2016 19:54
ES6 Promises
parent.console.clear();
function asyncFunction(id = '', delay = 1000) {
return new Promise((resolve, reject) => {
setTimeout(() => {
// resolve('yeah ' + id);
reject('nooo ' + id);
}, delay);
});
}
@KKrisu
KKrisu / object_literal.js
Created May 12, 2016 19:52
Object literal ES6
parent.console.clear();
// var {a, b} = {a: 1, b: 2};
var a = 1;
var b = 2;
// console.log(a, b);
var bar = 'test';
@KKrisu
KKrisu / templates.js
Created February 16, 2016 13:42
ES6 Strings, Templates
// var text = `something`;
// var template = '' +
// '<div>' +
// '<input>' +
// '</div>';
// console.log(template);
// var template2 = `
@KKrisu
KKrisu / deconstructing.js
Created February 16, 2016 13:38
ES6 Deconstructing
// # Arrays
// var a = ['a', 'b', 'c'];
// var i = a[0];
// var j = a[1];
// var k = a[2];
// var [i, j, k] = a;
// var [i, j, k] = ['a', 'b', 'c'];
@KKrisu
KKrisu / functions.js
Last active January 19, 2016 21:05
JS functions
// FUNCTIONS
// use on babeljs.io/repl
function declaration() {
console.log('declaration');
}
var expression = function() {
@KKrisu
KKrisu / TDZ_Temporal_Dead_Zone.md
Last active August 29, 2015 14:25
ES6 var / let / const

let / const declarations do hoist, but they throw errors when accessed before being initialized (instead of returning undefined as var would)

let x = 'outer scope';
console.log(x); // => outer scope

(function() {

  console.log(x); // => ReferenceError (let is hoisted, but doesn't allow accessing)
  
  console.log(y); // => undefined (var is hoisted and allows accessing)
@KKrisu
KKrisu / fill_array_without_holes.md
Last active August 29, 2015 14:25
JS Sparse Arrays

input: var a = [2, 3, 5]
Task: we want to fill array with undefineds to 6th element.
output: [2, 3, 5, undefined, undefined, undefined]

ES5 solutions:

  1. a.length = 6 result: [2, 3, 5, undefined x 3]
    Problem: this array has sparse elements (holes) on elements 3-5. We can iterate through it like: for (i = a.length ; i-- ;) {}, but when we iterate like: a.forEach(callback) it only goes through iterable values.
@KKrisu
KKrisu / tricks.html
Created April 21, 2015 10:58
CSS HTML tricks
<!-- To avoid spaces between inline-block elements and still have enter between them in the code. -->
<ul>
<li><!--
--></li>
<li><!--
--></li>
</ul>