Skip to content

Instantly share code, notes, and snippets.

#Node - File Paths

##File Paths Node has a path module which can be used to manipulate paths.

###Normalizing Paths Paths can be stored in different ways and it is neccessary to ensure that the path is standardized.

var path = require('path');
path.normalize('/foo/bar//baz/asdf/quux/..');

update object

var state = {
    id: 1,
    points: 100,
    name: "Goran"
};

var newState = {
@StasKoval
StasKoval / authentication.rb
Created April 11, 2016 11:17 — forked from theCrab/authentication.rb
A Hanami Framework authentication based on JSON Web Tokens.
# lib/authentications/authentication.rb
# @api auth
# Authentication base class
#
module Authentication
def self.included(base)
base.class_eval do
before :authenticate!
expose :current_user
@StasKoval
StasKoval / gist:7af0c5af3e619da45702
Created March 29, 2016 15:09 — forked from shovon/gist:5685073d03829f3b63d0
Haskell-style monads in JavaScript (ES6).
'use strict';
class Monad {
constructor(a) { this._value = a; }
'>>='(f) { return f(this.value()); }
static create(a) { return new Monad(a); }
value() { return this._value; }
}
var val = Monad.create(10) ['>>=']
@StasKoval
StasKoval / maybe.traceur
Created March 29, 2016 04:09 — forked from torgeir/maybe.traceur
An es6 js maybe monad, using generators
log = console.log.bind(console);
maybe = v => {
function * f () {
if (v) yield v;
}
f.bind = f =>
v ? f(v) : maybe();
@StasKoval
StasKoval / pubsub
Created March 2, 2016 20:46 — forked from jarrettmeyer/pubsub
pubsub with NodeJS and AMQPLib
#!/usr/bin/env node
//
// Example of publisher/subscriber pattern in NodeJS, with AMQPLib. This program has been
// demonstrated to work with 500k messages and 4 subscribers.
//
// #WorksOnMyMachine
//
// Usage: ./pubsub
//
@StasKoval
StasKoval / reconnect.js
Created March 2, 2016 04:35 — forked from carlhoerberg/reconnect.js
How to build reconnect logic for amqplib
var amqp = require('amqplib/callback_api');
// if the connection is closed or fails to be established at all, we will reconnect
var amqpConn = null;
function start() {
amqp.connect(process.env.CLOUDAMQP_URL + "?heartbeat=60", function(err, conn) {
if (err) {
console.error("[AMQP]", err.message);
return setTimeout(start, 1000);
}
@StasKoval
StasKoval / rpc_consumer.rb
Created February 27, 2016 07:14 — forked from gaffneyc/rpc_consumer.rb
Basic RPC using RabbitMQ and Bunny
require 'rubygems'
gem 'gaffneyc-bunny'
require 'bunny'
# Example of simple RPC using server named queues
Bunny.open do |amqp|
# Exchange definition
amqp.exchange('reply', :type => :direct)
amqp.exchange('out', :type => :direct)
@StasKoval
StasKoval / README.md
Created February 4, 2016 22:37
Kurento Media Server Installation (Debian Wheezy 64bit)

NOTE: This guide is currently incomplete.

Install general dependencies:

sudo apt-get install git build-essential cmake pkg-config libboost-dev libboost-test-dev \
     libboost-program-options-dev libevent-dev automake libtool flex bison pkg-config \
     libssl-dev libsoup2.4-dev libboost-system-dev libboost-filesystem-dev \
     libogg-dev libtheora-dev libasound2-dev libvorbis-dev libpango1.0-dev \
     libvisual-0.4-dev libffi-dev libgmp-dev
@StasKoval
StasKoval / common.yml
Created February 2, 2016 18:14 — forked from akurkin/common.yml
ROSI docker-compose.yml
#
# Shared definition of ruby microservice
#
microservice:
command: "runsvdir /etc/service"
environment:
PORT: 3000
RAILS_ENV: development
SERVICE_PLATFORM: "mia"
ports: