Skip to content

Instantly share code, notes, and snippets.

View narqo's full-sized avatar
🌕
Berlin, +15°

Vladimir Varankin narqo

🌕
Berlin, +15°
View GitHub Profile
@narqo
narqo / arguments.sh
Created March 14, 2015 14:03
Essential shell scripting
# Parsing and processing script arguments
while [ $# -gt 0 ]; do
case $1 in
-p)
shift
PORT=$1
;;
--pbuilder-basetgz=*)
BASETGZ="$(echo $1 | cut -d = -f 2)"
;;
if(global.Intl) {
global.Intl = require('intl');
}
var IntlMessageFormat = require('intl-messageformat');
var formats = {
number : {
rur : {
style : 'currency',
function Ctor(param1, param2, param3) {
this._param1 = param1;
this._param2 = param2;
this._param3 = param3;
}
Ctor.create = function(p1, p2, p3) {
return new this(p1, p2, p3);
}
@narqo
narqo / cococo.js
Created June 18, 2014 22:19
A silly generator based flow-control example
/** @module cococo */
/**
* A silly control-flow runner
* @param {GeneratorFunction} gen
* @returns {Function}
*/
function cococo(gen) {
return function(done) {
var g = gen();
@narqo
narqo / scan-async.js
Created January 12, 2014 13:14
Comparison of different ways to implement `fs#scan()`
var fs = require('fs'),
path = require('path');
/**
* Async version of `scan`
*
* @example
* var scan = require('./scan-async');
* scan('<dir>', function(err, files) {
* // do something with `files` object
@narqo
narqo / producer-consumer.js
Created December 29, 2013 19:41
"Producer-Consumer" example implementation using generators. See http://en.wikipedia.org/wiki/Deterministic_concurrency#Comparison_with_generators for more about coroutine
/* jshint esnext:true */
/**
* "Producer-Consumer" implementation using generators.
* @see http://en.wikipedia.org/wiki/Deterministic_concurrency#Comparison_with_generators
*/
var SIZE = 3,
queue = newQueue();
@narqo
narqo / nav.css
Created December 19, 2013 23:20
Simple example of i-bem.js usage to one way of behaviour driven development. See http://toddmotto.com/stop-toggling-classes-with-js-use-behaviour-driven-dom-manipulation-with-data-states/#comment-1170723194 for refer
.nav
{
background: #2284B5;
color: #fff;
border-radius: 3px;
}
.nav__toggle
{
padding: 5px 10px;
/*borschik:include:i-bem.js*/;
modules.require(['i-bem'], function(BEM) {
BEM.decl('block1', {
method1 : function() {
console.log('m1');
}
});
@narqo
narqo / global.bemtree.js
Last active December 29, 2015 00:38
Yet another concept of async BEMTREE templates
block('global').def(function() {
var data = this.param('req'),
host = this.param('apiHost'),
params = {};
return async(function() {
try {
var result = await(this.httpInvoke({ host : host, path : '/some/api' });
var status = result.status;
@narqo
narqo / parser.js
Last active December 22, 2015 00:58
Test for bem-xjst
var bemxjst = require('bem-xjst'),
FN_RE = /^function(?:\s+\w+)?\s*\([^\)]*\)\s*\{|\}$/g;
function noop() {
return '[sorry]';
}
function parse(fn) {
var body = fn.toString().replace(FN_RE, '').trim();