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 / 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 / first_letter_to_upper_case.js
Created February 2, 2016 09:50
Changing First Letter of a String to Upper Case in Javascript
/* Changing first letter of string to uppercase */
String.prototype.toFirstUpperCase = function(){
return this.slice(0,1).toUpperCase()+this.slice(1);
}
/* Usage */
"example".toFirstUpperCase(); //Example
@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 / nginx_load_balancing_steps.txt
Created February 3, 2016 16:44
Configuring NGINX Load Balancing
/* install nginx */
>>sudo apt-get install nginx
/* comment out other line and add configurations to the below file */
>>sudo vi /etc/nginx/sites-available/default
/* list of server to be added to upstream */
upstream backend {
server <IPADDRESS1>:<PORT>;
@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 [email protected]
/* 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();
@dineshsprabu
dineshsprabu / MySQL_query_adding_auto_increment_field.txt
Created February 8, 2016 12:42
[MySQL] Adding Auto Increment Field to an Existing Table Using SELECT
/* 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;
@dineshsprabu
dineshsprabu / return_promise_from_function.js
Created February 11, 2016 13:17
[NodeJS] Return a promise from your own function
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>);
@dineshsprabu
dineshsprabu / iptable_mongo_allow_localhost_only.sh
Created February 13, 2016 02:27
[IPTable] Make Mongo Accessible only by localhost
iptables -A INPUT -p tcp -s localhost --dport 27017 -j ACCEPT
iptables -A INPUT -p tcp --dport 27017 -j REJECT