Skip to content

Instantly share code, notes, and snippets.

@rubik
rubik / A.py
Last active December 16, 2015 17:39
My solution to the problem A of the round 1A of Google Code Jam 2013
'''
Problem solution
----------------
The area of a circular ring is:
pi * (R^2 - r^2)
where R is the radius of the bigger circle and r
the radius of the other one.
test/Spec.hs:57:44:
Couldn't match type ‘m’ with ‘Pipes.Safe.SafeT IO’
‘m’ is a rigid type variable bound by
the type signature for
shouldReturnP :: (MonadIO m, MonadSafe m) =>
IO (Producer FilePath m ()) -> [FilePath] -> Expectation
at test/Spec.hs:53:18
Expected type: Producer FilePath (Pipes.Safe.SafeT IO) ()
Actual type: Producer FilePath m ()
Relevant bindings include
@rubik
rubik / Alb-DS.txt
Last active November 4, 2015 10:54
group: esempio alberghi
Cliente = { CodC, NomeC
1, Mario
2, Giuseppe
3, Laura
4, Angela
}
Albergo = { CodA, NomeA, Comune, NumStelle:number
@rubik
rubik / sub_ex.py
Created September 29, 2012 13:58
Subclassing example with rik0's ParamUnittest
from paramunittest import *
@parametrized((1, 2))
class TestLess(ParametrizedTestCase):
def setParameters(self, a, b):
self.a = a
self.b = b
@rubik
rubik / sub_example.py
Created September 23, 2012 08:41
ParamUnittest failure when unittest's skip is used (subclassing)
import unittest
from paramunittest import *
@parametrized(
('1', '2'),
)
class TestFoo(ParametrizedTestCase):
def setParameters(self, a, b):
self.a = a
@rubik
rubik / test.txt
Created August 24, 2012 19:40
Wheel testing with Pip
$ ls hammock/dist/
hammock-0.1.0-py27-none-any.whl
$ pip install hammock --no-index --find-links file:///home/miki/exp/hammock/dist
Ignoring indexes: http://pypi.python.org/simple/
Downloading/unpacking hammock
Requirement already satisfied (use --upgrade to upgrade): requests>=0.13.6 in ./lib/python2.7/site-packages/requests-0.13.6-py2.7.egg (from hammock)
Installing collected packages: hammock
Successfully installed hammock
Cleaning up...
import math
import itertools
import collections
def sum_column(data):
return sum(zip(*data)[1], 0.0)
def split_groups(sensors):
@rubik
rubik / split_in_columns.py
Created April 25, 2012 08:57
Split a number in batches
'''
Split a long number in batches.
>>> k = 178684461669052552311410692812805706249615844217278044703496837914086683543763273909969771627106004287604844670397177991379601L
>>> print pretty(k)
17868446 16690525 52311410 69281280 57062496 15844217 27804470 34968379
14086683 54376327 39099697 71627106 00428760 48446703 97177991 379601
>>> print pretty(k, 3, 9)
@rubik
rubik / kivy_multistroke_profiling.txt
Created April 8, 2012 18:13
Kivy multistroke recognition profiles (with cProfile)
1964 function calls in 0.024 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.024 0.024 <string>:1(<module>)
2 0.000 0.000 0.000 0.000 clock.py:121(_hash)
2 0.000 0.000 0.000 0.000 clock.py:135(__init__)
1 0.000 0.000 0.000 0.000 clock.py:159(get_callback)
1 0.000 0.000 0.000 0.000 clock.py:178(release)
@rubik
rubik / find_roots.py
Created February 29, 2012 16:07
Polynomial parsing and division (by Ruffini's method)
import poly
import operator
import fractions
import functools
import itertools
def is_root(p, k):
'''
True if k is a root of the polynomial p, False otherwise.