Skip to content

Instantly share code, notes, and snippets.

View ViktorStiskala's full-sized avatar

Viktor Stískala ViktorStiskala

View GitHub Profile
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Viktor Stískala
# Contact: viktor (at) stiskala.cz
# Copyright: This module has been placed in the public domain.
"""
This module removes language specific characters from file name
and makes it more usable for web. Can be also used as nautilus user script
@ViktorStiskala
ViktorStiskala / CustomRenderer.php
Created August 28, 2010 19:53
Custom renderer for Nette framework with containerClass support
<?php
/**
* Extended form renderer.
*
* @author Viktor Stískala <viktor(at)stiskala.cz>
*/
class CustomRenderer extends ConventionalRenderer
{
/**
* Renders 'control' part of visual row of controls.
@ViktorStiskala
ViktorStiskala / gist:557567
Created August 30, 2010 15:33
Wondershaper script without LAN limitation
#!/bin/bash
# Wonder Shaper
# please read the README before filling out these values
#
# Speed/Rate syntax: tcng vs. tc
# source: http://www.faqs.org/docs/Linux-HOWTO/Traffic-Control-tcng-HTB-HOWTO.html
#
# tcng English tc
# ----------------------------------------------
# bps bit(s) per second bit
@ViktorStiskala
ViktorStiskala / cclean.sh
Created October 21, 2010 20:05
cclean.sh
#!/bin/bash
#
# Transliterate and clean C code using iconv and GNU Indent
# Created: 2010-10-21
# Author: Viktor Stískala, viktor@stiskala.cz
#
filename="$1"
encoding="$2"
@ViktorStiskala
ViktorStiskala / gist:900053
Created April 3, 2011 00:26
Simple browser recognition
/*
Requires browscap.ini configuration, more info at http://php.net/manual/en/function.get-browser.php
*/
$this->template->registerHelper('browser', function($s) {
$brs = get_browser($s);
if($brs === false)
return 'N/A';
// ex.: Firefox 3.6/Linux
return $brs->browser . ' ' . $brs->version . '/' . $brs->platform;
});
@ViktorStiskala
ViktorStiskala / gist:969269
Created May 12, 2011 19:38
Allow users from www-data group to change owner of files under /var/www
#!/bin/bash
# Resursively change owner to www-data
#
# Created: 2011-05-12
# Author: Viktor Stiskala <viktor@stiskala.cz>
LOGFILE=/var/log/wwwdata
## Add following line tu sudoers file (using visudo command) in order to allow
## users from www-data group to change owners under /var/www/
@ViktorStiskala
ViktorStiskala / gist:969558
Created May 12, 2011 22:03
Simple MySQL backup script
#!/bin/bash
# MySQL backup script
# Creates database dump file for each database.
# Created: 2010-09-27
# config
BACKUP_USER=backup
BACKUP_DIR=/var/backups/mysql
LOGFILE=/var/log/mysql_backup
@ViktorStiskala
ViktorStiskala / xsendfile.py
Created July 8, 2011 08:53
XSendFileResponse for Django with fallback when XSendFile is disabled
from django.http import HttpResponse
from mimetypes import guess_type
import settings
import re, os
class XSendFileError(Exception):
pass
class XSendFileResponse(HttpResponse):
def __init__(self, file_path, content_type=None):
@ViktorStiskala
ViktorStiskala / include.sh
Created November 27, 2011 16:52
Display highlighted C include file
#!/bin/bash
if [ -z $1 ]
then
echo "Usage: include filename" 1>&2
exit 1
fi
filename="/usr/include/$1"
if [ ! -f $filename ]; then
echo "File not found" 1>&2
@ViktorStiskala
ViktorStiskala / gist:3479130
Created August 26, 2012 13:15
Amazon Glacier tree hash calculation
import math
import hashlib
def bytes_to_hex(str):
return ''.join( [ "%02x" % ord( x ) for x in str] ).strip()
def chunk_hashes(str):
"""
Break up the byte-string into 1MB chunks and return sha256 hashes
for each.