Skip to content

Instantly share code, notes, and snippets.

View amix's full-sized avatar

Amir Salihefendic amix

View GitHub Profile
@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>*
#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 / 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 / bitmapist_gen_html_form.py
Created December 16, 2015 02:21
Generating the HTML form for querying bitmapist
from bitmapist import cohort
html_form = cohort.render_html_form(
action_url='/_Cohort',
selections1=[ ('Are Active', 'user:active'), ],
selections2=[ ('Task completed', 'task:complete'), ]
)
print html_form
@amix
amix / bitmapist_gen_html_data.py
Created December 16, 2015 02:23
Generating bitmapist HTML data
from bitmapist import cohort
dates_data = cohort.get_dates_data(select1='user:active',
select2='task:complete',
select3=None,
time_group='days')
html_data = cohort.render_html_data(dates_data,
time_group='days')
#!/usr/bin/env python
"""
fix_s3_cache_headers
~~~~~~~~
Updates S3 objects with new cache-control headers.
Usage::
python fix_cloudfront.py <bucket_name> <keys>*
@pytest.yield_fixture
def v5_api_data():
with resources.project_ctx() as project, \
resources.item_ctx() as task1, \
resources.item_ctx() as task2, \
resources.item_ctx() as in_history:
with resources.note_ctx(item_id=task1.id) as note_task_1,\
resources.note_ctx(item_id=in_history.id) as note_task_3:
// JavaScript that solves http://regex.alf.nu/
// Run in Chrome or Firefox console
// Enjoy ;-)
// Some people, when confronted with a problem, think
// “I know, I'll use regular expressions.”
// Now they have two problems.
for(var lvl in levels) {
var fn = function(lvl) {
// JavaScript that solves http://regex.alf.nu/
// Run in Chrome or Firefox console
// Enjoy ;-)
// Some people, when confronted with a problem, think
// “I know, I'll use regular expressions.”
// Now they have two problems.
for(var lvl in levels) {
var fn = function(lvl) {
@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