Skip to content

Instantly share code, notes, and snippets.

View anandology's full-sized avatar

Anand Chitipothu anandology

View GitHub Profile
@anandology
anandology / Makefile
Created November 13, 2015 05:42
Makefile to export jupyterhub notebooks for all users to html
#
# 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 June 20, 2015 22:54
Example to try incremental template rendering
<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 April 10, 2015 17:44
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
anandology / math.txt
Last active August 29, 2015 14:17
Are my trainings very expensive?
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 August 29, 2015 14:13
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 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 August 29, 2015 14:07
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
anandology / sa.py
Last active August 29, 2015 14:07
SA like query chaining for web.py 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 = []
@anandology
anandology / parse_voter_rolls.py
Last active May 31, 2019 05:03
Script to extract voter info from voter rolls
"""Script to extract voter info from voter rolls.
This script expects the extracted text file from the voter-list pdf.
It can be done using:
$ pdftotext -layout AC1580002.pdf
"""
import sys
#include <stdio.h>
void hack() {
int start = 0;
int *p=&start;
/* start moving up the stack until we find the marker. */
while (*p != 0x12345678)
p++;
@anandology
anandology / voterlist2pdf.py
Created April 15, 2014 13:16
voterlist2pdf
"""Script to generate voterlist PDF.
References:
* https://pkimber.net/howto/python/modules/reportlab/header-footer.html
* http://www.blog.pythonlibrary.org/2010/09/21/reportlab-tables-creating-tables-in-pdfs-with-python/
* http://www.hoboes.com/Mimsy/hacks/multiple-column-pdf/
"""
from reportlab.platypus import BaseDocTemplate, Frame, PageTemplate, Table, TableStyle
from reportlab.lib.pagesizes import A4, inch, landscape
from reportlab.lib import colors