Skip to content

Instantly share code, notes, and snippets.

View dineshsprabu's full-sized avatar

Dineshprabu S dineshsprabu

  • Bangalore, India.
View GitHub Profile
@dineshsprabu
dineshsprabu / backup_restore_mongo_db_collection.txt
Created February 13, 2016 12:09
[Mongo] Backup and Restore Mongo DB and Collection
/* dumping a particular collection */
mongodump --host 127.0.0.1 --port 27017 --out <backup-path> --db '<db-name>' --collection '<collection-name>'
/* dumping the entire DB */
mongodump --host 127.0.0.1 --port 27017 --out <backup-path> --db <db-name>
/* restoring backup/dump */
mongorestore --host 127.0.0.1 --port 27017 <backup-path>
@dineshsprabu
dineshsprabu / phantomjs_selenium_webdriver_server.js
Created February 16, 2016 04:50
[Selenium][Phantomjs] How to use PhantomJS web driver server with NodeJS?
/*
Bring up the selenium webdriver server using below command
phantomjs --proxy=104.131.57.228:8090 --proxy-type=http --webdriver=8543
The value in --webdriver is the port binded on wd server
*/
var webdriver = require('selenium-webdriver');
var browser = webdriver.Capabilities.phantomjs();
browser.set('phantomjs.page.settings.userAgent', "Mozilla");
@dineshsprabu
dineshsprabu / phantomjs_service_screen.txt
Created February 16, 2016 12:58
[Phantom] Run PhantomJS WebDriver as Service in Ubuntu
/*
Make sure you have scree on your server using screen --version
if not, install using 'sudo apt-get install screen'.
Make sure you have phantomjs installed and accessible on the path
'/usr/bin/phantomjs'.
*/
screen -dmS test bash -c '/usr/bin/phantomjs -w ; exec bash'
@dineshsprabu
dineshsprabu / install_phantomjs_2_0_ubuntu_14_04_x64.txt
Created February 16, 2016 19:43
[PhantomJS] Installing PhantomJS 2.0 on Ubuntu 14.04 x64
cd ~
/* Below is the direct download link for compiled binary */
wget https://github.com/Pyppe/phantomjs2.0-ubuntu14.04x64/raw/master/bin/phantomjs
/* Making PhantomJS accessible */
mv ~/phantomjs /usr/local/share/phantomjs
ln -s /usr/local/share/phantomjs /usr/local/bin/phantomjs
ln -s /usr/local/share/phantomjs /usr/bin/phantomjs
@dineshsprabu
dineshsprabu / phantomjs_restart_automatically_after_crash.txt
Last active February 17, 2016 20:36
[PhantomJS] How to make PhantomJS to restart automatically after a crash?
/*
Make sure you install phantomjs 2.0 which is really stable
Follow the below link for instructions to install it,
https://gist.github.com/dineshsprabu/543de6b41a7597967ea7
*/
>> vi /usr/bin/runphantom.sh
#!/bin/bash
bash -c '/usr/bin/phantomjs -w ; exec bash' &
@dineshsprabu
dineshsprabu / check_port_for_hosts.js
Created February 18, 2016 10:46
[NodeJS] Check port availability for list of IPs
var net = require('net');
var Promise = require('bluebird');
function checkConnection(host, port, timeout) {
return new Promise(function(resolve, reject) {
timeout = timeout || 10000; // default of 10 seconds
var timer = setTimeout(function() {
reject("timeout");
socket.end();
}, timeout);
@dineshsprabu
dineshsprabu / nodejs_events_example.js
Created February 21, 2016 05:16
[NodeJS] Simple example of Events in NodeJS
/* npm install events */
var EventEmitter = require('events').EventEmitter;
/* creating an event emitter object */
var eventObj = new EventEmitter();
/* making it to listen for the event (catchme) with resulting action (console.log) */
eventObj.on('catchme', function(){
console.log(" You Catched Me! ");
});
@dineshsprabu
dineshsprabu / isString.js
Created February 21, 2016 16:18
[NodeJS] Check a variable String or not in NodeJS
/* Best way to check whether a variable is string or not */
function isString(o) {
return typeof o == "string" || (typeof o == "object" && o.constructor === String);
}
@dineshsprabu
dineshsprabu / starting_mongodb_wiredtiger_storage_engine.txt
Last active February 26, 2016 09:50
[Mongo] Starting MongoDB with wiredTiger Storage Engine
/* mongodb version 3.2 */
mongod --storageEngine wiredTiger --dbpath="./data/"
/* Migrate data from mmapv1 by taking a dump of data from db using mmapv1 and restore on wiredTiger */
/* Ref: https://gist.github.com/dineshsprabu/06f2ede79753ff4f43f5 */
@dineshsprabu
dineshsprabu / oops_example_nodejs.js
Created February 29, 2016 05:43
[NodeJS] OOPS example for NodeJS
var crawler = function(initialIPPool){
//private variable
var privateVariable = 10;
//instance variable;
this.pool = initialIPPool;
//private function
var privateCrawler = function(privatePool){