This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This can be used if the table doesn't have an existing Primary Key */ | |
SELECT @s:=@s+1 as id, <table-name>.* from <table-name>, (SELECT @s:= 0) as s; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongo = require('mongodb'); | |
var monk = require('monk'); | |
var Promise = require('bluebird'); | |
/* DB connection */ | |
var dbName = '' | |
var db = monk('localhost:27017/'+dbName); | |
/* replace <collection-name> with your collection*/ | |
var collection = db.get(<collection-name>); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iptables -A INPUT -p tcp -s localhost --dport 27017 -j ACCEPT | |
iptables -A INPUT -p tcp --dport 27017 -j REJECT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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' & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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! "); | |
}); |