Skip to content

Instantly share code, notes, and snippets.

View mhemesath's full-sized avatar

Mike Hemesath mhemesath

View GitHub Profile
from django.core.management import base
from django.core.cache import get_cache
from django.conf import settings
from django.core.management import call_command
import StringIO
import re
import urls
<% start_date = date.beginning_of_month.beginning_of_week - 1.day %>
<% end_of_month = date.end_of_month.end_of_week %>
<% weeks = (start_date...end_of_month).each_slice(7).to_a %>
<table>
<thead>
<% (0..6).each do |i| %>
<th><%= (start_date + i.days).strftime('%a') %></th>
<% end %>
</thead>
PIPELINE_LESS_ARGUMENTS = '--include-path=' + ':'.join([
'{0}/static/less'.format(app_module.filename)
for app_module in [pkgutil.get_loader(app) for app in INSTALLED_APPS]
])
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<!--[if lte IE 8]><script src="../r2d3.v2.js"></script><![endif]-->
<!--[if gte IE 9]><!-->
<script src="../lib/d3/d3.v2.js"></script>
<!--<![endif]-->
</head>
<body><div id="pyramidDiagram"></div></body>
<script>
@mhemesath
mhemesath / async_task_middleware.py
Last active May 12, 2022 19:17
MIddleware to allow celery tasks to be batched per request.
from celery import task
class AsyncTaskMiddleware(object):
"""
Dynamically adds an async task queue to the request to be executed when the
response is processed.
All tasks added to the request are executed using a single asynchronous celery task.
Once the task is executed, it will execute each individual task in its own celery
task.
@mhemesath
mhemesath / transformToMatrix.js
Created October 9, 2012 03:01
Converts a SVG transform string into a Raphael Matrix object.
function toMatrix(transform) {
var transforms = transform.split(' '),
matrix = Raphael.matrix();
for (var i=0; i<transforms.length; i++) {
var match = /^(\w+)\((.+)\)$/.exec(transforms[i]),
tranform = match[1],
values = toFloatArray(match[2]);
if ('translate' === transform) matrix.translate.apply(matrix, values);
@mhemesath
mhemesath / gist:2771836
Created May 22, 2012 21:46
Stylus Right-To-Left Support
.foo {
p { color: #333; text-align: rtl(right, left); }
}
// Output
.foo p { color: #333; text-align: left; }
html[dir="rtl"] .foo p { text-align: right; }