Skip to content

Instantly share code, notes, and snippets.

View amix's full-sized avatar

Amir Salihefendic amix

View GitHub Profile
#!/usr/bin/env python
"""
fix_s3_cache_headers
~~~~~~~~
Updates S3 objects with new cache-control headers.
Usage::
python fix_cloudfront.py <bucket_name> <keys>*
@amix
amix / gist:5282957
Created April 1, 2013 02:41
Hacker's news ranking algorithm
Score = (P-1) / (T+2)^G
where,
P = points of an item (and -1 is to negate submitters vote)
T = time since submission (in hours)
G = Gravity, defaults to 1.8 in news.arc
@amix
amix / Reddits_Algorithm.py
Created March 24, 2013 02:14
The confidence sort algorithm is implemented in _sorts.pyx, I have rewritten their Pyrex implementation into pure Python (do also note that I have removed their caching optimization)
#Rewritten code from /r2/r2/lib/db/_sorts.pyx
from math import sqrt
def _confidence(ups, downs):
n = ups + downs
if n == 0:
return 0
#Rewritten code from /r2/r2/lib/db/_sorts.pyx
from math import sqrt
def _confidence(ups, downs):
n = ups + downs
if n == 0:
return 0
@amix
amix / fix_cloudfront.py
Created May 2, 2012 21:21
Updating caching headers for Amazon S3 and CloudFront
#!/usr/bin/env python
"""
fix_s3_cache_headers
~~~~~~~~
Updates S3 objects with new cache-control headers.
Usage::
python fix_cloudfront.py <bucket_name> <keys>*
@amix
amix / script_communicator_new.js
Created February 2, 2012 18:51
Implementation of script communication that can be used to do long polling (comet) and JSONP communication. Uses Cross-Origin Resource Sharing
// For more information about this check: http://amix.dk/blog/post/19677
ScriptCommunicator = {
sourceJavaScript: function(uri, on_success, on_error) {
var xhr = ScriptCommunicator.createCORSRequest('GET', uri);
if(xhr) {
xhr.onload = function() {
eval(xhr.responseText);
@amix
amix / amazon_sender.py
Created May 17, 2011 13:39
Amazon SES helper script using boto
# -*- coding: utf-8 -*-
"""
amazon_sender.py
~~~~~~~~
Python helper class that can send emails using Amazon SES and boto.
The biggest feature of this class is that encodings are handled properly.
It can send both text and html emails.
This implementation is using Python's standard library (which opens up for a lot more options).