Skip to content

Instantly share code, notes, and snippets.

View estliberitas's full-sized avatar

Alexander Makarenko estliberitas

  • Hire me
  • Stockholm, Sweden
View GitHub Profile
@estliberitas
estliberitas / reset.js
Created January 3, 2013 23:27
Node.js script which makes Tor change identity (i.e. IP address)
/**
* Created with IntelliJ IDEA.
* User: Alexander <estliberitas> Makarenko
* Date: 04.01.13
* Time: 3:25
*/
'use strict';
var fs = require('fs')
, net = require('net')
@estliberitas
estliberitas / install.sh
Created September 29, 2014 10:04
Puppet local installation
wget https://apt.puppetlabs.com/puppetlabs-release-trusty.deb
sudo dpkg -i puppetlabs-release-trusty.deb
sudo apt-get update
sudo apt-get install puppet
sudo puppet resource service puppet ensure=running enable=true
sudo puppet resource cron puppet-apply ensure=present user=root minute=30 command='/usr/bin/puppet apply $(puppet apply --configprint manifest)'
@estliberitas
estliberitas / test-stringify-circular.js
Last active October 7, 2020 12:22
JSON.stringify() - debug TypeError: Converting circular structure to JSON
'use strict';
function replacer() {
var objects = [];
return function(key, value) {
if (typeof value === 'object' && value !== null) {
var found = objects.some(function(existing) {
return (existing === value);
});
@estliberitas
estliberitas / pool.js
Last active August 29, 2015 14:15
Simple pool
'use strict';
module.exports = pool;
function pool(options) {
var instances = options.config.map(function() {
return null;
});
function noop() {
@estliberitas
estliberitas / object-to-array.js
Created February 24, 2015 18:22
Object to Array using Object.keys and Array#reduce
var o = {
a: 1,
b: 2,
c: 3
};
Object.keys(o).reduce(function(out, key) {
out.push({
key: key,
value: o[key]
@estliberitas
estliberitas / array-to-object.js
Created February 24, 2015 18:23
Array to Object using Array#reduce
var a = [{key: 'a', value: 1}, {key: 'b', value: 2}, {key: 'c', value: 3}];
a.reduce(function(out, item) {
out[item.key] = item.value;
return out;
}, {}); // {a: 1, b: 2, c: 3}
@estliberitas
estliberitas / .travis.yml
Created April 19, 2015 18:02
Apache ZooKeeper configuration for Travis CI
# Use following configuration to run ZooKeeper while executing tests
before_install:
# Add repository key
- "curl -s http://archive.cloudera.com/cdh4/ubuntu/precise/amd64/cdh/archive.key | sudo apt-key add -"
- "wget http://archive.cloudera.com/cdh4/one-click-install/precise/amd64/cdh4-repository_1.0_all.deb"
# Add Cloudera repository
- "sudo dpkg -i cdh4-repository_1.0_all.deb"
- "sudo apt-get update -qq"
# Install ZooKeeper
@estliberitas
estliberitas / coollex.js
Created June 1, 2015 08:37
JavaScript cool-lex implementation
// Below 3 versions of cool-lex loopless algorithm are listed.
// The only difference between them is data structure used to
// store a bit string: Number, Array, Buffer (node.js).
//
// Number version, as you may guess, will work properly for
// s + t < 32 thus bitwise / shift operators operate on 32bit
// integers.
function coollexArray(s, t, cb) {
@estliberitas
estliberitas / gen-markdown-contents.js
Last active August 29, 2015 14:23
Generate contents for Markdown file (uses Node.js)
'use strict';
// Use it like this: node gen-markdown-contents.js FILENAME
var fs = require('fs');
var lines = fs.readFileSync(process.argv[2]).toString('utf8').split(/\n\r?/);
var links = {};
var contents = lines.map(lineMapper).filter(Boolean).map(toListItem);
function getNextHash(link) {
@estliberitas
estliberitas / changelog-add-dependencies.js
Created September 17, 2015 11:31
Update Changelog in README.md when dependencies are updated in package.json
#!/usr/bin/env node
/**
* In private projects I usually keep changelog in README.md.
*
* It looks like:
*
* ## Changelog
*
* ### Version