Skip to content

Instantly share code, notes, and snippets.

@stephenmcd
stephenmcd / django_browsable_email_backend.py
Last active August 29, 2015 13:56
An email backend for Django that opens each HTML email sent in a local webbrowser
from tempfile import NamedTemporaryFile
import webbrowser
from django.core.mail import EmailMultiAlternatives
class BrowsableEmailBackend(BaseEmailBackend):
def send_messages(self, email_messages):
for message in email_messages:
for body, content_type in getattr(message, "alternatives", []):
@stephenmcd
stephenmcd / generate_page_tree.py
Created October 13, 2014 20:00
Generate a Page Tree in Mezzanine
from mezzanine.pages.models import RichTextPage
def generate_page_tree(per_branch):
for a in range(per_branch):
x = RichTextPage.objects.create(title="Page %s" % a)
for b in range(per_branch):
y = RichTextPage.objects.create(title="Page %s-%s" % (a, b), parent=x)
for c in range(per_branch):
z = RichTextPage.objects.create(title="Page %s-%s-%s" % (a, b, c), parent=y)
@stephenmcd
stephenmcd / admin.html
Last active August 29, 2015 14:07
Stripped down page tree branch template for Mezzanine's admin.
{% load pages_tags future %}
<ol>
{% for page in page_branch %}
<li id="ordering_{{ page.id }}">
<div>
<a href="#" class="tree-toggle" id="page-{{ page.id }}"
{% if not page.has_children %}style="visibility:hidden;"{% endif %}>
<span class="icon open">+</span>
<span class="icon close">-</span>
@stephenmcd
stephenmcd / MergeSort.scala
Last active August 29, 2015 14:08
Askless Parallel Merge Sort in Scala/Akka
import scala.math.{floor, log}
import scala.util.Random
import akka.actor.{ActorSystem, Actor, Props}
object MergeSort extends App {
case class Items(items: Vector[Int])
@stephenmcd
stephenmcd / conf.py
Last active August 29, 2015 14:21
Django model updates over websockets - run with: `gunicorn -c conf.py server:serve`
# This is the gunicorn config file for the websocket server.
worker_class = "geventwebsocket.gunicorn.workers.GeventWebSocketWorker"
bind = "0.0.0.0:9000"
workers = 1
timeout = 10000000000
loglevel = "error"
proc_name = "websocket-server"
# Modify paths here as required - allows websocket server to run
@stephenmcd
stephenmcd / pull.py
Last active August 29, 2015 14:21
My Github pull request pull script for Mercurial
#!/usr/bin/env python
import os
import sys
import github
username = "stephenmcd"
while True:
@stephenmcd
stephenmcd / script.sh
Last active August 29, 2015 14:26
Recursive scripting API in CurioDB
~ redis-cli EVAL "return redis.call('EVAL', 'return redis.call(\'EVAL\', \'return redis.call(\\\\\'TIME\\\\\')\', 0)', 0)" 0
1) (integer) 227734
2) (integer) 541653
@stephenmcd
stephenmcd / gist:311723
Created February 23, 2010 01:00
Formset Forms for Django
from copy import copy
from itertools import dropwhile, takewhile
from re import match
from django import template
from django.utils.datastructures import SortedDict
from django.utils.translation import ugettext as _
@stephenmcd
stephenmcd / ghetto_life_stream.php
Created April 16, 2010 06:46
Format different entry types from Google Buzz
<?
/**
* ghetto life stream script for http://jupo.org
*
* The main function of this script is to use the feed provided by Google Buzz
* to create a life stream of entries from various sources with specific
* handling for each different type of source. Sources are either directly
* integrated into Google Buzz such as Twitter and Flickr, or are subscribed to
* via Google Reader which when shared are then sent to Google Buzz. So far the
@stephenmcd
stephenmcd / create_test_products.py
Created April 22, 2010 23:40
Concurrent product data generation from Google Base / Flickr
"""
Stand-alone data generation routine that uses the ecommerce taxonomy found on
Google Base to generate a significant amount of category and product data, as
well as using the Flickr API to retrieve images for the products. The
multiprocessing module is also used for parallelization.
The Django models and environment used here are specific to the Cartridge
project but the approach could easily be reused with any ecommerce database.
"""