Skip to content

Instantly share code, notes, and snippets.

View naiquevin's full-sized avatar

Vineet Naik naiquevin

View GitHub Profile
@naiquevin
naiquevin / elections2014.py
Created May 16, 2014 12:49
elections2014
import os
import json
import requests
from lxml import html
def num_to_state(n):
assert n <= 35
if n < 10:
@naiquevin
naiquevin / twdm.py
Created January 15, 2014 17:40
Script to delete spam DMs sent from your account by some malicious apps on twitter
"""Script to delete spam DMs sent from your account by some malicious
apps on twitter
Usage: This script needs to be run in two steps
1. $ python twdm.py auth (for getting oauth token and secret)
This step will prompt you to enter pin and then print the oauth
token and secret.
@naiquevin
naiquevin / funcpat.sml
Created October 20, 2013 07:29
ML function patterns
fun xyz 1 = "single"
| xyz 2 = "double"
| xyz 3 = "triple"
| xyz _ = "multiple"
(*
val xyz = fn : int -> string
val it = () : unit
@naiquevin
naiquevin / wrap_partial.py
Last active December 25, 2015 05:18
wrapping a partial
from functools import wraps, partial
def mul(a, b):
return a * b
double = partial(mul, 2)
## And now try this,
print(wraps(double)(lambda a: str(double(a)))(2))
@naiquevin
naiquevin / comp.py
Last active April 13, 2019 15:09
Function composition in Python inspired by Clojure's `comp` function
## Update! Found an alternative approach that's concise and feels much more idiomatic
def compose (f, g):
return lambda x: f(g(x))
def comp(*args):
return reduce(compose, args[1:], args[0])
def comp1(*args):
@naiquevin
naiquevin / tw.py
Created September 14, 2013 07:55
Twython wrapper for app authenticated requests to twitter api
from twython import Twython
## Defining access_token as a function so that the token may be cached
## using a decorator as follows,
##
## get_access_token = cache_textfile('.twython-token')(access_token)
##
def access_token(auth_client):
return auth_client.obtain_access_token()
@naiquevin
naiquevin / insertion.png
Last active December 18, 2015 17:09
Comparing execution time of in-place and immutable implementation of insertion sort in Python 3
insertion.png
@naiquevin
naiquevin / LittleSchemerForeword
Last active December 18, 2015 03:08
Little Schemer Foreword
In 1967 I took an introductory course in photography. Most of the students (including me) came
into that course hoping to learn how to be creative-to take pictures like the ones I admired
by artists such as Edward Weston. On the first day the teacher patiently explained the long
list of technical skills that he was going to teach us during the term. A key was Ansel Adams'
"Zone System" for previsualizing the print values (blackness in the final print) in a photograph
and how they derive from the light intensities in the scene. In support of this skill we had
to learn the use of exposure meters to measure light intensities and the use of exposure time
and development time to control the black level and the contrast in the image. This is in turn
supported by even lower level skills such as loading film , developing and printing, and mixing
chemicals. One must learn to ritualize the process of developing sensitive material so that one
@naiquevin
naiquevin / thankyou.py
Last active September 16, 2020 16:09
Python script to thank people who sent birthday wishes on facebook
import sys
from urllib import urlencode
import requests
from urlparse import urlparse, parse_qs
from random import choice
import re
self_id = None # your facebook id here
utc_bday = None # utc timestamp of your birthday
@naiquevin
naiquevin / octo2pelican.py
Created February 17, 2013 17:21
A quick script for converting octopress posts (markdown source files) to pelican posts (markdown again but slightly different)
#!/usr/bin/env python
import os
import yaml
import datetime
from collections import OrderedDict
__doc__ = 'A quick script for converting octopress posts (markdown source files) to pelican posts'