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 / export_multiple_prototypes.js
Last active August 18, 2017 23:54
Export multiple Prototypes from one file in Nodejs
/* protos.js*/
var hey = function(){
}
hey.prototype.sayHey = function(){
console.log('Hey');
}
@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 / async_series_example.js
Created January 19, 2016 05:24
NodeJS Async Series Example
var async = require("async");
//series calls the final callback function on every successful execution of the function in the list.
async.series([
function(callback) {
setTimeout(function() {
console.log("Task 1");
callback(null, 1);
}, 300);
@dineshsprabu
dineshsprabu / async_waterfall_example.js
Created January 19, 2016 05:44
NodeJS Async WaterFall Example
var async = require('async');
async.waterfall(
[
function(callback) {
callback(null, 'Yes', 'it');
},
function(arg1, arg2, callback) {
var caption = arg1 +' and '+ arg2;
callback(null, caption);
@dineshsprabu
dineshsprabu / forever_npm_start
Last active June 9, 2022 12:58
Forever for NPM applications starting with 'npm start'
/*
If your package.json file contains "start": "node ./bin/www"
Use the following command to bring up your app with forever
*/
forever start --minUptime 1000 --spinSleepTime 1000 ./bin/www
/* Check list of forever process using the command */
forever list
@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 / dns_lookup_nodejs.js
Created January 29, 2016 07:34
DNS Lookup from NodeJS
/* npm install dns */
var dns = require('dns');
/* domain name to lookup */
domain_name = 'example.com';
dns.lookup(domain_name, function(err, addresses, family){
/* handle if look up fails inside if condition */
if(err){return console.log(err.stack);}
@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 ');
}