Skip to content

Instantly share code, notes, and snippets.

View YozhEzhi's full-sized avatar

Alexandr Zhidovlenko YozhEzhi

  • Sportmaster Lab
  • Saint-Petersburg, Russia
View GitHub Profile
@YozhEzhi
YozhEzhi / js-pattern-facade
Last active September 16, 2015 11:51
JS pattern Facade
var module = (function() {
var _private = {
i: 5,
get: function() {
console.log('Текущее значение:' + this.i);
},
set: function(val) {
this.i = val;
},
run: function() {
function bind(func, context) {
return function() {
return func.apply(context, arguments);
};
}
var user = {
firstName: "Вася",
sayHi: function() {
alert( this.firstName );
@YozhEzhi
YozhEzhi / object-reference.js
Created August 29, 2016 19:16
Tricky code with js object reference
/**
* Tricky code with object reference
*
* @Reference:
* http://ejohn.org/apps/learn/#13
* http://ejohn.org/apps/learn/#14
* http://stackoverflow.com/questions/22216159/an-object-null-and-behaviour-in-javascript
*/
// Program 1
@YozhEzhi
YozhEzhi / decorator-meaning.js
Last active January 24, 2017 19:14
JS function decoration example
function checkPermissionDecorator(f) {
return function() {
if (isAdmin()) {
return f.apply(this, arguments);
}
alert( 'Недостаточно прав' );
}
}
function save() { ... }
@YozhEzhi
YozhEzhi / es6-composition.js
Last active January 25, 2017 20:04
ES6 composition
const greeter = {
doGreeting(msg) {
console.log(msg);
}
};
const newYearGreeter = {
setYear(year) {
this.year = year;
},
@YozhEzhi
YozhEzhi / rename-git-branch.sh
Last active February 20, 2017 13:26 — forked from lttlrck/gist:9628955
Rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@YozhEzhi
YozhEzhi / debounce.js
Last active February 20, 2017 13:28
JS debounce
function debounce(fn, delay) {
let timeout;
return function(...args) {
const context = this;
clearTimeout(timeout);
timeout = setTimeout(() => fn.apply(context, args), delay);
}
}
@YozhEzhi
YozhEzhi / es6-singleton-module-scoped-instance.js
Last active February 25, 2017 14:53 — forked from dmnsgn/SingletonEnforcer.js
ES6 singleton pattern: constructor returns an instance scoped to the module. Without using the `new` operator.
const singleton = Symbol();
const singletonEnforcer = Symbol();
class Singleton {
constructor(enforcer) {
if (enforcer !== singletonEnforcer) {
throw new Error('Cannot construct singleton');
}
this._type = 'Singleton';
/**
* @author https://github.com/vasanthk/js-bits/blob/master/js/currying.js
* Currying refers to the process of transforming a function with multiple arity (# or args a fn accepts)
* into the same function with less arity.
*
* Briefly, currying is a way of constructing functions that allows partial application of a function’s arguments.
* What this means is that you can pass all of the arguments a function is expecting and get the result,
* or pass a subset of those arguments and get a function back that’s waiting for the rest of the arguments.
*
* Currying vs Partial Application
@YozhEzhi
YozhEzhi / mediaquery-mixin.less
Last active March 2, 2017 09:53 — forked from vestman/media-queries.less
Less: Mixin for building media queries
// Live example: https://goo.gl/xJblcx
.Q(@breaks; @rules;) {
// If there's only one breakpoint:
& when (length(@breaks) = 1) {
@query: ~"(min-width: @{breaks}px)";
@media screen and @query {@rules();};
}
// If there's two breakpoints:
& when (length(@breaks) = 2) {