Skip to content

Instantly share code, notes, and snippets.

@dshipp
dshipp / RemoteScheduleJob
Created June 16, 2014 13:20
Remotely executing commands on Windows XP can be achieved through Cygwin and OpenSSH. However, some commands will not work correctly if executed like this, for example running Selenium requires correct access to the Desktop that Cygwin doesn't seem to achieve. This can be worked around by setting up a Windows Schedule Task to execute the command…
# To run the restart-all Windows Scheduled Task from the command line (either cmd or Cygwin):
(windows box)$ schtasks /run /tn restart-all
To run that command remotely from a linux box:
(linux box)$ ssh windows-user@windows-machine "schtasks /run /tn restart-all"
# Ensure that you have setup public key authentication on the windows box, to allow this command to work without password entry
# Jenkins can be scheduled to execute the above command to allow Windows Selenium instances to be restarted between builds (so as not to clash with running builds).
@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
@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 / 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 / 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 / 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 / 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 / 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'
#!/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 / pylint_pragma.py
Last active December 13, 2015 17:58
How to disable a Pylint message
# pylint: disable=R0904