Skip to content

Instantly share code, notes, and snippets.

View nitinbhojwani's full-sized avatar

Nitin Bhojwani nitinbhojwani

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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)