Skip to content

Instantly share code, notes, and snippets.

View styrmis's full-sized avatar

Stefan Magnuson styrmis

View GitHub Profile
@styrmis
styrmis / gist:1483971
Created December 16, 2011 01:26
Add a simple flag to a python script, e.g. a --debug flag
from optparse import OptionParser
parser = OptionParser()
parser.add_option("--debug", action="store_true", dest="debug")
(options, args) = parser.parse_args()
# Access the option like so; in this case it will be stored as a boolean
print options.debug
@styrmis
styrmis / gist:5317292
Created April 5, 2013 07:27
One way to set a background colour for some frames in your reportlab Platypus document that works with the document's build method.
# If you use this class instead of SimpleDocTemplate you can add ColorFrame objects along
# with regular Frame objects and the ColorFrame objects will have their background colour
# rendered at the appropriate time during the document build process.
class ColorFrameDocTemplate(SimpleDocTemplate):
def handle_frameBegin(self, *args):
SimpleDocTemplate.handle_frameBegin(self, *args)
if hasattr(self.frame, 'background'):
self.frame.drawBackground(self.canv)
@styrmis
styrmis / download_attachments_from_sender_gmail.py
Created March 19, 2014 08:55
Download all attachments from Gmail from a specific sender
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
@styrmis
styrmis / gist:420946e05621269ca93e
Created September 4, 2014 06:35
Embedding code blocks in Leanpub aside/warning/tip blocks
Example using both an embedded code block (with language explicitly specified), and inline code.
T> When a Ruby object is printed or otherwise asked to represent itself as a
string, the `to_s` ('to string') method of that object is called. So for our
managed object what we want to do is define a `to_s` method which displays our
task attributes. Add this method to `app/task.rb`:
T>
{lang="ruby"}
def to_s
"Priority: #{self.priority} " +
@styrmis
styrmis / cronitor.sh
Last active January 22, 2016 21:59 — forked from erchn/cronitor.sh
Cronitor wrapper script for start/stop notifications, shamelessly stolen from the now defunct Proby
#!/bin/bash
#
# This script surrounds the command passed in with start and finish notifications
# to the cronitor monitoring application.
#
# === SETUP
#
# * Make sure the cronitor script is executable.
#
# chmod +x cronitor