Skip to content

Instantly share code, notes, and snippets.

const H = require('highland')
const Promise = require('bluebird')
const _ = require('lodash')
const Writable = require('stream').Writable;
const SIZE = 10
function grabFromApi(i) {
console.log('start reading', i)
return Promise.delay(1000).then(() => {
PG_USER=booking PG_PASSWORD=booking psql -h localhost -p 15432 booking -c 'SELECT COUNT(*) FROM Hotels;'
var pg = require('pg');
var client = new pg.Client();
// connect to our database
client.connect(function (err) {
if (err) throw err;
// execute a query on our database
client.query('SELECT COUNT(*) FROM Hotels;', function (err, result) {
@kharandziuk
kharandziuk / explanation.md
Last active April 27, 2017 12:26
Unnecessary promise wrapping explanation

Consider you are developing a math library which has a function isPi.

function isPi(x) {
  return x === 3.14
}

Now you are saying something like - We don't want to care where do we take the data(db, network, etc). So, we will receive a promise

@kharandziuk
kharandziuk / flatmap.js
Created January 24, 2017 16:03
strange flatmap behaviour
const request = require('superagent');
const _ = require('lodash');
const H = require('highland');
const Promise = require('bluebird');
function getLocations() {
const call = request
.get('http://viatorapi.viator.com/service/taxonomy/locations')
.query({apiKey: API_KEY})
return Promise.resolve(call)
.then((res) => res.body.data)
@kharandziuk
kharandziuk / playbook.yml
Created January 20, 2017 15:43
ansible playbook for postgis
# -*- mode: yaml-*-
# vi: set ft=yaml sw=2 ts=2 :
- name: Configure scala study machine
hosts: all
sudo: True
vars:
pg_version: 9.4
pg_conf: "/etc/postgresql/{{ pg_version }}/main/postgresql.conf"
pg_hba: "/etc/postgresql/{{ pg_version }}/main/pg_hba.conf"
@kharandziuk
kharandziuk / playbook.yml
Created February 21, 2016 08:45
Install node and npm with ansible on ubuntu box
# now you don't need to use curl
tasks:
- apt_key:
url: "https://deb.nodesource.com/gpgkey/nodesource.gpg.key"
# change trusty for your distributive name
- apt_repository: repo="deb https://deb.nodesource.com/node_5.x trusty main" state=present
class N
constructor: (val, next) ->
@val = val
@next = next
assert = require('assert')
reverse = (node, prev) =>
if not node?
assert(prev?)
.phony: check
check1:
curl -v http://develop.cricketduel.inprogress.rocks/
check2:
curl -i http://develop.cricketduel.inprogress.rocks/
t:
def rotations(num):
str_num = str(num)
result = set()
for mid in xrange(len(str_num)):
result.add(
str_num[mid:] + str_num[:mid]
)
return result