Skip to content

Instantly share code, notes, and snippets.

View crap0101's full-sized avatar

Marco Chieppa crap0101

View GitHub Profile
## !!! gawk, non posix
## run: gawk -v cmp=[fst|snd] -f thisfile
## prints half `lspci -k` output, cutting sensibly ;)
## see: https://forum.ubuntu-it.org/viewtopic.php?f=33&t=654734&sid=8194abf8e927662044c7c8f3ab902872
function fst(val, cmp) {
return (val < cmp) ? 1 : 0
}
function snd(val, cmp) {
# Cfr. https://forum.ubuntu-it.org/viewtopic.php?p=5297724#p5297724
# ... and https://forum.ubuntu-it.org/viewtopic.php?f=33&t=649359
# ... and https://gist.github.com/crap0101/7dd3acd6f294507505fc23a5b62890ef
import argparse
import functools
import itertools
import collections
import math
# Cfr. https://forum.ubuntu-it.org/viewtopic.php?p=5297724#p5297724
# ... and https://forum.ubuntu-it.org/viewtopic.php?f=33&t=649359
import math
import time
def is_primo(n):
lst_range = [x for x in range(2, n+1)]
lim = int(math.sqrt(n))
#!/usr/bin/env python3
# Cfr. https://forum.ubuntu-it.org/viewtopic.php?f=33&t=649253
import argparse
import collections
import random
import sys
import timeit
@crap0101
crap0101 / gist:6443801
Last active December 22, 2015 08:18
access list diff
# Cfr. http://rickystewart.wordpress.com/2013/09/03/why-sorting-an-array-makes-a-python-loop-faster/
from __future__ import print_function
import random
import timeit
MAX = int(1e6)
ls = [x for x in range(MAX)]
lu = [x for x in range(MAX)]
random.shuffle(lu)
@crap0101
crap0101 / gist:1428344
Created December 3, 2011 22:26
python implementation of a MENACE machine (a sort of)
#!/usr/bin/env python
#coding: utf-8
import shelve
from contextlib import closing
import itertools as it
import time
import random
import argparse
@crap0101
crap0101 / conway.py
Created June 9, 2011 03:30
Conway's Game of Life with pygame
# -*- coding: utf-8 -*-
# This file is part of ImparaParole and is released under a MIT-like license
# Copyright (c) 2010 Marco Chieppa (aka crap0101)
# See the file COPYING.txt in the root directory of this package.
"""
Conway's Game of Life (modified to be used with pygame)
NOTE: needs the classes GenericGameObject and Grid
@crap0101
crap0101 / lazy_set.py
Created February 8, 2011 14:46 — forked from rik0/lazy_set.py
#coding: utf-8
# Copyright (C) 2011 by Enrico Franchi (tweaks by crap0101)
#
# This file is released under the terms of the MIT license
# http://www.opensource.org/licenses/mit-license.php
import itertools as it
import functools