Skip to content

Instantly share code, notes, and snippets.

Anand Chitipothu anandology

Block or report user

Report or block anandology

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@anandology
anandology / search-sum.rb
Created Jul 3, 2016
Given an array and a number , how do I find that sum of any consecutive array elements equals the number?
View search-sum.rb
def search(array, sum, expected, head, tail)
if head > tail
return false
elsif sum == expected
return [head, tail]
else
return (search(array, sum - array[head], expected, head+1, tail) or search(array, sum - array[tail], expected, head, tail-1))
end
end
@anandology
anandology / unibug.py
Last active Jun 24, 2016
Code reproduce a web.py bug caused with Python 3
View unibug.py
"""Program to reproduce a bug that appears when used with Python 3.
How to reproduce:
1. Run the dev server
$ python unibug.py
http://0.0.0.0:8080/
2. Open the following URL in your browser.
@anandology
anandology / plot_decision_boundaries.py
Created Mar 18, 2016
Function to plot the decision boundaries of a scikit-learn classification model.
View plot_decision_boundaries.py
def plot_decision_boundaries(X, y, model_class, **model_params):
"""Function to plot the decision boundaries of a classification model.
This uses just the first two columns of the data for fitting
the model as we need to find the predicted value for every point in
scatter plot.
One possible improvement could be to use all columns fot fitting
and using the first 2 columns and median of all other columns
for predicting.
@anandology
anandology / Makefile
Created Nov 13, 2015
Makefile to export jupyterhub notebooks for all users to html
View Makefile
#
# Makefile to export ipython notebooks in each user home to html
# The output goes to build/$USER/$FILENAME.html
#
SOURCES=$(wildcard /home/*/*.ipynb)
TARGETS=$(shell echo $(SOURCES) | sed -e 's/.ipynb/.html/g' -e 's,/home/,build/,g')
default: $(TARGETS)
debug:
@anandology
anandology / index.html
Created Jun 20, 2015
Example to try incremental template rendering
View index.html
<html>
<head><title>Incremental Tornado Templates</title></head>
<body>
<h1>Incremental Tornado Templates</h1>
{% import time %}
<ul>
{% for i in range(n) %}
<li>{{ i }}</li>
{{ time.sleep(delay) or "" }}
@anandology
anandology / email-count.py
Created Apr 10, 2015
Script to find the number of emails in the given gmail account
View email-count.py
"""Script to count the emails received in a gmail account and posts it to a web hook.
"""
import imaplib
import optparse
import json
import urllib2
def count_emails(username, password, folder="INBOX"):
"""Returns the number of emails in specified folder.
"""
@anandology
anandology / math.txt
Last active Aug 29, 2015
Are my trainings very expensive?
View math.txt
Someone on twitter said my python course is too expensive.
Here are some quick calculations to show cost-of-class-per-day is not any more expensive than typical college education.
Tution fee per year for college education - Rs. 1,00,000
Number of working days = 200
Fee per day - 100000/200 = 500
Number of students in class = 60
cost per class per day = 60*500 = 30000
@anandology
anandology / winners.py
Last active Aug 29, 2015
Python script to select winners at random using donation amount as weight
View winners.py
"""Script to pick N random entries from a file using donation amount as weight.
USAGE: python winners.py filename num-winners
"""
import random
import sys
import argparse
import time
def weighted_choice(elements, weight_func):
@anandology
anandology / 0-readme.md
Last active Aug 29, 2015
tcpdump analysis of ADE4
View 0-readme.md

After reading [Adobe is Spying on Users, Collecting Data on Their eBook Libraries][1] article by [Nate Hoffelder][2], I didnt an test my self to see how it is effecting [Internet Archive][3]'s [Open Library][4] lending program.

Here are the things that I did, in this order.

  • borrowed a book from OL in epub format
  • started tcpdump
  • started ADE
  • opened the book in ADE
  • read it
  • read some other epub book
@anandology
anandology / sa.py
Last active Aug 29, 2015
SA like query chaining for web.py db
View sa.py
import web
class SelectQuery:
def __init__(self, tables):
if isinstance(tables, basestring):
tables = [tables]
self._tables = tables
self._columns = "*"
self._where = web.SQLQuery("")
self._order = []
You can’t perform that action at this time.