Skip to content

Instantly share code, notes, and snippets.

Avatar
🏘️
wip

Semyon Bliznyuk sematgt

🏘️
wip
View GitHub Profile
@sematgt
sematgt / scrollbar.scss
Created Jul 21, 2021
custom scrollbar for webkit and firefox
View scrollbar.scss
// scrollbar
// firefox
.textarea {
scrollbar-color: transparentize($color-titanic, 0.92) transparent;
scrollbar-width: thin;
}
// the rest, besides IE
.textarea::-webkit-scrollbar-track
View arrowFunctionsDefinition.js
/*
Differences & Limitations:
Does not have its own bindings to this or super, and should not be used as methods.
Does not have arguments, or new.target keywords.
Not suitable for call, apply and bind methods, which generally rely on establishing a scope.
Can not be used as constructors.
Can not use yield, within its body.
*/
View setTimeoutWithThis.js
// если в колбеке setTimeout используем this, то нужно либо привязка bind, либо стрелочная функция,
// так как setTimeout вызывает колбек в другом контексте и this внутри функции будет глобальным объектом
// wrong
var obj = {
count : 10,
doSomethingLater : function (){
setTimeout(function(){ // the function executes on the window scope
this.count++;
@sematgt
sematgt / curry.js
Created Jan 9, 2021
curry function
View curry.js
function sum(a, b, c) {
return a + b + c;
}
function curry(func) {
return function curried(...args) {
if (args.length >= func.length) {
return func.apply(this, args);
@sematgt
sematgt / arrayCreate.js
Created Jan 9, 2021
array creation via mapping function
View arrayCreate.js
const obj = {
length: 4,
0: 'one',
1: 'two',
2: 'three',
};
console.log(Array.from(obj, (v, i) => {
if (v === undefined) {
return 'no element';
View clock.js
class Clock {
constructor({ template }) {
this.template = template;
}
stop() {
clearInterval(this.timer);
};
@sematgt
sematgt / throttle.js
Last active Jul 24, 2020
throttling decorator js
View throttle.js
function throttle(f, ms) {
return function updater() {
if (updater.ready === false) {
updater.args = arguments;
return;
}
updater.ready = false;
f.apply(this, arguments);
@sematgt
sematgt / spy.js
Created Jul 24, 2020
js spy decorator
View spy.js
function spy(func) {
wrapper.calls = [];
function wrapper() {
wrapper.calls.push([...arguments]);
func(...arguments);
}
return wrapper;
}
@sematgt
sematgt / bench.js
Created Jul 22, 2020
benchmark function js
View bench.js
function loopSumTo(n) {
let sum = 0;
for (let i = n; i >= 1; i--) {
sum += i;
}
return sum;
}
@sematgt
sematgt / calc.js
Created Jul 18, 2020
Editable calculator on plain JS
View calc.js
function Calculator() {
this.operations = {
'+': (a, b) => +a + +b,
'-': (a, b) => a - b,
};
this.validateInputNumbers = function(arr) {
return !(isNaN(arr[0]) || isNaN(arr[2]))
};