Skip to content

Instantly share code, notes, and snippets.

@mozz100
mozz100 / renamer.py
Created May 11, 2014 20:41
Rename files in order, move to a directory
#!/usr/bin/python
import sys, csv, os, shutil
pattern = "Vol09-%04d.jpg"
original_filename = sys.argv[1]
output_path = sys.argv[2]
output_csv = os.path.join(output_path, "original_filenames.csv")
next_index = 0
@mozz100
mozz100 / bookmarklet.js
Created June 26, 2014 09:20
Bookmarklet: Jump between envisage staging/production
javascript:(function(){var where=document.location.toString();if(where.indexOf('envisage-system.co.uk')>=0){document.location=where.replace('envisage-system.co.uk','envisage-staging.co.uk');}if(where.indexOf('envisage-staging.co.uk')>=0){document.location=where.replace('envisage-staging.co.uk','envisage-system.co.uk');}})()
@mozz100
mozz100 / python-package-update.sh
Last active August 29, 2015 14:05
Patch updates for pinned python packages
# Use sed to replace '==x.y' with '<x.y.999'
# and save results to a file
sed -r -e "s/==([0-9]+\.[0-9]+)(\..+)?/<\1.999/" requirements.txt > /tmp/requirements2.txt
# It works by transforming the file like this:
# Django==1.4.8 >> Django<1.4.999
# Jinja2==2.5 >> Jinja2<2.5.999
# M2Crypto==0.19.1 >> M2Crypto<0.19.999
# MySQL-python==1.2.5 >> MySQL-python<1.2.999
# Pillow==2.5.1 >> Pillow<2.5.999
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Owlstone - Chemical Detection and Chemical Sensing</title>
<link href="https://plus.google.com/103452364153605968626" rel="publisher" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="x-dns-prefetch-control" content="on" />
<link rel="dns-prefetch" href="//www.owlstone.net" />
@mozz100
mozz100 / hosts
Created December 4, 2014 10:59
Ansible list syntax - apparently confusing behaviour
localhost ansible_connection=local
@mozz100
mozz100 / simple_web_server.py
Created February 2, 2015 11:00
Very simple web server
# A VERY simple (naive?) web server.
# Listens for requests (on a socket) and responds with HTML responses.
# There are some obvious problems with this (it's really very basic). For instance,
# it responds to ALL requests with 200 OK and HTML.
# Code based on http://code.activestate.com/recipes/576541-very-simple-http-web-server/
from socket import *
HOST = '' # Can put '127.0.0.1' - meaning the local host
PORT = 5000 # Arbitrary non-privileged port
@mozz100
mozz100 / keybase.md
Created February 27, 2015 12:54
keybase.md

Keybase proof

I hereby claim:

  • I am mozz100 on github.
  • I am mozz (https://keybase.io/mozz) on keybase.
  • I have a public key whose fingerprint is 1BDB 23C4 5299 08F6 B042 83F5 4414 F64B 6368 2CDA

To claim this, I am signing this object:

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mozz100
mozz100 / marketo_interesting_moment.js
Created January 30, 2012 12:03
Marketo Sales Insight - notify sales team which file was downloaded
/* Use the Munchkin API to record a 'visitWebPage' event (see http://community.marketo.com/MarketoArticle?id=kA050000000Kyr7). Set the url of the visitWebPage event to the url of the download. I found that I had to make the link open in a new window, otherwise the Munchkin never manages to 'call home'...
I did it with jQuery. Replace $jq with a reference to a valid jQuery object in the code below.
We use a separate subdomain for Marketo-hosted landing pages and resources (in common with most users, I suspect). Since we wanted to track downloads for any PDF or PPT file within that domain, the jQuery selector pretty much wrote itself. It's case sensitive, but could easily be extended or modified to work around that - wasn't necessary for me.
Opening the links in a new window seems to help with the tracking. If the new page loads too quickly, then it seemed as if the event handler code didn't get called. Leaving the original window open avoids this (I set target="_blank").
*/
@mozz100
mozz100 / querystring.js
Created February 1, 2012 15:19
Read the querystring from javascript
// Adapted from http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript
// Give a querystring like this: yourpage.html?cheese=wensleydale&biscuits=nice
var qs = (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i)
{
var p=a[i].split('=');
if (p.length != 2) continue;