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 / 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]
return (search(array, sum - array[head], expected, head+1, tail) or search(array, sum - array[tail], expected, head, tail-1))
anandology /
Last active Jun 24, 2016
Code reproduce a bug caused with Python 3
"""Program to reproduce a bug that appears when used with Python 3.
How to reproduce:
1. Run the dev server
$ python
2. Open the following URL in your browser.
anandology /
Created Mar 18, 2016
Function to plot the decision boundaries of a scikit-learn classification model.
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 / 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)
anandology / index.html
Created Jun 20, 2015
Example to try incremental template rendering
View index.html
<head><title>Incremental Tornado Templates</title></head>
<h1>Incremental Tornado Templates</h1>
{% import time %}
{% for i in range(n) %}
<li>{{ i }}</li>
{{ time.sleep(delay) or "" }}
anandology /
Created Apr 10, 2015
Script to find the number of emails in the given gmail account
"""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 / 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 /
Last active Aug 29, 2015
Python script to select winners at random using donation amount as weight
"""Script to pick N random entries from a file using donation amount as weight.
USAGE: python filename num-winners
import random
import sys
import argparse
import time
def weighted_choice(elements, weight_func):
anandology /
Last active Aug 29, 2015
tcpdump analysis of ADE4

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 /
Last active Aug 29, 2015
SA like query chaining for db
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.