This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import pickle | |
>>> class C(object): | |
... def __init__(self, banana): | |
... self.banana = banana | |
... def __reduce__(self): | |
... return (C, (self.banana,)) | |
... | |
>>> pickle.dumps(C(1)) | |
'c__main__\nC\np0\n(I1\ntp1\nRp2\n.' | |
>>> pickle.loads(pickle.dumps(C(1))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RichardB@narcissus ~$ od -t x1 /sys/bus/pci/devices/0000:01:00.0/config | |
0000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff | |
* | |
0000100 | |
RichardB@narcissus ~$ optirun glxgears >/dev/null & | |
[1] 3758 | |
RichardB@narcissus ~$ sleep 1 | |
RichardB@narcissus ~$ od -t x1 /sys/bus/pci/devices/0000:01:00.0/config | |
0000000 de 10 92 13 07 00 10 00 a2 00 02 03 00 00 00 00 | |
0000020 00 00 00 f6 0c 00 00 e0 00 00 00 00 0c 00 00 f0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html><head><meta charset="UTF-8" /> | |
<title>Odd layout example.</title> | |
<style type="text/css"> | |
#evil-container { | |
position: relative; | |
background: #aaffaa; | |
} | |
body, #evil-container { | |
width: 100%; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FindBirthday where | |
-- compile as: ghc --make FindBirthday.hs -main-is FindBirthday.main | |
-- or run as: runhaskell FindBirthday.hs | |
-- and answer "y" or "n" when the program asks you a question. :) | |
import Data.Time (formatTime, addDays) | |
import System.Locale (defaultTimeLocale) | |
-- use 2014 because that was a leap year, and we need all 366 days. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "ie_counts" | |
version = "0.0.1" | |
authors = ["Richard Barrell <[email protected]>"] | |
[[bin]] | |
name = "ie_counts" | |
crate-type = ["staticlib"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# setting ALTERNATE_EDITOR to the empty string "" instructs | |
# emacsclient to invoke Emacs in daemon-mode iff it isn't running already | |
export EDITOR=emacsclient | |
export ALTERNATE_EDITOR="" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module PrimeLastDigit where | |
-- compile with: | |
-- ghc --make PrimeLastDigit.hs -O2 -main-is PrimeLastDigit.main | |
import Data.List (foldl') | |
primes :: [Integer] | |
primes = 2 : [ c | c <- [3,5..], all (\p -> c `mod` p > 0) (takeWhile (\p -> p*p <= c) primes) ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE BangPatterns #-} | |
module Collatz where | |
-- thing I want to know: what's the smallest (n) such that a naive C | |
-- implementation of "iterate the Collatz function until I get to 1" with | |
-- fixed-size integers will encounter an integer overflow | |
-- the below is terrible and contains multiple implementations because I kept | |
-- trying to make it go faster. | |
import Data.Word |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from StringIO import StringIO | |
from hypothesis import given | |
from hypothesis.strategies import lists, binary | |
def to_lines(f, _block_size=32<<10): | |
"""file.__iter__ but in python and ought to be slower | |
>>> list(to_lines(StringIO("foo\\nbar\\nbaz\\n"), _block_size=2)) | |
['foo\\n', 'bar\\n', 'baz\\n'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import sys | |
try: | |
column_indexes = list(map(int, sys.argv[1:])) | |
except ValueError: | |
sys.stderr.write("Usage: python pick_csv.py 0 1 2...\n") | |
sys.exit(1) | |
if len(column_indexes) == 0: |