Skip to content

Instantly share code, notes, and snippets.

View alexlovelltroy's full-sized avatar
🏫
Attending Marcel Marceau College of Radio Performance

Alex Lovell-Troy alexlovelltroy

🏫
Attending Marcel Marceau College of Radio Performance
View GitHub Profile
@alexlovelltroy
alexlovelltroy / create_gcp_data_project.sh
Created September 6, 2018 08:51
Bash snippet I use to create a temporary GCP project for doing datalab stuff
#!/usr/bin/bash
set -e
PROJECT_SUFFIX=$(cat /dev/random | LC_CTYPE=C tr -dc "a-z0-9" | head -c 5)
PROJECT_NAME=temp-project-$PROJECT_SUFFIX
PROJECT_BUCKET=data_export_bucket-$PROJECT_SUFFIX
# Update gcloud
@alexlovelltroy
alexlovelltroy / flap_nginx.py
Last active August 30, 2016 22:37
Python can reload the nginx config file faster than I can write a new one
#!/usr/bin/env python
import time
import psutil
import os
import signal
@alexlovelltroy
alexlovelltroy / reassign.sh
Created December 18, 2014 20:33
reallocate unassigned shards in elasticsearch
NODE="a hostname"
IFS=$'\n'
for line in $(curl -s 'localhost:9200/_cat/shards' | fgrep UNASSIGNED); do
INDEX=$(echo $line | (awk '{print $1}'))
SHARD=$(echo $line | (awk '{print $2}'))
curl -XPOST 'localhost:9200/_cluster/reroute?pretty' -d '{
"commands": [
{
"allocate": {
@alexlovelltroy
alexlovelltroy / handler_test.py
Created October 9, 2013 15:21
This is a generic mixin that can add action handlers to any other class
class HandlerMixin(object):
action_handlers = {}
def add_handler_action(self,action):
if action not in self.action_handlers.keys():
self.action_handlers[action] = []
def register_handler(self, action, function):
self.add_handler_action(action)
if function not in self.action_handlers[action]:

#INTROS PRIVACY POLICY

  1. ###Introduction

    Thank you for visiting Intros.to, an online service which allows its Users to track introductions. Please read our Terms of Service and this Privacy Policy carefully, as you must agree to both as a condition of using our Service.

  2. ###Definitions

    Throughout this document, we may use certain words or phrases, and it is important that you understand the meaning of them. The following is a non-exhaustive list of definitions of words and phrases found in this document:

@alexlovelltroy
alexlovelltroy / gravatar_util.py
Created August 10, 2013 05:12
generate a gravatar image url from an e-mail address
import hashlib
def generate_avatar_url(addr, size):
default = 'mm'# or '404' or 'blank'
gravatar_base_url = 'http://www.gravatar.com/avatar/'
computed_hash = hashlib.md5(str(addr).lower().lstrip().rstrip()).hexdigest()
return '%s%s?d=%s&s=%s' % (gravatar_base_url, computed_hash, default, size)
@alexlovelltroy
alexlovelltroy / models.py
Last active December 20, 2015 04:49
Class Based E-mail for django
from django.conf import settings
from django.core.mail import EmailMultiAlternatives
from django.db import models
from django.template import Template, Context ,loader
from django.contrib.sites.models import Site
def resolve_template(template):
"Accepts a template object, path-to-template or list of paths"
if isinstance(template, (list, tuple)):
@alexlovelltroy
alexlovelltroy / userplot.js
Last active December 19, 2015 17:39
Time-based graph of any django model with a date/datetime field
// * Somewhere in your html, you'll need a place to put the graph (flotcharts.org)
// <div class="graph-container">
// <div id="userGraph" class=graph-placeholder></div>
// </div>
// * You'll also need the data available to the js
// * This should probably go near the bottom. Like just before the </body> tag.
// <script>
// {% autoescape off %}
// GRAPHABLE_DATA = {{ report_as_json }}
// {% endautoescape %}
#!/usr/bin/env python
import xmlrpclib
import pip
pypi = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
for dist in pip.get_installed_distributions():
available = pypi.package_releases(dist.project_name)
if not available:
# Try to capitalize pkg name
@alexlovelltroy
alexlovelltroy / recipie_default.rb
Created March 1, 2013 19:01
How I install multiple django apps on one host by re-using a recipe
node.django_apps.each do |key,value|
django_app = value
djangoapp_build_repo django_app.branch do
action :add
settings django_app.settings
repo django_app.repo
app_name django_app.app_name
env_root django_app.env_root
app_user django_app.app_user
not_if { File.directory? "#{django_app.env_root}/#{django_app.app_name}-env" }