Skip to content

Instantly share code, notes, and snippets.

@avovsya
avovsya / maybe-example.js
Last active December 14, 2015 09:38
Another one impletementation of "maybe" monad in JavaScript
var o = { data: { success: true } }
maybe('o')
.with('data')
.with('success')
.if(function(x){
return x === true;
})
.do(function(x){
if(x === null){return "if failed"} else{ return "if succeded"}
config.json
reading-image.png
@avovsya
avovsya / gist:e23aaea3e8364934a58b
Created May 29, 2014 13:39
Helper to work with cassandra's inverted indeces table. Allows to partition index key to multiple row keys.
"use strict";
var slug = require('slug');
var hashFunctions = {
/**
* Return string hash, based on first two symbols of string
* @param {string} str Str to calculate the hash
*/
"two_symbol_hash": function (str) {
@avovsya
avovsya / rabbitdel.sh
Created August 13, 2014 12:44
Script to delete RabbitMQ queues by pattern. Took from http://stackoverflow.com/a/18785918/1130863
for word in "$@"
do
args=true
newQueues=$(rabbitmqctl list_queues name | grep "$word")
queues="$queues
$newQueues"
done
if [ $# -eq 0 ]; then
queues=$(rabbitmqctl list_queues name | grep -v "\.\.\.")
fi
@avovsya
avovsya / gist:a3c78494a99c8547f0d7
Created August 13, 2014 12:51
Command line tools
# Count greped lines
grep pattern | wc -l
# Count greped lines, and display them
grep pattern | tee /dev/tty | wc -l
@avovsya
avovsya / service.js
Last active August 29, 2015 14:05
Postgres db service wrapper
var pg = require('pg');
var Service = function (connectionConfig) {
this.connectionConfig = connectionConfig;
this._client = null;
this._releaseClient = null;
this.isConnected = false;
};
Service.prototype._connection = function (callback) {
@avovsya
avovsya / casper-bit.js
Last active July 13, 2017 16:52
Web scraping with node and casper
var casper = require('casper').create({
pageSettings: {
// javascriptEnabled: false
}
});
var system = require('system');
var options = casper.cli.options;
@avovsya
avovsya / ssh-tail.sh
Created December 15, 2015 09:35
Tail and Grep log files from multiple servers
cat <(ssh server1 sudo tail -f /var/log/log.log) <(ssh server2 sudo tail -f /var/log/log.log) | grep /api/1/test >> hits
@avovsya
avovsya / ssh-tail-count.sh
Created December 15, 2015 09:50
Tail remote logs, grep and count lines
cat <(ssh server1 sudo tail -f /var/log/test.log) <(ssh server2 sudo tail -f /var/log/test.log) | grep /api/1/test >> hits & watch wc -l hits
@avovsya
avovsya / split-kinesis-shard.sh
Created April 11, 2016 08:59
Split Amazon Kinesis shard using aws-cli
# Get list of streams
aws kinesis list-streams --region {region: us-east-1}
# Get list of shards for a stream
aws kinesis describe-stream --region {region: us-east-1} --stream-name {stream_name}
# Split
aws kinesis split-shard --region {region: us-east-1} --stream-name {stream_name} --shard-to-split {shard_id_to_split} --new-starting-hash-key {new_starting_hash_key:(shard ending hashkey / 2)}
# Check that it worked
aws kinesis describe-stream --region {region: us-east-1} --stream-name {stream_name}