Skip to content

Instantly share code, notes, and snippets.

import math
import itertools
import collections
def sum_column(data):
return sum(zip(*data)[1], 0.0)
def split_groups(sensors):
@rubik
rubik / gisty.py
Created July 9, 2012 19:53
Example command line program powered by Baker and other cool libraries (pathlib, slumber & colorama)
import sys
import baker
import slumber
import pathlib
import colorama
API_URL = 'https://api.github.com/'
def get_api(auth=None):
@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...
@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 / 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 / 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.
@rubik
rubik / apples.py
Last active December 17, 2015 20:49
Python solution for SPOJ problem 'Buying apples'
import collections
# From
# http://stackoverflow.com/questions/1653970/does-python-have-an-ordered-set
class OrderedSet(collections.OrderedDict, collections.MutableSet):
def update(self, *args, **kwargs):
if kwargs:
raise TypeError("update() takes no keyword arguments")
@rubik
rubik / arch-strap.sh
Last active December 18, 2015 16:38
A little script that does the basic things when installing ArchLinux
#!/bin/bash
# Configuration
root=/dev/sda3
boot=/dev/sda1
home=/dev/sda4
lang=en_US-UTF-8
keyboard=it
zone=Europe
subzone=Rome
@rubik
rubik / pi_digits.py
Last active December 22, 2015 00:48
Computing PI digit by digit. The input to the function is the number of decimal digits.
f=lambda w=4:(lambda j,o,i:(lambda s,g:list(i.takewhile(lambda _:len(o)<w+1,
(((4*g(0)+g(1)-g(2)<g(4)*g(2)and(o.append(int(g(4))),s(6,10*(g(1)-g(4)*g(2))),
s(4,((10*(3*g(0)+g(1)))//g(2))-10*g(4)),s(0,g(0)*10),s(1,g(6))))or(s(6,(2*g(0)
+g(1))*g(5)),s(7,(g(0)*(7*g(3))+2+(g(1)*g(5)))//(g(2)*g(5))),s(0,g(0)*g(3)),
s(2,g(2)*g(5)),s(5,g(5)+2),s(3,g(3)+1),s(4,g(7)),s(1,g(6))))for _ in iter(int,1)
)))and o)(lambda v,y:j.__setitem__(v,y),lambda v:j[v]))([1,0,1,1,3,3,-1,-1],[],
__import__('itertools'))
@rubik
rubik / program01.py
Created February 5, 2014 20:42
Homework04, program01.py
'''Definire una classe PColor e una classe PImage secondo le seguenti specifiche.
La classe PColor rappresenta un pixel che puo' avere un colore RGB o essere
trasparente e deve implementare i seguenti metodi:
- Costruttore, senza argomenti, che inizializza l'oggetto come pixel trasparente.
- set_RGB(r, g, b) imposta il colore RGB dell'oggetto con i valori r,g,b e
ritorna l'oggetto.
- to_RGB() ritorna una tripla (r,g,b) che sono i valori dei canali RGB