Skip to content

Instantly share code, notes, and snippets.

View nitinbhojwani's full-sized avatar

Nitin Bhojwani nitinbhojwani

View GitHub Profile
@nitinbhojwani
nitinbhojwani / DrugbankScrapper.py
Created October 7, 2015 19:07
Used this python script to scrape data from drugbank.ca
from lxml import html
import requests
import csv
import sys
def fetchResult(z):
print("Starting ... "+str(z))
resultList = []
drugnum = str(z)
@nitinbhojwani
nitinbhojwani / date_to_str.py
Created December 3, 2015 17:58
More Date Madness
def num_to_words(num):
units = ["", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine "]
teens = ["", "eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
tens = ["", "ten", "twenty", "thirty", "forty",
"fifty", "sixty", "seventy", "eighty", "ninety"]
@nitinbhojwani
nitinbhojwani / vowel_count.py
Created January 6, 2016 17:41
Gives vowel count of string entered. Accepted string-> without number i.e alphabets A-Z a-z and all symbo
# Calling
print 'allowed input - any string without number(s) i.e. (^[[\S|\s][\d+][\S|\s]])'
string_input = raw_input('Enter String: ')
# using regex to validate the input
import re
if re.search(r'\d+', string_input):
exit('error - string must not consist any number')
@nitinbhojwani
nitinbhojwani / useful_queries.sql
Created April 24, 2016 13:31
MySQL - Useful Queries
# To Get the list of all the processes
show processlist;
# kill connection or current query of a connection
kill connection <connection_id>
kill query <connection_id>
# Currently Connections Count
show status where `variable_name` = 'Threads_connected';
@nitinbhojwani
nitinbhojwani / stop_all.sh
Created April 27, 2016 08:04
Closes all rabbitmq connections
sudo rabbitmqctl list_connections pid | while read pid ; do sudo rabbitmqctl close_connection ${pid} "go away" ; done
@nitinbhojwani
nitinbhojwani / send_csv
Created April 30, 2016 08:27
Django - Send CSV File as Attachment in Response
def dowload_view(request):
from django.http import HttpResponse
rows = [['name', 'city', 'email'], ['Nitin', 'Bengaluru', 'nitinbhojwani1993@gmail.com']]
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="download.csv"'
writer = csv.writer(response)
for row in rows:
writer.writerow(row)
return response
@nitinbhojwani
nitinbhojwani / nr-server-commands
Created May 3, 2016 13:18
commands to setup newrelic for server monitoring in ubuntu
wget -O- https://download.newrelic.com/548C16BF.gpg | sudo apt-key add -
# create new file
sudo vi /etc/apt/sources.list.d/newrelic.list
# and write this line in above opened file
deb http://apt.newrelic.com/debian/ newrelic non-free
sudo apt-get update
@nitinbhojwani
nitinbhojwani / django_send_mail
Created May 4, 2016 18:33
Django - Send a Mail with Attachment File like CSV
# Import EmailMessage class - https://docs.djangoproject.com/en/1.9/topics/email/#django.core.mail.EmailMessage
from django.core.mail import EmailMessage
email = EmailMessage('... Subject ...', '... Body ...', 'from-email',
['to-email-1', 'to-email-2'], ['bcc-email-1', 'bcc-email-2'])
# now let's create a csv file dynamically
import csv, StringIO
attachment_csv_file = StringIO.StringIO()
writer = csv.writer(attachment_csv_file)
@nitinbhojwani
nitinbhojwani / nmonitor.sh
Created March 23, 2017 07:28
Monitor individual process metrics - nmonitor usage and shell script.
#!/bin/bash
if [ "$#" -ne 2 ]; then
echo "usage error: sh nmonitor.sh <pid> <time_to_monitor_in_seconds>";exit 1
fi
pid=$1
time=$2
#read -p "Please enter your process Id: " pid
@nitinbhojwani
nitinbhojwani / do_telnet.py
Created July 26, 2017 10:49
Send message over TCP connection given host and port
def do_telnet(host, port, message):
import telnetlib
tn = telnetlib.Telnet(host, port)
ret = tn.write(message + '\n')
print "sent the message: %s" % message
tn.close()
def send_thru_socket(host, port, message):
TCP_IP = host