Skip to content

Instantly share code, notes, and snippets.

@rubik
rubik / .gitignore
Last active August 29, 2015 14:15
Formulario di Chimica I e principali composti organici
*.aux
*.fdb_latexmk
*.pdf
*.log
*.fls
@michalmarczyk
michalmarczyk / sieve.py
Created January 7, 2010 22:40
priority queue-based, wheel-using incremental prime number sieve in Python
# A priority queue-based, wheel-using incremental Sieve of Eratosthenes.
# See `The Genuine Sieve of Eratosthenes' by Melissa E. O'Neill
# (http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf)
# for the Haskell incremental sieve which inspired this implementation
# (along with detailed analyses of performance of several Haskell
# sieves).
#
# Usage:
# Sieve() -> simple SoE
# Sieve(Wheel(4)) -> SoE + a wheel based on 4 initial primes
@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)
@qwcode
qwcode / gist:3828683
Created October 3, 2012 18:07
"pip wheel"
Usage: pip wheel [OPTIONS] PACKAGE_NAMES...
Creates wheel archives from your requirements and place into ./wheels
(requires distribute>0.6.28 and wheel)
-w --wheel-dir <DIR> //alternative dir to place wheels into
--force-rebuild //rewrite existing wheels
--unpack-only <DIR> //unpack to dir, for manual building with "setup.py bdist_wheel"
-r, --requirement <FILENAME>
-f, --find-links <URL>
@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 / 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
@keis
keis / coro.py
Created April 14, 2014 08:27
asyncio examples
import asyncio
@asyncio.coroutine
def waiting(r):
print("hello from waiting -", r)
yield from asyncio.sleep(2)
print("bye from waiting -", r)
return r
@carlsmith
carlsmith / barcode.py
Last active March 27, 2018 11:15
Interleaved 2 of 5, SVG Barcode Generator
def render(digits):
'''This function converts its input, a string of decimal digits, into a
barcode, using the interleaved 2 of 5 format. The input string must not
contain an odd number of digits. The output is an SVG string.
Wikipedia [ITF Format]: http://en.wikipedia.org/wiki/Interleaved_2_of_5
'''
top = '<svg height="58" width="{0}" style="background:white">'
@rik0
rik0 / AtkinSieveArray.java
Created July 22, 2011 11:16
Lots of Atkin and some Erat
import java.lang.Boolean;
import java.lang.Integer;
public class AtkinSieveArray {
static private int count(boolean[] buffer) {
int counter = 0;
for(int i = 2; i < buffer.length; ++i) {
if(buffer[i]) {
counter++;
@mikelikespie
mikelikespie / argbase.py
Created July 28, 2012 05:34
Interface for Argparse Similar to Declarative base
import abc
import re
import argparse
class ArgBaseError(Exception): pass
def _inject_vals(name, bases, dict):
expected_args = {}