Skip to content

Instantly share code, notes, and snippets.

@dshipp
dshipp / pylint_environment_vars.src
Created February 14, 2013 10:04
A virtualenv can also be invoked by setting environment variables, rather than the normal activate script
VIRTUAL_ENV=/opt/myenv
PATH=$VIRTUAL_ENV/bin:$PATH
@dshipp
dshipp / pylint_pragma.py
Last active December 13, 2015 17:58
How to disable a Pylint message
# pylint: disable=R0904
#!/bin/bash
# Colours
ESC_SEQ="\x1b["
COL_RESET=$ESC_SEQ"39;49;00m"
COL_RED=$ESC_SEQ"31;01m"
COL_GREEN=$ESC_SEQ"32;01m"
COL_YELLOW=$ESC_SEQ"33;01m"
COL_BLUE=$ESC_SEQ"34;01m"
COL_MAGENTA=$ESC_SEQ"35;01m"
@dshipp
dshipp / DirectoriesContainingFiletype.sh
Last active December 25, 2015 01:59
Output all directories that contain a particular file type anywhere within the directory structure. Useful for checking where there are directories that represent python projects for example.
#!/bin/bash
# In this example checking for directories containing Python files
find -iname '*.py' -printf '%h/\n'
@dshipp
dshipp / MatchAndReplaceLine.sh
Created October 9, 2013 11:02
Use sed to match a regular expression and replace the full line with just the match.
#!/bin/bash
# Use \( and \) to create a match group in the find part, use \1 in the replace part to reference the match group.
echo "./ThingToMatch/other/stuff/" | sed -n 's/\.\/\([a-zA-Z0-9]*\)\/.*/\1/p'
# This will output: ThingToMatch
# Works with multiline input, applying the replacement to each line.
@dshipp
dshipp / simplehttp.sh
Created October 29, 2013 13:18
Simple web server in python. Exposes the current directory on the port number provided.
python -m SimpleHTTPServer 8000
@dshipp
dshipp / download-exec.sh
Created November 12, 2013 15:01
Download a script and execute it without writing it to disk or setting permissions
curl -s server.com/file | sh
@dshipp
dshipp / git-top-level.sh
Last active December 29, 2015 10:49
Substitute to top level directory for the current git repository. Useful when you have aliases and scripts which need to work across all repositories and refer to some file relative to that repository
$(git rev-parse --show-toplevel)
@dshipp
dshipp / restart-all.bat
Last active August 29, 2015 14:01
Kills all command processes (agressive) and restarts the processes for Selenium hub, node and PhantomJS, without killing itself!
title restart-all
call taskkill /F /t /IM cmd.exe /fi "Windowtitle ne restart-all"
call taskkill /F /IM cmd.exe /fi "Windowtitle ne restart-all"
call taskkill /F /IM iexplore.exe
call taskkill /F /IM IEDriverServer.exe
start cmd.exe /k hub.bat
start cmd.exe /k node.bat
start cmd.exe /k phantomjs.bat
@dshipp
dshipp / find-and-delete.sh
Last active August 29, 2015 14:01
Find and delete all files matching a pattern (e.g. *.pyc files) recursing from the current directory
sudo find . -type f -name "*.pyc" -delete