Skip to content

Instantly share code, notes, and snippets.


Shubhanshu Mishra napsternxg

View GitHub Profile
napsternxg /
Created Jun 13, 2014
Save current SQL interactive session to file
mysql --user=root --password=root --tee=./SQLSession.out
# To start the logging to the given file from the session use
# mysql> \T
# Logging to file ./SQLSession.out
# To stop logging use
# mysql> \t
View hist.sql
SELECT ROUND(numeric_value, -2) AS bucket,
RPAD('', LOG(COUNT(*)), '*') AS bar
FROM my_table
GROUP BY bucket;
numeric_value = column name
-2 to round in steps of 100. Use -1 for steps of 10 and any positive vale for rounding to nearest decimal
LOG(COUNT(*)) is to make the count on log scale
napsternxg /
Created Feb 11, 2015
Monte Carlo Method for approximating the value of pi using ratio of area of circle inscribed in unit length square.
Using Monte Carlo to find the value of pi.
Intiution: Ratio of area of circle to area of uniq length squre it is inscribed it can be used to approximate pi.
Area of circle = pi/4
Area of square = 1
Ratio = pi/4
Let us generate random points x,y inside the square. The probabilty of the point being inside circle is equal to the above ratio.
Circle centered on origin.
Given: -0.5 <= x,y <= 0.5
A point is inside circle if x**2 + y**2 <= 1/4
napsternxg /
Last active Aug 29, 2015
Generate 10 power range like 1,2,3,..10,20,30,...90,100,200,300...
max_n = 1200
[k for k in range(1,max_n) if k % 10**int(np.log10(k)) == 0]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]
#More computationally effective solution for large max_n
napsternxg /
Created Jun 1, 2015
Toy demo for demostrating the implementation of a dictionary in python
This code snippet explains the implementation of a dictionary using a hashing function.
Problem: Store the marks of student with given roll numbers in a data structure for quick access of marks based on roll number.
Concept: Use a dictionary data structure.
roll_numbers = [9,8,7,2,1,3,4,5]
marks = [10,20,5,13,77,33,2,99]
HASH_CONST=11 # Constant used for hashing. For practical purposes more sophesticated and optimized hash functions are used.
napsternxg / Decrypt.vb
Last active Aug 29, 2015
Decrypt the passwords saved by Totroise SVN
View Decrypt.vb
' SAMPLE: Encryption and decryption using DPAPI functions.
' To run this sample, create a new Visual Basic.NET project using the Console
' Application template and replace the contents of the Module1.vb file with
' the code below.
' Go to the folder %APPDATA%\Subversion\auth\svn.simple
' Copy the Encrypted Value of the password denoted by the line below 2 lines below the line saying password
' Compile the code and put this value in a new file called InputFile.txt and in the same location where you are executing the code.
# coding=UTF-8
import nltk
from nltk.corpus import brown
# This is a fast and simple noun phrase extractor (based on NLTK)
# Feel free to use it, just keep a link back to this post
# Create by Shlomi Babluki
# May, 2013
napsternxg / logit_scale.ipynb
Last active Aug 29, 2015 — forked from pierre-haessig/logit_scale.ipynb
Logit scale, for plotting cumulated probability distributions (matplotlib implementation). Better visualization of the tails
View logit_scale.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import nltk
import string
from collections import Counter
def untokenize(ngram):
tokens = list(ngram)
return "".join([" "+i if not i.startswith("'") and \
i not in string.punctuation and \
i != "n't"
else i for i in tokens]).strip()
* To change this template, choose Tools | Templates
* and open the template in the editor.
* @author napsternxg