Skip to content

Instantly share code, notes, and snippets.

dpkg-source: error: cannot represent change to .tox/py33/include/python3.3m:
dpkg-source: error: new version is symlink to /usr/include/python3.3m
dpkg-source: error: old version is nonexistent
dpkg-source: error: cannot represent change to .tox/py33/lib/python3.3/tempfile.py:
dpkg-source: error: new version is symlink to /usr/lib/python3.3/tempfile.py
dpkg-source: error: old version is nonexistent
dpkg-source: error: cannot represent change to .tox/py33/lib/python3.3/posixpath.py:
dpkg-source: error: new version is symlink to /usr/lib/python3.3/posixpath.py
dpkg-source: error: old version is nonexistent
dpkg-source: error: cannot represent change to .tox/py33/lib/python3.3/tokenize.py:
#!/usr/bin/env python
import sys
import argparse
def mkvirtualenv_argparser():
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--python')
parser.add_argument('-i', action='append', dest='packages', help='Install \
a package after the environment is created. This option may be repeated.')
@berdario
berdario / dummyhttp.py
Created December 7, 2014 21:22
A toy HTTP server in pure Python3 I wrote in September 2013
#! /usr/bin/env python
import sys
import os
import locale
from collections import defaultdict
from socket import socket, AF_INET, SOCK_STREAM
from urllib.parse import urlparse
from contextlib import closing
from functools import wraps
@berdario
berdario / dummyhttp.py
Created December 7, 2014 21:37
3to2 porting of the 2to3 porting of the 3to2 porting of https://gist.github.com/berdario/39313b94cd08ebe6b3fb portingception!
#! /usr/bin/env python
from __future__ import with_statement
import sys
import os
import locale
from collections import defaultdict
from socket import socket, AF_INET, SOCK_STREAM
from urlparse import urlparse
#!/usr/bin/env ruby
bytes=(0..255).to_a
valid=bytes.product(bytes)
.map{|a,b|(a.chr+b.chr).force_encoding('EUC-JISX0213')}
.select &:valid_encoding?
jis_only = valid.select{ |s| s.encode('UTF-8', undef: :replace) == "\uFFFD" }
# this will obtain only the valid characters that we can't convert to unicode
@berdario
berdario / _utils.py
Last active February 21, 2023 13:29
A simple python hook system that doesn't mutate global variables and tries to be as side-effect free as possible
from __future__ import print_function
import sys
from collections import namedtuple
from imp import load_module, find_module
from pathlib import Path
Hooks = namedtuple('Hooks', 'preactivate postactivate get_env_details postrmvirtualenv')
_HOOKS = Hooks._fields
@berdario
berdario / withFiles.hs
Created January 16, 2015 19:28
I felt the need for an n-ary version of withFile. It works, but for something this simple, readFile + writeFile would've been enough
import System.Environment (getArgs)
import System.IO (withFile, IOMode(..), FilePath, Handle, hGetContents, hPutStr)
import Data.Functor ((<$>))
withFiles' :: [Handle] -> [(IOMode, FilePath)] -> ([Handle] -> IO r) -> IO r
withFiles' handles [] f = f $ reverse handles
withFiles' handles ((mode, fpath):xs) f = withFile fpath mode (\x -> withFiles' (x:handles) xs f)
withFiles = withFiles' []
@berdario
berdario / nixnotes.md
Last active August 29, 2015 14:14
Nix notes

It's been a while since I started to use Nixos, and I promised myself to improve the documentation/wiki, but since I haven't overcome yet the barrier of entry to that, and some of the information that I discovered/asked on irc/etc might otherwise be forgotten, I'll temporarily keep track of it here:

  • Don't rely too much on nix-shell/nix-build: the Phases will kick you out of the shell if an error happens, and you won't be able to load the correct scripts, I reported this here but I'll probably need to add some more details
  • Apparently there's no way to see software that is available for another platform (this would be useful in a porting effort): you have to manually grep nixpkgs yourself
  • There's no way to do a partial match query on nix-env: just nix-env -qaP "*" and grep it
  • The nix manual is seriously paltry when discussing the Nix language itself: some operators aren't even mentioned (e.g. <)
  • If
@berdario
berdario / fulltextindex.hs
Created February 11, 2015 09:11
A simple text index/full text search in Haskell (I wanted a simple, but non-trivial fold example)
import qualified Data.Map.Strict as M
import qualified Data.Set as S
docs = ["the quick brown fox jumps over the lazy dog",
"what does the fox say?",
"what is the meaning of life?"]
buildIndex docs = M.unionsWith S.union [foldr (flip M.insert $ S.singleton doc) M.empty $ words doc | doc <- docs]
search _ [] = S.empty
package object wordwrap{
def wrapSingleLine(column: Int)(words: List[String]): Iterable[String] = words match {
case List() => List();
case (hd :: tl) => {
tl.scanLeft(hd)({_ + " " + _}).span({_.length <= column}) match {
case (List(), _) => hd.grouped(column).toIterable ++ wrapSingleLine(column)(tl)
case (f, s) => {
val f2 = f.map({_.split(" ").last})
f2 ++ wrapSingleLine(column)(s.map{_.drop(f2.last.length)});
}