Add a Separator Between Commands in Terminal

Original post in lifehacker.com here.

The code for Mac: (paste to a file, and source from ~/.bash_profile)

############################################
# Modified from emilis bash prompt script
# from https://github.com/emilis/emilis-config/blob/master/.bash_ps1
#
# Modified for Mac OS X by
# @corndogcomputer
###########################################

# Fill with minuses
# (this is recalculated every time the prompt is shown in function prompt_command):
fill=”— “

reset_style=’\[\033[00m\]’
status_style=$reset_style’\[\033[0;90m\]’ # gray color; use 0;37m for lighter color
prompt_style=$reset_style
command_style=$reset_style’\[\033[1;29m\]’ # bold black
# Prompt variable:

PS1=”$status_style”‘$fill \t\n'”$prompt_style”‘${debian_chroot:+($debian_chroot)}\u@\h:\w\$'”$command_style “

# Reset color for command output
# (this one is invoked every time before a command is executed):
trap ‘echo -ne “\033[00m”‘ DEBUG

function prompt_command {

# create a $fill of all screen width minus the time string and a space:
let fillsize=${COLUMNS}-9
fill=””
while [ “$fillsize” -gt “0” ]
do
fill=”-${fill}” # fill with underscores to work on
let fillsize=${fillsize}-1
done

# If this is an xterm set the title to user@host:dir
case “$TERM” in
xterm*|rxvt*)
bname=`basename “${PWD/$HOME/~}”`
echo -ne “\033]0;${bname}: ${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007”
;;
*)
;;
esac

}
PROMPT_COMMAND=prompt_command

A Python Tool to export Read It Later list to Instapaper

Needed to move my “Read It Later” reading list to Instapaper so I wrote this script.

To use it, you need: Python, Read it Later username, password and API key, Instapaper username and password.

Notice that if the reading list is long, it will take some time to finish, since each item issues a HTTP request to Instapaper.

Sorry about the typos in the code. Too lazy to fix.

Get the script at malloc.co public repo in GitHub.

Please let me know if you face problems.

 

PLY – Python Lex-Yacc

PLY is a python implementation of lex & yacc. Allowing you to implement a lexer, interpreter or compiler in python.

If you have used lex/yacc (or flex/bison) before, it is very straightforward to use.

Official Page

Official Documentation

An example of implementing a calculator with PLY. You can start here if you want to get going quickly.

I used it and it is (combined with the power of python) really powerful.