Skip to content

Instantly share code, notes, and snippets.

@sanand0
sanand0 / open.cmd
Created April 4, 2010 11:41
Opens files wherever they are in your machine. Change to any directory from anywhere.
@echo off
REM = """
REM python -x skipped that first line...
REM make sure that this file is saved with Windows newlines
REM make sure to change the next lines to whatever this file is called:
set FOLDER=D:/Apps/Misc
python -x %FOLDER%/o.cmd %*
if errorlevel == 1 goto changedir
goto end
@sanand0
sanand0 / textarea-maxlength.js
Created September 7, 2010 07:17
Restricts number of characters to maxlength in textarea
// Textarea maxlength
// Ensures that textarea's maxlength is validated
//
// (c) S Anand, 2010, MIT License
// Credits: http://yelotofu.com/2009/12/jquery-textarea-max-length/
// Credits: http://stackoverflow.com/questions/43569/max-length-for-html-text-areas
(function() {
var ignore = [8,9,13,33,34,35,36,37,38,39,40,46];
function limit(event) {
@sanand0
sanand0 / Multiple-successive-vowels.txt
Created November 10, 2010 09:48
Words with multiple successive vowels
# See http://www.s-anand.net/blog/shortening-sentences/
# Removing vowels from words reduces the readability, but shrinks text by 18% [column 1]
# Removing only single vowels (e.g. read -> read, but yet -> yt) shrinks by 14% [column 2]
# Is the difference worth it? Here are some examples:
abbrviatn abbrviation
ablitn ablition
ablits ablities
abnd abound
abndng aboundng
@sanand0
sanand0 / applog.py
Created March 6, 2011 20:51
A simple python application that periodically logs the name of the application you're working on.
import win32gui, time, os.path
filename = os.path.join(os.path.dirname(__file__), 'applog.txt')
out = open(filename, 'a')
while True:
title = win32gui.GetWindowText(win32gui.GetForegroundWindow())
out.write(time.strftime('%a %d-%m-%Y %H:%M:%S') + '\t' + title + '\n')
out.flush()
time.sleep(30)
@sanand0
sanand0 / viz.py
Created May 3, 2011 17:10
Utility functions for visualisations
'''
Usage: viz.py INPUT.csv [template.html] > OUTPUT.xhtml
'''
import re
import math
import logging
import datetime
import operator
from tornado import template
@sanand0
sanand0 / R.css
Created May 12, 2011 12:08
R help .css inspired by tornadoweb.org. Place in R/doc/html/R.css
body {
background: white;
color: #444;
font-family: Georgia, serif;
font-size: 11pt;
margin: 15px auto;
max-width: 850px;
line-height: 1.5;
}
@sanand0
sanand0 / color.js
Created March 30, 2012 08:24
Color manipulation library
// Internal color conversion
// Converts `#ffffff` to `(255, 255, 255)`
function _colornum(color) {
var l = color.length;
return [
parseInt(color.slice(l-6,l-4), 16),
parseInt(color.slice(l-4,l-2), 16),
parseInt(color.slice(l-2,l-0), 16)
];
}
@sanand0
sanand0 / pyconindia2012.json
Created September 30, 2012 10:45
All 566 tweets mentioning #pyconindia #pyconindia2012 and @pyconindia until 4:10pm IST on 30-Sep-2012
{"iso_language_code": "da", "to_user_name": "Jishnu", "to_user_id_str": "110358179", "profile_image_url_https": "https://si0.twimg.com/profile_images/1761677446/2850384465_604be38694_b__copy__normal.jpg", "from_user_id_str": "15649930", "text": "@jishnu7 Automated Data Analysis talk By S Anand is at A1 #PyconIndia2012", "from_user_name": "Ramakrishna Reddy", "in_reply_to_status_id_str": "252282073249902593", "profile_image_url": "http://a0.twimg.com/profile_images/1761677446/2850384465_604be38694_b__copy__normal.jpg", "id": 252284135371067392, "to_user": "jishnu7", "source": "<a href="http://twitter.com/">web</a>", "in_reply_to_status_id": 252282073249902593, "id_str": "252284135371067392", "from_user": "ramkrsna", "from_user_id": 15649930, "to_user_id": 110358179, "geo": null, "created_at": "Sun, 30 Sep 2012 05:49:59 +0000", "metadata": {"result_type": "recent"}}
{"iso_language_code": "da", "to_user_name": null, "to_user_id_str": "0", "profile_image_url_https": "https://si0.twimg.com/pr
@sanand0
sanand0 / header.py
Created November 9, 2012 04:27
Captures HTTP headers and saves them in a JSON file
"""
Captures all headers in a JSON file.
"""
import json
import tornado.ioloop
import tornado.web
import pprint
class Header(tornado.web.RequestHandler):
@sanand0
sanand0 / .gitignore
Created December 9, 2012 13:31
Scrapes pypi.python.org modules into a CSV file
*.csv
.cache