Skip to content

Instantly share code, notes, and snippets.

View napsternxg's full-sized avatar
🎯
Focusing

Shubhanshu Mishra napsternxg

🎯
Focusing
View GitHub Profile
@napsternxg
napsternxg / saveSQLSession.sh
Created June 13, 2014 16:07
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
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
@napsternxg
napsternxg / monte_carlo_circle.py
Created February 11, 2015 01:00
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
napsternxg / gen10power_range.py
Last active August 29, 2015 14:21
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
napsternxg / toy_dict.py
Created June 1, 2015 07:57
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.
# 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
@napsternxg
napsternxg / logit_scale.ipynb
Last active August 29, 2015 14:27 — forked from pierre-haessig/logit_scale.ipynb
Logit scale, for plotting cumulated probability distributions (matplotlib implementation). Better visualization of the tails
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author napsternxg
*/
function returnFirstPostImage($id){
global $wpdb;
$the_content =$wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id");
$pattern = '!<img.*?src="(.*?)"!';
preg_match_all($pattern, $the_content, $matches);
$image_src = $matches['1'][0];
@napsternxg
napsternxg / Output.txt
Created September 9, 2015 17:20
Haiku Char-RNN
('----- diversity:', 0.2)
----- Generating with seed: " cane
the train's wh"
cane
the train's wh bcattat saobnahhsaaelmemm t ealaeeteueuiirrrrethu uriibiboboo tat stttalalllaer tmettummm p ooor rthhuie rrres aa
('----- diversity:', 0.5)
----- Generating with seed: " cane
the train's wh"
cane