Skip to content

Instantly share code, notes, and snippets.

@rubik
rubik / frac_math.py
Created December 7, 2011 16:22
Floor and ceil function without computing division
def floor(x, y):
return (x - x % y) / float(y)
def ceil(x, y):
return floor(x - 1, y) + 1
def integer_part(x, y):
if x * y >= 0:
return floor(x, y)
return ceil(x, y)
@rubik
rubik / vc.py
Created July 3, 2011 10:28
vc.py
'''
vc.py is a slight modification of virtualenvcontext, and it offers the possibility
to use the context manager without virtualenvwrapper.
This is useful while testing things, because it allows you to works with ad hoc
virtualenvs.
'''
## Modified from virtualenvcontext (C) 2011 Ralph Bean
## http://pypi.python.org/pypi/virtualenvcontext/
@rubik
rubik / badmo.py
Created April 20, 2011 10:38
Bad modules detector (modules imported but not used)
import re
import os
import ast
import glob
import collections
class ImportVisitor(ast.NodeVisitor):
def __init__(self):
self.imports = []
self.modules = collections.defaultdict(list)
@rubik
rubik / werkzeug-pyg_themes.diff
Created March 27, 2011 09:26
Diff between Werkzeug and Pyg Sphinx themes
--- a/werkzeug.css_t
+++ b/pyg.css_t
@@ -7,8 +7,8 @@
*/
{% set page_width = '980px' %}
-{% set sidebar_width = '220px' %}
-{% set font_family = "Georgia, serif" %}
+{% set sidebar_width = '230px' %}
+{% set font_family = "'Ubuntu', serif" %}
from __future__ import division
import sys
class Person(object):
attrs = ('name', 'surname', 'birth', 'birth_place', 'gender', 'marital_status', 'address', 'job')
def __init__(self, name, surname, birth, birth_place, gender, marital_status, address, job):
kw = locals()
@rubik
rubik / infos.py
Created January 5, 2011 16:06
Python archives infos
import os
import time
import tarfile
import zipfile
def bytes2str(bytes):
if bytes < 0: return "0 B"
if bytes < 1024: return "%.2f B" % (bytes)
elif bytes < 1048576: return "%.2f Kb" % (bytes / 1024)
elif bytes < 1073741824: return "%.2f Mb" % (bytes / 1048576)
@rubik
rubik / .gitignore
Last active August 29, 2015 14:15
Formulario di Chimica I e principali composti organici
*.aux
*.fdb_latexmk
*.pdf
*.log
*.fls
module Main
where
perfectSquares :: [Int]
perfectSquares = map (^2) [1..100]
divisors :: Int -> [(Int, Int)]
divisors n = [ (i, div n i) | i <- [1..floor $ sqrt $ fromIntegral n]
, mod n i == 0]
module Main
where
import System.Environment (getArgs)
import Data.List (transpose, sort, groupBy)
import Math.Sieve.Factor (factor, sieve)
-- The Thue-Morse sequence
thueMorse :: [Int]
@rubik
rubik / 0.Guide.md
Last active August 29, 2015 14:03
Brief installation guide for ArchLinux with a bootstrap script that sets up the environment as I like it.

Installation Guide

Excerpted from the official [ArchLinux Installation Guide][1].

Keyboard layout

The available keymap files can be found in /usr/share/kbd/keymaps/ (you can omit the keymap path and file extension when using loadkeys).

Partition disks

See [partitioning][2] for details. Then, to format the partitions, see [File Systems][3] and optionally [Swap][4] for details.

Run arch-strap.sh