Skip to content

Instantly share code, notes, and snippets.

View anandology's full-sized avatar

Anand Chitipothu anandology

View GitHub Profile
@anandology
anandology / day1.ipynb
Last active August 29, 2015 13:56
Advanced Python Training at LinkedIn -- Feb 26 - Mar 1, 2014
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@anandology
anandology / shp2pgsql.txt
Created March 27, 2014 04:55
shp2pgsql for AC and PC data
[geosearch-anandology.rhcloud.com S01]\> shp2pgsql -W "latin1" -s4326 -d S01_AC ac geosearch > ac.sql
Shapefile type: Polygon
Postgis type: MULTIPOLYGON[2]
[geosearch-anandology.rhcloud.com S01]\> psql -q geosearch < ac.sql
dropgeometrycolumn
-------------------------------------
public.ac.geom effectively removed.
(1 row)
NOTICE: CREATE TABLE will create implicit sequence "ac_gid_seq" for serial column "ac.gid"
@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
#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 / 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 / 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 / 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 / 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 / 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 / edition.
Created March 20, 2009 11:14
couchdb view for /type/edition
{
"_rev": "1-262566171",
"_id": "_design/type_edition",
"language": "javascript",
"views": {
"by_title": {
"map": "function(doc) { if (doc.type.key == '/type/edition' && doc.title) emit(doc.title, doc.key);}"
},
"by_isbn_10": {
"map": "function(doc) { if (doc.type.key == '/type/edition' && doc.isbn_10) for (var i in doc.isbn_10) emit(doc.isbn_10[i], doc.key);}"