Skip to content

Instantly share code, notes, and snippets.

Virtualenv's bin/activate is Doing It Wrong

I'm a Python programmer and frequently work with the excellent [virtualenv][] tool by Ian Bicking.

Virtualenv is a great tool on the whole but there is one glaring problem: the activate script that virtualenv provides as a convenience to enable its functionality requires you to source it with your shell to invoke it. The activate script sets some environment variables in your current environment and defines for you a deactivate shell function which will (attempt to) help you to undo those changes later.

This pattern is abhorrently wrong and un-unix-y. activate should instead do what ssh-agent does, and launch a sub-shell or sub-command with a modified environment.

Problems

#!/bin/bash
# makeagif.com dl
# USAGE: ./makegif-dl.sh <URL>
URL=$1
curl -s $URL |grep -o '<img src=['"'"'"][^"'"'"']*['"'"'"]' | sed -e 's/<img src=["'"'"']//' -e 's/["'"'"']$//' |grep .cdn | xargs curl --retry 3 -O -J
#!/bin/bash
# USAGE: ./gifboom-dl.sh <URL>
URL=$1
curl -s $URL |grep -o 'data-video-url=['"'"'"][^"'"'"']*['"'"'"]' | sed -e 's/data-video-url=["'"'"']//' -e 's/["'"'"']$//' |cut -d '"' -f 2 | xargs wget
@jadedgnome
jadedgnome / feh bashrc bash function
Last active August 29, 2015 14:03
feh bash function/alias , It will search current dir and subfolders for .jpg,.jpeg & .png files and write them to a file in /tmp/ (e.g /tmp/filelist-4Gf) the last 3 characters are random. feh will then load the filelist and sort the files by modified time, display filename, auto-zoom and 800x600 resolution.
fehl() {
randomfile=filelist-$(< /dev/urandom tr -dc A-Za-z0-9 |head -c 3).txt
find . -type f \( -iname "*.jpg*" -or -iname "*.jpeg*" -or -iname "*.png*" \) -printf "%p\n" | grep -v /thumbs/ >> /tmp/$randomfile ; feh -d -S mtime -Z -g 800x600 -f /tmp/$randomfile &
}
@jadedgnome
jadedgnome / list sshfs mounts bash function
Created July 13, 2014 13:28
list sshfs mounts from 'ps aux' output , formatted with awk.
lsshfs() {
#list sshfs mounts
ps aux | grep sshfs | grep @ | grep -v "\-p" |awk '{print $2" = "$12" = "$13}'
ps aux | grep sshfs | grep @ | grep "\-p" | awk '{print $2" = "$12" "$13" "$14" = "$15}'
}
#!/bin/bash
#list sshfs mounts
ps aux | grep sshfs | grep @ | grep -v "\-p" |awk '{print $2" = "$12" = "$13}'
ps aux | grep sshfs | grep @ | grep "\-p" | awk '{print $2" = "$12" "$13" "$14" = "$15}'
#!/bin/bash
#This is free and unencumbered software released into the public domain.
#Because this script needs root to do some things, excessive amounts of
#checking have been done to terminate the script if anything fails.
#Read all instructions very carefully. When it asks to type "yes", it must be
#all uppercase or it will fail.
#!/bin/bash
# Bash script to install latest version of ffmpeg and its dependencies on Ubuntu 12.04 or 14.04
# Inspired from https://gist.github.com/faleev/3435377
# Remove any existing packages:
sudo apt-get -y remove ffmpeg x264 libav-tools libvpx-dev libx264-dev
# Get the dependencies (Ubuntu Server or headless users):
sudo apt-get update
@jadedgnome
jadedgnome / retry bash function
Created July 27, 2014 12:44
retry bash function, copied from http://redd.it/25tgqg
retry(){
# FROM http://redd.it/25tgqg
local delay=1 n
if ! [[ $1 = *[^0-9]* ]]; then
if (($1 > 0)); then
delay=$1
fi
shift
fi