Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Topmenu and the submenus are based of the example found at this location http://blog.skeltonnetworks.com/2010/03/python-curses-custom-menu/
# The rest of the work was done by Matthew Bennett and he requests you keep these two mentions when you reuse the code :-)
# Basic code refactoring by Andrew Scheller
import curses, os #curses is the interface for capturing key presses on the menu, os launches the files
screen = curses.initscr() #initializes a new window for capturing key presses
curses.noecho() # Disables automatic echoing of key presses (prevents program from input each key twice)
curses.cbreak() # Disables line buffering (runs each key as it is pressed rather than waiting for the return key to pressed)
FROM ubuntu
MAINTAINER Mike Clarke <mike@standardtreasury.com>
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y language-pack-en
ENV LANGUAGE en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8
#!/usr/bin/env python
"""Run all processes in parallel.
Group output by process groups and order within groups
"""
import shlex
import subprocess
import sys
import threading
#!/usr/bin/env python
"""Show that a daemonic child process may have multiple threads."""
import multiprocessing
import threading
def child_process():
# start a thread
threading.Thread(target=child_thread).start()
# show that we can't have grandchildren processes
#!/usr/bin/env python
"""Translate text_to_translate using microsoft translator service."""
import json
import xml.etree.ElementTree as etree
try:
from urllib import urlencode
from urllib2 import urlopen, Request
except ImportError: # Python 3
from urllib.parse import urlencode
from urllib.request import urlopen, Request
#!/usr/bin/env python
"""Try to cause MemoryError by sending large data via multiprocessing.Pipe.
Context: http://stackoverflow.com/q/22150703
"""
from multiprocessing import Process, Pipe
def send_big_data(conn):
data = b"a" * (1 << 30) # 1GB
conn.send(data)
#!/usr/bin/env python
"""
- read subprocess output without threads using Tkinter
- show the output in the GUI
- stop subprocess on a button press
"""
import logging
import os
import sys
from subprocess import Popen, PIPE, STDOUT
#!/usr/bin/env bash
# call like this on the target server:
# NODENAME='foo' CHEF_ENV='production' RUNLIST='["role[foo]","recipe[bar]"]' CHEFREPO='git@example.com:repo.git' bash <( curl -L https://raw.github.com/gist/1026628 )
# You will need to ensure that the ssh key is already set up on the server.
set -e
export CHEF_DIR="${HOME}/chef"
sudo rm -rf $CHEF_DIR
mkdir -p "$CHEF_DIR"
@zennro
zennro / gist:9807714
Created March 27, 2014 13:37
generate entropy for corosync-keygen
while /bin/true; do dd if=/dev/urandom of=/tmp/100 bs=1024 count=100000; for i in {1..10}; do cp /tmp/100 /tmp/tmp_$i_$RANDOM; done; rm -f /tmp/tmp_* /tmp/100; done & /usr/sbin/corosync-keygen

Using strace and lsof to debug blocked processes

You can use strace on a specific pid to figure out what a specific process is doing, e.g.:

strace -fp <pid>

You might see something like:

select(9, [3 5 8], [], [], {0, 999999}) = 0 (Timeout)