Skip to content

Instantly share code, notes, and snippets.

@oconnor663
oconnor663 / build_debian.py
Last active August 29, 2015 14:27
Build script comparison
#! /usr/bin/env python3
from pathlib import Path
from subprocess import run, PIPE
from sys import argv
from tempfile import mkdtemp
here = Path(__file__).parent
build_root = Path(argv[1] if len(argv) >= 2 else mkdtemp())
@oconnor663
oconnor663 / osx_hang.py
Created September 5, 2015 00:24
Why does this hang on Mac but not on Linux
import os
import subprocess
r, w = os.pipe()
# Small enough to fit in the pipe buffer; won't hang.
os.write(w, b"one\ntwo\n")
# Call head twice. The first time works fine. The second hangs, but only on OSX!
subprocess.call(['head', '-c', '4'], stdin=r)
@oconnor663
oconnor663 / gist:9010980
Last active September 6, 2015 02:50
First Python problem set: if and while

If you already have a Python environment already set up that you're comfortable with, great. If not, I recommend downloading Python 3 from http://www.python.org/download/. It comes with a program called IDLE that helps you write small programs and run them. YouTube has some good videos for getting started with that, depending on whether you're running Windows, Mac, or Linux.

Here's the Python book I like to use to get started: http://openbookproject.net/thinkcs/python/english3e/

To do the problems below, you'll need to be roughly familiar with chapters 1-8 in that book, particularly chapters 5, 7, and 8. If you're starting from scratch, it might be a good idea to try the exercises in those chapters as you go along. When you're up to speed, you'll have the following basic building blocks for your programs:

  • how to print output
  • how to create variables and change their values
  • how to use if statements to make choices
  • how to use while loops to do repeated work
@oconnor663
oconnor663 / kourier_expire_times.iced
Created September 25, 2015 04:18
importing a key with time_travel=true changes the computed expiration time
kbpgp = require 'kbpgp'
armored = """-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1
mQINBFKB8x0BEADeCf76s/2pjkRKhJCGw3WeeARvMGxCInAbrQ1wHtdCBawBFdrD
oYDOvVX0vgWS+dIRv/UV7djtvji4K19tRRd79L/9BmFUfW/73va8dAyXEu9/RJIQ
+1+ku+pl8+YZ3n1ZyNRhtBMIu5QDUqf355FaIE1E6uaS1gjjUdSsWjc0CN4d1Vag
Bi/ImES4ru8+xLuePkVil4vL/3TOHQ4qNnInD2bR6pi6WSwZNUJsPeSG8RuX2GC6
a0Ou8glL53YvIW+JtY44nVbJUw824/gQZQTzVsUJTyuuvQaIRD6JzGFQHcLXa9/3
@oconnor663
oconnor663 / fizzbuzz.py
Created October 5, 2012 00:09
fizzbuzz.py
#!/usr/bin/python3
pairs = (
(3, "Fizz"),
(5, "Buzz"),
)
@oconnor663
oconnor663 / FizzBuzz.hs
Created October 5, 2012 00:56
FizzBuzz.hs
pairs = [(3, "Fizz"), (5, "Buzz")]
main = mapM_ (putStrLn . fizzLine) [0..100]
where fizzLine x = if output /= "" then output else show x
where output = concat (map snd matches)
matches = filter (\pair -> x `rem` fst pair == 0) pairs
import System.Environment
import Control.Monad
addNumbers strs = zipWith (\a b -> show a ++ " " ++ b) [1..] strs
main = do
args <- getArgs
text <- if length args > 0
then readFile (head args)
else getContents
@oconnor663
oconnor663 / subprocess_deadlock_demo.py
Last active December 2, 2015 15:23
demonstration of a Windows deadlock in subprocess.py, with extra sleeps to trigger it
#! /usr/bin/env python3
# This is a python version of this pipeline: `echo foo | cat`. It demonstrates
# a deadlock that can happen on Windows when Popen is called simultaneously
# from two different threads. Although os.pipe() file descriptors are not
# normally inheritable (never on Windows, and not in recent Python versions on
# POSIX), the Windows implementation of Popen() creates temporary inheritable
# copies of its descriptors. See _make_inheritable() in subprocess.py. If a
# second process is spawned while those inheritable copies are open, both
# children will inherit the copies. With pipes, this can cause deadlocks when
@oconnor663
oconnor663 / asyncio_contextlib_deadlock.py
Last active December 2, 2015 21:08
asyncio + contextlib deadlock (Python 3.5, but not 3.4)
#! /usr/bin/env python3
# This script reproduces a deadlock that shows up when we mix asyncio,
# generator-context-managers, and an ExitStack. I'm not sure why it happens.
# When the script hangs, it consumes 100% CPU and blocks ctrl-c. To kill it,
# use ctrl-z and then `kill %`.
import asyncio
import contextlib
diff --git a/PKGBUILD.buggy b/PKGBUILD
index c4ad354..b8c01ab 100644
--- a/PKGBUILD.buggy
+++ b/PKGBUILD
@@ -31,9 +31,6 @@ prepare() {
# Get the ANT_HOME environment variable
source /etc/profile.d/apache-ant.sh
- mkdir -p $pkgdir/usr/share/eclipse
- mkdir -p $pkgdir/usr/share/vim/vimfiles