Skip to content

Instantly share code, notes, and snippets.

@mludvig
mludvig / virtualenv-init.sh
Created August 15, 2016 03:20
Initialise Python VirtualEnv and show it's name in $PS1
#!/bin/bash
# virtualenv init.sh - Initialise Python VirtualEnv and show it in $PS1
# By Michael Ludvig <mludvig@logix.net.nz>
# Usage
# 1) copy this file as 'init.sh' to your 'virtualenv' project's folder
# 2) run it, e.g. ~/whatever/init.sh (where 'whatever' is the project)
if [ -z "${_MY_DIR}" ]; then
@mludvig
mludvig / dropbox-rename.py
Created October 17, 2016 23:44
Rename images in DropBox folder to facilitate sorting by date
#!/usr/bin/env python
# Rename files in DropBox folder to allow easy sorting by date.
# If a JPG files contains EXIF data recognised by DropBox we
# rename it from e.g. "IMG_1234.JPG" to "2016-01-01 10:20:30 IMG_1234.JPG"
# Requires access token obtained from DropBox API page.
# By Michael Ludvig <mludvig@logix.net.nz>
# License Public Domain (it's too simple a script to deserve any licensing protection :)
@mludvig
mludvig / split-image.sh
Created September 28, 2011 05:04
split-image.sh - Split a large image into same-size tiles
#!/bin/bash -e
## split-image.sh - Split a large image into same-size tiles
## Split a large image into same-size tiles
## and optionally convert to a print-ready PDF document
##
## For example split a huge A1-size banner into 8x A4 tiles
## and create a single PDF ready for print.
@mludvig
mludvig / audio_test.py
Created March 13, 2019 02:44
Simple pygame audio test
#!/usr/bin/env python3
# audio_test.py - simple pygame audio test
# Author Michael Ludvig
import pygame
# PyGame initialisation
pygame.init()
pygame.mixer.init()
@mludvig
mludvig / audio_helper.py
Last active March 13, 2019 07:25
Sample code for using AWS Polly in Python
#!/usr/bin/env python3
# audio_helper.py - simple PyGame audio player
# Author Michael Ludvig
import io
import pygame
# PyGame initialisation - upon module loading
pygame.init()
@mludvig
mludvig / hello_polly.py
Created March 13, 2019 07:26
Simple AWS Polly demo
#!/usr/bin/env python3
# hello_polly.py - Simple AWS Polly demo
# Author Michael Ludvig
# Import play_audio_stream() from audio_helper.py
from audio_helper import play_audio_stream
# Boto3 is the AWS SDK for Python
import boto3
# SSML-enhanced audio
ssml_text = '''
<speak>
Let me tell you a secret.
<break time="1s" />
<amazon:effect name="whispered">Amazon Alexa is my sister!</amazon:effect>
</speak>
'''
response = polly.synthesize_speech(OutputFormat='ogg_vorbis', VoiceId='Emma',
@mludvig
mludvig / describe_voices.py
Created March 13, 2019 07:54
Describe and play all available AWS Polly voices
#!/usr/bin/env python3
# describe_voices.py - describe and play all AWS Polly voices
# Author Michael Ludvig
import boto3
from audio_helper import play_audio_stream
polly = boto3.client('polly')
@mludvig
mludvig / ssml_simple.py
Created March 14, 2019 09:37
Basic SSML-enhanced text synthesis
#!/usr/bin/env python3
# ssml_simple.py - Basic SSML-enhanced text output
# Author Michael Ludvig
# Import play_audio_stream() from audio_helper.py
from audio_helper import play_audio_stream
# Boto3 is the AWS SDK for Python
import boto3
@mludvig
mludvig / cfn-service-role-and-policy.yml
Last active August 10, 2019 08:46
CloudFormation Service Role and Policy
---
AWSTemplateFormatVersion: '2010-09-09'
Description: CloudFormation Service Role and Policy
Metadata:
Author: Michael Ludvig
Url: https://aws.nz/best-practice/cloudformation-service-roles/
Parameters:
RoleName: