View Cell.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pl.org.xion.taphoo.logic; | |
/** | |
* An utility class to hold ranges of cells' values. | |
* @author Xion | |
*/ | |
final class CellRanges { | |
/** | |
* Private constructor to prevent instantiation. |
View truck_time.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
View jinja_capture.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"): | |
View gist:1804474
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This puzzle is (allegedly) solved by elementary school children in 5 to 10 minutes, | |
but adults usually struggle with it much longer. | |
8809=6 | |
7111=0 | |
2172=0 | |
6666=4 | |
1111=0 | |
3213=0 | |
7662=2 |
View monads.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Monadic IO | |
def print_(s): | |
def _(): | |
print s | |
return _ | |
def some_io(): | |
for x in ['Hello', 'World']: | |
yield print_(x) |
View almost_roguelike.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import curses | |
SHIFTS = { | |
curses.KEY_LEFT: (0, -1), | |
curses.KEY_UP: (-1, 0), | |
curses.KEY_RIGHT: (0, 1), | |
curses.KEY_DOWN: (1, 0), |
View scramble.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
continue |
View sqla_enum.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from enum import Enum | |
from inspect import isclass | |
import re | |
from sqlalchemy.types import TypeDecorator, TypeEngine | |
__all__ = ['EnumType'] | |
View objectproperty.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def objectproperty(func): | |
"""Alternate version of the standard ``@property`` decorator, | |
useful for proeperties that expose setter (or deleter) in addition to getter. | |
It allows to contain all two/three functions and prevent PEP8 warnings | |
about redefinion of ``x`` when using ``@x.setter`` or ``@x.deleter``. | |
Usage:: |
View url_for_ex.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from flask import url_for | |
from myflaskapp import app | |
def url_for_ex(endpoint, **values): | |
"""Improved version of standard Flask's :func:`url_for` | |
that accepts an additional, optional ``_strict`` argument. | |
:param _strict: If ``False``, values for the endpoint are not checked |
OlderNewer