Skip to content

Instantly share code, notes, and snippets.

View ViktorStiskala's full-sized avatar

Viktor Stískala ViktorStiskala

View GitHub Profile
def split_sum_into_parts(limit=1500, min_parts=2, max_parts=5):
sample = sorted([0, limit] + random.sample(range(limit), random.randint(min_parts-1, max_parts-1)))
return [sample[i+1] - item for i, item in enumerate(sample) if i+1 < len(sample)]
def split_sum_into_parts(limit=1500, min_parts=2, max_parts=5):
sample = sorted([0, limit] + random.sample(range(limit), random.randint(min_parts-1, max_parts-1)))
return [sample[i+1] - item for i, item in enumerate(sample) if i+1 < len(sample)]
with open('even_numbers.txt', 'w') as f:
for number in (n for n in range(10**100) if n%2 == 0):
f.write('{}\n'.format(number))
@ViktorStiskala
ViktorStiskala / test.sh
Created June 29, 2015 11:19
Bash catch exception
#!/bin/bash
set -e
err_report() {
ERR=$?
echo "$1 failed on line $2 ('$3') with error code $ERR" 1>&2
exit $ERR
}
trap 'err_report "$BASH_SOURCE" "$LINENO" "$BASH_COMMAND"' ERR
echo "l" | grep f
@ViktorStiskala
ViktorStiskala / bash_colors.sh
Created July 20, 2015 09:07
Bash color variables
# source: https://wiki.archlinux.org/index.php/Color_Bash_Prompt
txtblk='\e[0;30m' # Black - Regular
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtylw='\e[0;33m' # Yellow
txtblu='\e[0;34m' # Blue
txtpur='\e[0;35m' # Purple
txtcyn='\e[0;36m' # Cyan
txtwht='\e[0;37m' # White
#!/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 / 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/