Skip to content

Instantly share code, notes, and snippets.

View rturowicz's full-sized avatar

Rafal Turowicz rturowicz

  • Poland
View GitHub Profile
#!/usr/bin/env python
"""
Recipe for creating and updating security groups programmatically.
"""
import collections
import boto
from django.core.mail import send_mail
import os
def sendMyAppEmail(toList, template, toType=None, subject="", templateDict={}):
# Load the image you want to send at bytes
img_data = open(os.path.join(settings.MEDIA_ROOT, 'bumblebee.jpeg'), 'rb').read()
# Create a "related" message container that will hold the HTML

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@rturowicz
rturowicz / hashes.py
Last active December 23, 2015 12:18
compare dictionaries content
from hashlib import md5
from cPickle import dumps
def make_hashes(data):
ret = [md5(dumps(data)).hexdigest()]
ret.extend([
md5(dumps(v)).hexdigest() for v in data.values()
])
@rturowicz
rturowicz / mysql_functions.sql
Last active December 17, 2015 14:29
postgresql: mysql functions
CREATE OR REPLACE FUNCTION UNIX_TIMESTAMP(TIMESTAMP WITHOUT TIME ZONE)
RETURNS BIGINT
LANGUAGE SQL
IMMUTABLE STRICT
AS 'SELECT EXTRACT(EPOCH FROM $1)::bigint;';
CREATE OR REPLACE FUNCTION UNIX_TIMESTAMP(TIMESTAMP WITH TIME ZONE)
RETURNS BIGINT
LANGUAGE SQL
IMMUTABLE STRICT
@rturowicz
rturowicz / page.py
Last active December 19, 2018 11:50
django - intermediate admin page
# admin.py: admin action definition
def make_copy(self, request, queryset):
form = None
if 'apply' in request.POST:
form = CopyPageForm(request.POST)
if form.is_valid():
issue = form.cleaned_data['issue']
@rturowicz
rturowicz / scaled.py
Last active December 16, 2015 17:41
django - ImageField scaled-down on the fly
# models.py: overwritten model save method
def save(self, *args, **kwargs):
if self.cover:
img_string = StringIO()
pil_image = Image.open(self.cover.file)
if pil_image:
res_image = pil_image.resize((1034, 1400))
res_image.save(img_string, pil_image.format)
# original image replaced by thumbnail
self.cover.file = InMemoryUploadedFile(
@rturowicz
rturowicz / switch.py
Created April 5, 2013 16:44
switch implementation
'''switch implementation'''
def a(what):
print what
def switch(what):
try:
{'1' : lambda : a('one'),
'2' : lambda : a('two')
}[what]()
@rturowicz
rturowicz / utf8.py
Last active December 15, 2015 19:49
read / write utf-8 files
import codecs
infile = codecs.open("file", "r", "utf-8")
line = infile.readline()
while line:
print line
#!/bin/bash
# +----------------------------------------------------------------------+
# | |
# | Mount the root file system / with the option noatime |
# | |
# | By Philipp Klaus <http://blog.philippklaus.de> |
# | Tip found on <http://blogs.nullvision.com/?p=275> |
# | |
# +----------------------------------------------------------------------+