Skip to content

Instantly share code, notes, and snippets.

View gpiancastelli's full-sized avatar

Giulio Piancastelli gpiancastelli

View GitHub Profile
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(column-number-mode t))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
/*
Functions used for the fade-in effect on Google's home page.
To reuse it, link this JavaScript file from your HTML source in a <script>
element; then, set the onmousemove attribute of the chosen element (e.g. <p>,
or <html> as Google did) to call the google.fade function.
<html onmousemove="google.fade()">
(Actually, Google setting is "google&&google.fade&&google.fade()". YMMV.)
@gpiancastelli
gpiancastelli / goodreads-oauth-example.py
Created August 19, 2010 13:50
A Python example of how to use OAuth on GoodReads
import oauth2 as oauth
import urlparse
url = 'http://www.goodreads.com'
request_token_url = '%s/oauth/request_token/' % url
authorize_url = '%s/oauth/authorize/' % url
access_token_url = '%s/oauth/access_token/' % url
consumer = oauth.Consumer(key='Your-GoodReads-Key',
secret='Your-GoodReads-Secret')
@gpiancastelli
gpiancastelli / tbd.py
Created November 9, 2010 15:34
A Python web scraper for wish lists on The Book Depository
# A web scraper for wish lists on The Book Depository.
#
# TBD offers a mail notification service for books in a wish list when some
# price drops. Unfortunately, you are notified only if prices drop of 10% or
# more; also, the message you receive does not contain the new dropped price,
# nor the old, higher price. Finally, when I got one of those notifications,
# that very day I visited the book page on TBD only to discover that the price
# got higher again. Not very effective as a service, you know.
#
# So I decided to write a script myself.
@gpiancastelli
gpiancastelli / birthday.py
Created January 31, 2011 14:30
Calculate the probability of the birthday problem for 23 people on a user-supplied number of randomly generated samples.
#!/usr/bin/env python2.6
# In probability theory, the birthday problem, or birthday paradox pertains to
# the probability that in a set of randomly chosen people some pair of them
# will have the same birthday. By the pigeonhole principle, the probability
# reaches 100% when the number of people reaches 367 (including February 29
# births). But perhaps counter-intuitively, 99% probability is reached with
# just 57 people, and 50% probability with 23 people. These conclusions are
# based on the assumption that each day of the year (except February 29) is
# equally probable for a birthday.
@gpiancastelli
gpiancastelli / rot13.py
Created February 1, 2011 22:30
A basic ROT13 implementation in Python
#!/usr/bin/env python2.6
import sys
from os.path import basename
from string import lowercase, uppercase, maketrans
if len(sys.argv) != 2:
print 'Usage: %s text' % basename(sys.argv[0])
sys.exit(1)
@gpiancastelli
gpiancastelli / kwcounter.py
Created March 14, 2011 21:10
A keyword counter for Python scripts
#!/usr/bin/env python2.6
'''
For each Python script in the current directory, prints the total
number of keywords used and the partial number for each keyword.
'''
import collections
import glob
import keyword
@gpiancastelli
gpiancastelli / KeywordCounter.java
Created April 14, 2011 09:11
A simplified keyword counter for Python scripts, written in Java
package com.example;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@gpiancastelli
gpiancastelli / Letters.java
Created June 26, 2011 14:49
Print the letters of an input string in decreasing order of frequency.
package com.example;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@gpiancastelli
gpiancastelli / Letters.java
Created July 2, 2011 12:55
Print the letters of an input string in alphabetic order alongside their frequency
package com.example;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Letters {