Skip to content

Instantly share code, notes, and snippets.


Karol Kuczmarski Xion

View GitHub Profile
Xion / git-today
Last active Aug 29, 2015
Git command displaying work summary for today
View git-today
# git-today
# Usage:
# * Name it `git-today` and put somewhere inside a `$PATH` directory
# * Invoke as $ git today
LAST_BEFORE_TODAY=$(git log --oneline --until='yesterday 23:59:59' | head -1 | cut -d' ' -f 1)
git diff ${LAST_BEFORE_TODAY}..HEAD --stat
Xion /
Created Dec 28, 2014
Cell enum from Taphoo
* An utility class to hold ranges of cells' values.
* @author Xion
final class CellRanges {
* Private constructor to prevent instantiation.
Xion /
Created Nov 3, 2011
Very simple optimization problem
# The wreck of a plane in a desert is 15 miles from the nearest point A on a straight road.
# A rescue truck starts for the wreck at a point on the road that is 30 miles distant from A.
# If the truck can travel at 80 mph on the road and at 40 mph on a straight path in the desert,
# how far from A should the truck leave the road to reach the wreck in a minimum time?
from math import sqrt
def truck_time(turn_point):
road_distance = turn_point
skipped_road_distance = 30 - turn_point
from jinja2.ext import Extension
from jinja2.nodes import CallBlock, Output, MarkSafe
class CaptureExtension(Extension):
''' Generic capture extension, useful for providing
content that should go into specific places in HTML template,
such as the <head> tag for JavaScript includes.
Syntax for providing content for so-called 'dataset' (here it's "js"):
Xion / gist:1804474
Created Feb 11, 2012
A neat little numerical puzzle
View gist:1804474
This puzzle is (allegedly) solved by elementary school children in 5 to 10 minutes,
but adults usually struggle with it much longer.
Xion /
Created Mar 23, 2012
Monads in Python!
# Monadic IO
def print_(s):
def _():
print s
return _
def some_io():
for x in ['Hello', 'World']:
yield print_(x)
Xion /
Created May 28, 2012
Analysis of keywords in few popular languages
Analyzing keywords from different programming languages.
def word_stats(words):
count = len(words)
len_sum = sum(map(len, words))
return {
'count': count,
'total_chars': len_sum,
Xion /
Created Aug 5, 2012
Arrow-controlled movement in console with ncurses and Python
#!/usr/bin/env python
import curses
curses.KEY_LEFT: (0, -1),
curses.KEY_UP: (-1, 0),
curses.KEY_RIGHT: (0, 1),
curses.KEY_DOWN: (1, 0),
Xion /
Last active Oct 11, 2015
Scrambling word letters in legible way
import random
def scramble(text):
"""Scrambles the letters in given text, except for first
and last one in every word.
words = text.split()
for i in xrange(words):
if len(words[i]) < 3:
Xion /
Created Oct 25, 2015
SQLAlchemy column type for storing Python enums
from enum import Enum
from inspect import isclass
import re
from sqlalchemy.types import TypeDecorator, TypeEngine
__all__ = ['EnumType']
You can’t perform that action at this time.