Skip to content

Instantly share code, notes, and snippets.

View syul's full-sized avatar

Serhii Leshchenko syul

  • Odessa, Ukraine
View GitHub Profile
@syul
syul / validation.js
Created February 6, 2019 11:15
validation
function isValid(inStr = '') {
var dictionary = {
'{': '}',
'(': ')',
'[': ']'
}
var stack = [];
inStr = inStr.split('');
for (var i = 0; i < inStr.length; i++) {
if(!dictionary.hasOwnProperty(inStr[i]) && dictionary[stack[stack.length -1]] == inStr[i]) {
@syul
syul / clock.js
Created January 30, 2017 11:10
Clock implementation
var Test = function () {
this.eventsStorage = [];
this.loopHendler = undefined;
};
Test.prototype.on = function (name, cb) {
this.eventsStorage.push({
name: name,
fn: cb
})
@syul
syul / test.ja
Last active January 12, 2017 09:22
test
---------------1--------------
var a = (function(a) {
return function(b) {
return a + b;
}
})(5)(5);
console.log(a);
---------------2--------------
var a = 5;
@syul
syul / findIndex.js
Created December 7, 2016 07:12
find the index of the element in array
var a = ['one', 'two', 'three'];
//what is the index of the element 'two'
var index = a
.map(function (el, index) {
return {
index: index,
value: el
};
})
@syul
syul / collection.js
Created August 4, 2016 09:00
observable collection
'use strict';
const rx = require('rx');
let Collection = function () {
this._data = [];
this._onPush = undefined;
this._observable = rx.Observable.create((observer) => {
this._onPush = function () {
observer.onNext(this._data);
export function Factory(getInstance?: boolean) {
return function (target: any) {
let construct: any = function (constructor: Function, args: any[]) {
var model: any = function () {
return constructor.apply(this, args);
}
Object.keys(constructor.prototype).forEach((key:string) => {
Object.defineProperty(model.prototype, key, Object.getOwnPropertyDescriptor(constructor.prototype, key));
import {Inject} from '../decorators/inject';
import {Factory} from '../decorators/factory';
export interface IModelFactory {
attributes: any;
id: string;
getRelation(relation?: string): ng.IPromise<any>;
update(): ng.IPromise<any>;
delete(model: IModelFactory): ng.IPromise<any>;
add(model?: IModelFactory): ng.IPromise<any>;
@syul
syul / user.js
Created June 14, 2016 20:51
user model
'use strict';
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const MD5 = require('crypto-js/md5');
function setPassword(password) {
return this.encryptPassword(password);
};
@syul
syul / gist:20b708d0c5da2db7140c
Last active November 3, 2015 18:44
The right way to create view
var ContentView = BaseView.extend({
tagName:'div',
className: 'content',
views: {
"root": PickView,
"heroes": HeroesView
},
onInitialize: function (params) {
//reference to the current view
DD.ui.renderer.Fields.prototype.resize = function(component)
{
if (!component.isInDocument())
return;
var element = component.getElement();
if (element.DD_stylesheet)
goog.dom.removeNode(element.DD_stylesheet);
var content = component.getContentElement();
var fields = content.children;
var count = fields.length;