Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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: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) {
config.json
reading-image.png
@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"}