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 / following_links_scrapy_spider.py
Created November 28, 2015 05:01
Following Links in Scrapy Spider
@dineshsprabu
dineshsprabu / setting_id_as_string_mongodb_nodejs.js
Last active December 30, 2015 03:44
Setting _id as raw String on Mongo from NodeJS (Solution: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters)
/* The unwanted complication on monk ('_id' as HEX 12-24 bytes) can be handled by using native mongo driver */
var MongoClient = require('mongodb').MongoClient;
/* values to be changed as per need */
var input = {'_id':'string_value'};
var collection_name = 'collection_name';
var db_name = 'db_name';
MongoClient.connect("mongodb://localhost:27017/"+db_name, function(err, db) {
@dineshsprabu
dineshsprabu / replace_all.js
Created January 1, 2016 05:20
Replace All Possibilities in a String
String.prototype.replaceAll = function(replace_string,replace_with){
return this.split(replace_string).join(replace_with);
}
@dineshsprabu
dineshsprabu / monogd_as_service
Created January 28, 2016 18:38
Keep your mongod running on the server as a service
/* The following command will make a fork form the main process
It will log console data to the log file mentioned */
mongod --dbpath='./data' --fork --logpath ./mongod.log
@dineshsprabu
dineshsprabu / validate_email_nodejs.js
Created January 29, 2016 07:49
Validate email id on nodejs
/* npm install validator */
var validator = require('validator');
/* email id to check */
var email_id = 'email@domain.com'
/* validator.isEmail can do the job for us */
if (validator.isEmail(email_id)){
console.log(' valid email ');
}
@dineshsprabu
dineshsprabu / check_mxrecord_nodejs.js
Created January 29, 2016 09:16
Check MX Record for domains
/* npm install dns */
var dns = require('dns');
/* domain name to check for record */
domain_name = '<domain-name>';
/* dns.resolveMx can do the job for us */
dns.resolveMx(domain_name, function(err, addresses){
if(err){ return console.log(err.stack);}
console.log(addresses);
@dineshsprabu
dineshsprabu / iptable_rule_allow_ssh_deny_all.txt
Last active February 3, 2016 09:03
IPTable Rule for Allowing SSH and Denying all other ports
/* iptable rule for droping connections through eth0 to all ports except 22(ssh) */
>> iptables -A INPUT -i eth0 -p tcp ! --dport 22 -j DROP
/* Check applied rule */
>> iptables -L
target prot opt source destination
DROP tcp -- anywhere anywhere tcp dpt:!ssh
@dineshsprabu
dineshsprabu / mysql_query_email_inside_angular_braces.txt
Last active February 5, 2016 08:08
MySQL query to extract email id inside angular braces < >
select replace(substring(`email_field`, LOCATE('<', `email_field`)+1),substring(`email_field`, LOCATE('>', `email_field`)),'') from table_name
@dineshsprabu
dineshsprabu / solution_mongodb_cannot_read_property_undefined.txt
Created February 8, 2016 04:52
[Solution] "Cannot read property 'name' of undefined"
/* installing below version of mongodb can fix the problem for now */
npm install mongodb@1.4.4
/* for package.json, make an entry as below */
"mongodb":"^1.4.x"
@dineshsprabu
dineshsprabu / connect_mongodb_monk_nodejs.js
Created February 8, 2016 05:02
Connecting to MongoDB using Monk from NodeJS
var mongo = require('mongodb');
var monk = require('monk');
var db_name = ''
var db = monk('localhost:27017/'+db_name);
var collection = db.get('collection_name');
collection.find({}, function(err,docs){
console.log(docs);
db.close();