Skip to content

Instantly share code, notes, and snippets.

View amix's full-sized avatar

Amir Salihefendic amix

View GitHub Profile
@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:
#!/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 / 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')
@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 / 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
#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 / gist:88cc073049c1aba5c6af
Created February 9, 2015 22:41
Flux + React example
# Store
class CounterStore extends EventEmitter
constructor: ->
@count = 0
@dispatchToken = @registerToDispatcher()
increaseValue: (delta) ->
@count += 1
@amix
amix / gist:2b492d7e778da9ee4231
Created February 9, 2015 22:04
Model View Controller Example (Cocoa inspired)
class ModelCounter
constructor: (@value=1) ->
increaseValue: (delta) =>
@value += delta
class ControllerCounter
constructor: (opts) ->