Skip to content

Instantly share code, notes, and snippets.

View ivan-kleshnin's full-sized avatar
🏠
Working from home

Ivan Kleshnin ivan-kleshnin

🏠
Working from home
View GitHub Profile
@ivan-kleshnin
ivan-kleshnin / gist:6b17b0f6ac863cb17217
Created October 9, 2014 09:40
MongoDB: order positions by timedelta between CLOSE_DATE and NOW
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):
@ivan-kleshnin
ivan-kleshnin / .goaccessrc
Last active August 29, 2015 14:10
How to reveal hackers and spammers in standard nginx logs (OS X instruction)
# put this file in home folder
date_format %d/%b/%Y
log_format %h %^[%d:%^] "%r" %s %b "%R" "%u"
@ivan-kleshnin
ivan-kleshnin / lwip.utils.js
Last active August 29, 2015 14:12
Resize with lwip
// 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 {
@ivan-kleshnin
ivan-kleshnin / bash.npm_package_is_installed.sh
Created January 31, 2015 12:25
Check npm package is installed
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))
@staltz
staltz / slim-cycle-core.js
Created September 22, 2015 12:35
Cycle.js without sanity checks and comments in a single file. Don't use this, use normal Cycle.js. :-)
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
@shaunlebron
shaunlebron / es7coreasync.md
Last active July 28, 2018 07:58
es7 vs core.async

Comparing ES7 and core.async

ES7 core.async
async function() {...} (fn [] (go ...))
await ... (<! ...)
await* or Promise.all(...) (doseq [c ...] (<! c))
@kharandziuk
kharandziuk / article.md
Last active March 2, 2021 03:41
Node.js Streams and Reactive Programming Primer

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