Skip to content

Instantly share code, notes, and snippets.

View SergeyNarozhny's full-sized avatar

SergeyNarozhny

  • Saint-Petersburg, Russia
View GitHub Profile
@SergeyNarozhny
SergeyNarozhny / events_subscription.js
Created July 21, 2015 14:16
Simple event subscription pattern in NodeJS
var events = require('events'),
net = require('net'),
channel = new events.EventEmitter();
channel.clients = {};
channel.subscriptions = {};
// Add listener on join event
// we save client user object and send
channel.on('join', function(id, client) {
@SergeyNarozhny
SergeyNarozhny / 300914_app.js
Last active August 29, 2015 14:25
AngularJS mobile app example 300914_app
;(function(){
var app = angular.module("app", ['ngRoute', 'ngAnimate', 'mwl.calendar']);
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider){
$routeProvider
.when("/", { templateUrl: "index.html", controller: "IndexCtrl" })
.when("/statuses", { templateUrl: "main.html", controller: "MainCtrl" })
.when("/tasks", { templateUrl: "tasks.html", controller: "TasksCtrl" })
.when("/task/:id", { templateUrl: "task.html", controller: "TasksCtrl" })
@SergeyNarozhny
SergeyNarozhny / partners_personal.js
Last active August 29, 2015 14:25
AngularJS example personal partners desction
var tabs = [{
"text": "Данные пользователя",
"id": "user",
"active": false,
"hide": false
},
{
"text": "Информация о компании",
"id": "company",
"active": false,
@SergeyNarozhny
SergeyNarozhny / offer.js
Last active August 29, 2015 14:25
AngularJS example offer generator
(function(){
var app = angular.module("kp", ['angularFileUpload', 'ngRoute', 'ngAnimate', 'ngSanitize']);
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider){
$routeProvider
.when("/", {
templateUrl: "/offer/edit-template.html",
controller: "KpController",
controllerAs: "kp",
resolve: {
'isAdmin': ['$http', '$q', function($http, $q)
@SergeyNarozhny
SergeyNarozhny / nativetouchslide.js
Last active August 29, 2015 14:25
Native js Touch simple Slider class for mobile
function NativeTouchSlide(selector, minMoveX) {
this.domSelector = document.querySelector(selector) || selector;
this.sCh = this.domSelector.children;
this.checkSelector = !!this.domSelector && this.sCh && this.sCh.length>1;
this.minMoveX = minMoveX || 30;
if (this.checkSelector) {
this.domSelector.addEventListener('touchstart', this.onTouchStart.bind(this));
this.addClass(this.sCh[0], "current");
}
// [1,2,3,4,5].duplicator()
Array.prototype.duplicator = function() {
var arr = this;
if (!this.length) return;
Array.prototype.map.call(this, function(el){ arr.push(el); });
return arr;
}
// sum(1)(2)(3)();
function sum(x) {
@SergeyNarozhny
SergeyNarozhny / eqbintree.go
Created March 25, 2017 18:47
Equivalent Binary Trees
package main
import (
"golang.org/x/tour/tree"
"fmt"
)
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {
#include <cassert>
#include <iostream>
#include <unordered_map>
class Fibonacci final {
public:
static int get(int n) {
assert(n >= 0);
if (n == 0 || n == 1) {
return n;
#include <cassert>
#include <cstdint>
#include <iostream>
template <class Int>;
Int gcd(Int a, Int b) {
assert(a > 0 && b > 0);
Int current_gcd = 1;
for (Int d = 1; d * d <= a; d++) {
def memo(f):
cache = {};
def inner(n):
if n not in cache:
cache[n] = f(n);
return cache[n];
return inner;