Comparing ES7 and core.async
ES7 | core.async |
---|---|
async function() {...} |
(fn [] (go ...)) |
await ... |
(<! ...) |
await* or Promise.all(...) |
(doseq [c ...] (<! c)) |
from pymongo import MongoClient | |
from bson import SON | |
from time import mktime | |
from datetime import datetime, timedelta | |
from time import mktime | |
from pprint import pprint | |
from random import randrange, randint, choice | |
def seed_position_times(db): |
# put this file in home folder | |
date_format %d/%b/%Y | |
log_format %h %^[%d:%^] "%r" %s %b "%R" "%u" |
// resolution is [width, height] structure | |
// Evaluate resolution by width (height doesn't matter, just keep it proportional) | |
function evalResolutionByWidth(requiredWidth, actualResolution) { | |
var actualWidth = actualResolution[0]; | |
var actualHeight = actualResolution[1]; | |
if (actualWidth > requiredWidth) { | |
var scale = actualWidth / requiredWidth; | |
return [requiredWidth, Math.round(actualHeight / scale)]; | |
} else { |
function npm_package_is_installed { | |
if [ $(npm list --depth 0 --parseable true "${2}" | grep "${1}$") ]; then | |
echo "1" | |
else | |
echo "0" | |
fi | |
} | |
# npm_package_is_installed gulp | |
# npm_package_is_installed gulp -g |
class PPrintMixin: | |
def __str__(self): | |
return '<{}: id={!r}>'.format(type(self).__name__, self.id) | |
def __repr__(self): | |
attrs = [] | |
for name in self._fields.keys(): | |
value = getattr(self, name) | |
if isinstance(value, (Document, EmbeddedDocument)): | |
attrs.append('\n {} = {!s},'.format(name, value)) |
let Rx = require(`rx`) | |
function makeRequestProxies(drivers) { | |
let requestProxies = {} | |
for (let name in drivers) { | |
if (drivers.hasOwnProperty(name)) { | |
requestProxies[name] = new Rx.ReplaySubject(1) | |
} | |
} | |
return requestProxies |
Object Oriented Programming | |
I Objects / Classes are main units of design | |
II Objects are namespaces (expression problem, duality with Functional Programming) | |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | |
III Delegation / Inheritance (type dependency) | |
IV Constructors (vs data constructors) | |
V Mutability (shared state) | |
VI Fluent API (http://paqmind.com/blog/fluent-api-debunked/) | |
VII Instance |
ES7 | core.async |
---|---|
async function() {...} |
(fn [] (go ...)) |
await ... |
(<! ...) |
await* or Promise.all(...) |
(doseq [c ...] (<! c)) |
This article shows how to apply Node.js Stream and a bit of Reactive programming to a real(tm) problem. The article is intended to be highly practical and oriented for an intermediate reader. I intentionally omit some basic explanations. If you miss something try to check the API documentation or its retelling(e.g.: this one)
So, lets start from the problem description. We need to implement a simple web scraper which grabs all the data from some REST API, process the data somehow and inserts into our Database. For simplicity, I omit the details about the actual database and REST API(in real life it was the API of some travel fare aggregator website and a Pg database)
Consider we have two functions(code of the IO simulator functions and the other article code is here):
getAPI(n, count) // pseudo API ca
Look for more options here: https://www.tailwindawesome.com