Skip to content

Instantly share code, notes, and snippets.

Getting to a Bash prompt from inside PDB

Sometimes I'm doing stuff in PDB, the Python debugger, and I would like to hop out to a Bash prompt. Maybe I want to see what is the current directory, or what files are in the current directory, or I'd like to run some executable in this environment, or see what is on the current path. Anyway the trick is to do this.

$ python -m pdb foo.py 
> /Users/wware/foo.py(3)<module>()
#!/usr/bin/env python
"""
The top five vertices are at 72-degree increments at a height of z=A.
The next five vertices are at the same 72-degree incremenets at a
height of z=B. Next five are offset by 36 degrees, with z=-B, and last
five are also offset by 36 degrees with z=-A. The trick is to make sure
all the lengths are the same, and solve for A and B.
Let Ea and Fa be two adjacent vertices of the top five. Let Eb and Fb
be the vertices below them at z=B. Let Gb be the vertex connecting to
@wware
wware / widget010.scad
Last active June 15, 2019 20:45
3d-printable widget for Veracode's new "010" logo
$fn = 120;
thickness = 8;
height = 12;
width = 2;
module zero() {
difference() {
translate([0, 0, -.5*thickness])
cylinder(h=thickness, d=height);
translate([0, 0, -.5*thickness-1])
@wware
wware / commands.py
Last active May 2, 2019 17:36
A little command infrastructure thing to simplify using argparse.
import argparse
import logging
import os
import pdb
import re
import subprocess
_cmds = {}
_args = []
@wware
wware / git_ancestors.py
Last active April 18, 2019 20:05
A breadth-first-search decorator to search the history of a git repository to find the most recent commit(s) satisfying some criterion.
import os
from functools import wraps
def cmd(x):
return os.popen(x).read().strip()
def predecessors(hash):
return cmd("git log --pretty=%P -n 1 {0}".format(hash)).split(" ")
def is_a_merge_commit(hash):
@wware
wware / 1_kubernetes_on_macOS.md
Last active February 15, 2019 22:19 — forked from kevin-smets/1_kubernetes_on_macOS.md
Local Kubernetes setup on macOS with minikube on VirtualBox and local Docker registry

Requirements

Minikube requires that VT-x/AMD-v virtualization is enabled in BIOS. To check that this is enabled on OSX / macOS run:

sysctl -a | grep machdep.cpu.features | grep VMX

If there's output, you're good!

Prerequisites

"""
There is an unfortunate thing about Python scoping. You can't easily access the variables
of a calling function (as you can do in Scheme) so if you want to use those variables you
need to jump thru silly hoops. See
https://stackoverflow.com/questions/15608987/access-variables-of-caller-function-in-python
The nice thing about using a caller's variables is that it provides a nice way to do closures.
Variable access in closures will work OK as long as you are not ASSIGNING the variable. In
this case, we assign indices of "scope" but we never assign scope itself -- if we did, Python
would conclude that scope belongs to stuff, not to make_thing. Annoying.
@wware
wware / using_git-svn.md
Last active November 29, 2018 21:08 — forked from rickyah/using_git-svn.md
A simple guide to git-svn

Getting started with git-svn

git-svn is a git command that allows using git to interact with Subversion repositories.git-svn is part of git, meaning that is NOT a plugin but actually bundled with your git installation. SourceTree also happens to support this command so you can use it with your usual workflow.

Reference: http://git-scm.com/book/en/v1/Git-and-Other-Systems-Git-and-Subversion

Cloning the SVN repository

You need to create a new local copy of the repository with the command

@wware
wware / goldbach.py
Last active November 28, 2018 14:30
"""
https://twitter.com/fermatslibrary/status/1067423316095508480
Today's paper is a good example of an unsolved conjecture being disproved by counterexample.
Goldbach stated that every positive odd integer is either prime or the sum of a prime and
twice a square. 5777 and 5993 are the only known counterexamples.
https://fermatslibrary.com/s/a-not-so-famous-goldbach-conjecture#email-newsletter
"""
# this is python 2, not python3