Skip to content

Instantly share code, notes, and snippets.

Avatar

Stephen McDonald stephenmcd

View GitHub Profile
@stephenmcd
stephenmcd / script.sh
Last active Aug 29, 2015
Recursive scripting API in CurioDB
View script.sh
~ 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 / pull.py
Last active Aug 29, 2015
My Github pull request pull script for Mercurial
View pull.py
#!/usr/bin/env python
import os
import sys
import github
username = "stephenmcd"
while True:
@stephenmcd
stephenmcd / conf.py
Last active Aug 29, 2015
Django model updates over websockets - run with: `gunicorn -c conf.py server:serve`
View conf.py
# 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 / MergeSort.scala
Last active Aug 29, 2015
Askless Parallel Merge Sort in Scala/Akka
View MergeSort.scala
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 / admin.html
Last active Aug 29, 2015
Stripped down page tree branch template for Mezzanine's admin.
View admin.html
{% 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 / generate_page_tree.py
Created Oct 13, 2014
Generate a Page Tree in Mezzanine
View generate_page_tree.py
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 / MergeSort.scala
Last active Apr 8, 2019
Parallel Merge Sort in Scala/Akka
View MergeSort.scala
import scala.concurrent.Await
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.concurrent.Future
import scala.util.Random
import akka.actor.{ActorSystem, Actor, Props}
import akka.pattern.ask
import akka.util.Timeout
import akka.routing.RoundRobinPool
View parallel_merge_sort.py
import math
import multiprocessing
import random
import sys
import time
def merge(*args):
# Support explicit left/right args, as well as a two-item
# tuple which works more cleanly with multiprocessing.
@stephenmcd
stephenmcd / django_browsable_email_backend.py
Last active Aug 29, 2015
An email backend for Django that opens each HTML email sent in a local webbrowser
View django_browsable_email_backend.py
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", []):
View hardcoded_url_field.py
from rest_framework import serializers
class HyperlinkedIdentityField(serializers.HyperlinkedIdentityField):
"""
This is a performance wrapper for HyperlinkedIdentityField.
We save a ton of time by not calling reverse potentially
thousands of times per request.
"""
def __init__(self, *args, **kwargs):
You can’t perform that action at this time.