Skip to content

Instantly share code, notes, and snippets.

View sematgt's full-sized avatar
🏘️
wip

Semyon Bliznyuk sematgt

🏘️
wip
View GitHub Profile
@sematgt
sematgt / scrollbar.scss
Created July 21, 2021 15:39
custom scrollbar for webkit and firefox
// scrollbar
// firefox
.textarea {
scrollbar-color: transparentize($color-titanic, 0.92) transparent;
scrollbar-width: thin;
}
// the rest, besides IE
.textarea::-webkit-scrollbar-track
/*
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.
*/
// если в колбеке 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 January 9, 2021 09:09
curry function
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 January 9, 2021 09:09
array creation via mapping function
const obj = {
length: 4,
0: 'one',
1: 'two',
2: 'three',
};
console.log(Array.from(obj, (v, i) => {
if (v === undefined) {
return 'no element';
@sematgt
sematgt / clock.js
Created July 27, 2020 06:39
js clock
class Clock {
constructor({ template }) {
this.template = template;
}
stop() {
clearInterval(this.timer);
};
@sematgt
sematgt / throttle.js
Last active July 24, 2020 07:45
throttling decorator 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 July 24, 2020 06:51
js spy decorator
function spy(func) {
wrapper.calls = [];
function wrapper() {
wrapper.calls.push([...arguments]);
func(...arguments);
}
return wrapper;
}
@sematgt
sematgt / bench.js
Created July 22, 2020 13:40
benchmark function js
function loopSumTo(n) {
let sum = 0;
for (let i = n; i >= 1; i--) {
sum += i;
}
return sum;
}
@sematgt
sematgt / calc.js
Created July 18, 2020 08:43
Editable calculator on plain JS
function Calculator() {
this.operations = {
'+': (a, b) => +a + +b,
'-': (a, b) => a - b,
};
this.validateInputNumbers = function(arr) {
return !(isNaN(arr[0]) || isNaN(arr[2]))
};