Skip to content

Instantly share code, notes, and snippets.

@AnIrishDuck
AnIrishDuck / flock_mgr.py
Created August 29, 2012 18:59
Python flock context manager.
import fcntl
from contextlib import contextmanager
@contextmanager
def flocked(fd):
""" Locks FD before entering the context, always releasing the lock. """
try:
fcntl.flock(fd, fcntl.LOCK_EX)
yield
finally:
@AnIrishDuck
AnIrishDuck / contextlib.py
Created October 9, 2012 20:37
Some useful context manager utilities used when working with Python.
""" Utility methods for context managers. License is BSD 3-Clause. """
from collections import defaultdict
from unittest import TestCase
class nested(object):
"""
This context manager is different from ``contextlib.nested``.
``contextlib.nested`` is one-shot: once instantiated it can only be used
in a ``with`` statement once. This manager can be infinitely re-used. So
the following code works with this incarnation of ``nested``, but not with
@AnIrishDuck
AnIrishDuck / pipe_context.py
Created March 12, 2013 22:12
Pipe context manager.
import os
from contextlib import contextmanager
@contextmanager
def pipe(my_end):
"""
Context manager that produces a unidirectional pipe, automatically always
closing the other end of that pipe. Useful for creating pipes to use with
subprocesses.
@AnIrishDuck
AnIrishDuck / cmd_out_err.py
Created March 20, 2013 20:34
Similar to subprocess.check_output, but returns the results of stdout and stderr separately.
def check_out_and_err(*args, **kwargs):
"""
Pipe from BOTH stdout and stderr. Avoids deadlock by performing nonblocking
reads. Why this isn't in the stdlib is beyond me.
"""
if 'stdout' in kwargs or 'stderr' in kwargs:
raise ValueError("stdout/stderr arguments not allowed.")

Keybase proof

I hereby claim:

  • I am anirishduck on github.
  • I am anirishduck (https://keybase.io/anirishduck) on keybase.
  • I have a public key ASB3UsHkBF639z5lPcdgUozy8vWBKsuIVCTPGTr_k3VVngo

To claim this, I am signing this object:

#!/bin/bash
if [[ "$1" == "--help" ]] ; then
echo -n "Diff cloudgate secrets from HEAD to the specified git ref. " >&2
echo "Skips inaccessible vaults." >&2
echo >&2
echo "usage: $0 [REF] [ENVS...]" >&2
echo >&2
echo " REF: a git ref, defaults to HEAD^" >&2
echo " ENVS: the environments to diff, defaults to all" >&2
from petrify.solid import Vector, Box, Cylinder, Node, Union
from petrify.edge import Chamfer
port = 2.65
outer = 2.28
inner = 2.22
wall = 0.125
mm_p_in = 25.4
to_mm = Vector(mm_p_in, mm_p_in, mm_p_in)
from petrify.solid import Vector, Box, Cylinder, Node, Union
from petrify.edge import Chamfer
port = 2.65
outer = 2.28
inner = 2.22
wall = 0.125
mm_p_in = 25.4
to_mm = Vector(mm_p_in, mm_p_in, mm_p_in)
SELECT date_trunc('month', date(q.created_at)) AS month, COUNT(DISTINCT r.artifact_id) AS with_outcomes, COUNT(DISTINCT q.id) AS total FROM quizzes q
LEFT OUTER JOIN learning_outcome_results r ON (r.g_shard_id = q.g_shard_id AND r.artifact_id = q.id AND r.artifact_type = 'Quizzes::QuizSubmission')
WHERE date(q.created_at) > date('2017-07-01')
GROUP BY date_trunc('month', date(q.created_at))