Skip to content

Instantly share code, notes, and snippets.

View senko's full-sized avatar

Senko Rašić senko

View GitHub Profile
@senko
senko / i18n.py
Created March 21, 2013 14:08
Compile translations for all languages in a single map, for Django.
from gettext import translation
import os.path
from django.conf import settings
def get_all_translations(domain):
"""Return a language code => translations mapping for all defined
languages. This is useful if in a single view you need to use
different translation catalogs at the same time.
@senko
senko / create-new-lxc.sh
Created March 1, 2013 13:00
Set up a new LXC virtual machine
#!/bin/bash
#
# Initialize new virtual server using LXC and set up networking and HTTP proxy
#
# Written by: Deni Bertovic <deni.bertovic@dobarkod.hr>
#
# Released into Public Domain. You may use, modify and distribute it as you
# see fit.
#
# This script will:
@senko
senko / singleton.py
Created February 25, 2013 08:01
Singleton Django Model
# Written by Senko Rasic <senko.rasic@goodcode.io>
# Released into Public Domain. Use it as you like.
from django.db import models
class SingletonModel(models.Model):
"""Singleton Django Model
Ensures there's always only one entry in the database, and can fix the
@senko
senko / trigger.py
Created January 9, 2013 09:49
When triggered via a HTTP request, execute a command.
#!/usr/bin/env python
#
# When triggered via a HTTP request, execute a command.
#
# Written by Senko Rasic <senko.rasic@goodcode.io>
# Released into Public Domain. Use it as you like.
#
# Usage: python trigger.py <host> <port> <key> <command>...
#
# HTTP GET and POST requests are supported. If you need more verbs or need
@senko
senko / structsign.py
Created November 16, 2012 11:32
sign_structure - sign nested Python structures (including dicts) while ignoring dict ordering
from hashlib import sha1
import unittest
__all__ = ['sign_structure']
def sign_structure(data):
"""Create a (non-cryptographic) signature of the data structure.
This function makes sure that dict item ordering doesn't matter.
@senko
senko / screen-paste.sh
Created September 26, 2012 19:16
Grab a screenshot and paste it to the Web using pixbin.us
#!/bin/bash
#
# screen-paste - Paste a screenshot to the Web (using pixbin.us service)
#
# Written by Senko Rasic <senko.rasic@goodcode.io>
# Released into Public Domain. Use it as you like.
#
# The tool allows the user to select a portion of the screen, then copies it
# to pixbin.us, and stores the resulting URL in clipboard.
#
@senko
senko / gist:3505177
Created August 28, 2012 23:11
Grab a screenshot and paste it to the Web
#!/bin/bash
#
# screen-paste - Paste a screenshot to the Web
#
# Written by Senko Rasic <senko.rasic@goodcode.io>
# Released into Public Domain. Use it as you like.
#
# The tool allows the user to select a portion of the screen, then copies it
# to S3, and stores the resulting URL in clipboard.
#
@senko
senko / locals-fix.diff
Created August 6, 2012 19:26
locals() fix for SublimeLinter
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index fa2494e..f1eff00 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -131,6 +131,7 @@ def names(self):
class Scope(dict):
importStarred = False # set to True when import * is found
+ usesLocals = False
@senko
senko / gist:2988592
Created June 25, 2012 13:31
Easy VirtualBox VM handling for the command line
#!/bin/bash -e
#
# Easy VirtualBox VM handling from the command line
BASE_TEMPLATE="<uid-of-template-vm>"
function show_help() {
echo "Usage: $0 [cmd]"
echo "Valid commands:"
echo " list List available virtual machines"
@senko
senko / vcf2csv.py
Created May 14, 2012 07:47
Simple vCard to CSV converter (only uses name, phone, email info)
#!/usr/bin/env python
"""
Parse phone and email records out of vCard file and store them in a CSV.
Copyright (C) 2012 Senko Rasic <senko.rasic@dobarkod.hr>
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