View saveSQLSession.sh
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, | |
COUNT(*) AS COUNT, | |
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 |
View monte_carlo_circle.py
""" | |
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 |
View gen10power_range.py
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 |
View toy_dict.py
""" | |
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. |
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. |
View np_extractor.py
# 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 | |
# http://thetokenizer.com/2013/05/09/efficient-way-to-extract-the-main-topics-of-a-sentence/ | |
# Create by Shlomi Babluki | |
# May, 2013 |
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.
View phrases.py
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() |
View ObjectOperations.java
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
/** | |
* | |
* @author napsternxg | |
*/ |
OlderNewer