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 / commit-msg
Created January 23, 2020 13:11
A "commit-msg" hook to prepend a ticket ID to the first line of the commit message, given that the current branch name has a certain format.
#!/bin/bash
# Functions
get_current_branch() {
local branch_name=$(git symbolic-ref -q HEAD)
branch_name=${branch_name##refs/heads/}
branch_name=${branch_name:-HEAD}
echo "${branch_name}"
}
@estliberitas
estliberitas / generate-toc.js
Last active October 5, 2016 09:30
Generate table of contents for markdown file
'use strict';
const fs = require('fs');
const readline = require('readline');
const filename = process.argv[2];
const stream = fs.createReadStream(filename);
const rl = readline.createInterface({input: stream});
let currentLevel = 0;
const linkRevisions = {};
@estliberitas
estliberitas / generate.js
Last active September 26, 2016 08:37
Asynchronous parser
'use strict';
const fs = require('fs');
const random = (max) => Math.round(1 + Math.random() * (max - 1));
// Simple frame protocol:
// 4 bytes - frame length
// then read amount of bytes specified in frame length
const ws = fs.createWriteStream('parser.data');
@estliberitas
estliberitas / check-markdown-links.js
Last active September 8, 2017 10:11
Script checking that all links with references are present in Markdown file.
@estliberitas
estliberitas / bower-deps-get-versions.sh
Created November 17, 2015 16:21
When you need versions of all the Bower dependencies
#!/bin/bash
# Hi guys!
# If it has happened with you and you got Bower dependencies
# and no `bower.json` file, and all you want is just have
# `bower.json` with those dependencies...
# You'll probably want to get those dependencies and their
# actual versions. And this is what simple command below does:
# Run it in a folder which keeps dependencies
@estliberitas
estliberitas / graph-group-vertices.js
Last active September 22, 2015 13:36
Given a set of edges of multiple graphs return vertice set for each graph
/**
* I had a task to get sets of vertices for multiple graphs
* given a set of edges.
*
* So if input looks like
*
* [A, B], [C, B], [D, C], [K, L], [Z, X], [M, L]
*
* Output should be
*
@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
@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 / 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 / .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