Skip to content

Instantly share code, notes, and snippets.

View SergeyNarozhny's full-sized avatar

SergeyNarozhny

  • Saint-Petersburg, Russia
View GitHub Profile
@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");
}
@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 / 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 / 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 / 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 / app_logger.js
Last active August 29, 2015 14:25
NodeJS simple middleware logger
#logger.js
module.exports = function(request, response, next)
{
var start = +new Date(),
stream = process.stdout,
url = request.url,
method = request.method;
response.on("finish", function(){
var duration = +new Date() - start,
@SergeyNarozhny
SergeyNarozhny / eh.js
Created July 21, 2015 13:28
AngularJS $exceptionHandler decorator
app.config(function($provide){
$provide.decorator("$exceptionHandler", ["$delegate", function($delegate){
return function(exception, cause)
{
exception.message = "Some exception message";
$delegate(exception, cause); //call out basic implementation
alert(exception.message); //our custom alert
}
}]);
});
@SergeyNarozhny
SergeyNarozhny / carrying.js
Last active September 30, 2016 07:37
Native js function carrying realizations
//#1
var attitude = function(original, replacement, source)
{
return function (source)
{
return source.replace(original, replacement);
}
}
var slimify = attitude(/big test mark/ig, "smallone");
@SergeyNarozhny
SergeyNarozhny / throttle.js
Created July 21, 2015 13:09
Throttle native js realization
function throttle(method, context)
{
clearTimeout(method.tId);
method.tId = setTimeout(function(){
method.call(context);
}, 100);
}
//usage example
window.onresize = function()
@SergeyNarozhny
SergeyNarozhny / ymaps.js
Last active August 29, 2015 14:08
Yandex map popup with required load (by modules)
var map = $("#map_wrapper"), editorParams = {
wayPointFinishDraggable: false,
addWayPoints: false,
editorDrawOver: false,
wayPointFinishIconLayout: "default#image",
wayPointFinishIconImageHref: '/new/include/img/footer-map-point.png',
wayPointFinishIconImageSize: [171, 48],
wayPointFinishIconImageOffset: [-55, -48],
};