Skip to content

Instantly share code, notes, and snippets.

@nmpowell
nmpowell / qs.sh
Last active August 29, 2015 13:57
Summarise Sun Grid Engine (SGE) qstat contents for the current user (and save output to a file)
function qs() {
# Also use qs as shortcut to qstat -j
if [ $# -gt 0 ]
then
jobNum=$1
qstat -j ${jobNum}
fi
# Just one call to qstat; "double quotes" around "${qstat_contents}" below maintain the line breaks
@nmpowell
nmpowell / qda.sh
Created March 25, 2014 23:37
Function to delete all Sun Grid Engine (SGE) jobs with a given string in their name
function qda() {
# Delete all jobs containing $1 in their (shortened) name
jobName=$1
# Get list of job numbers
jobList=$(echo "`qstat`" | grep "${jobName}" | awk '{print $1;}')
# Delete individually
for job in ${jobList}
do
qdel ${job}
done
@nmpowell
nmpowell / matlab_np.sh
Last active July 22, 2016 14:39
Bash / shell script for running Matlab jobs with the Sun Grid Engine. Qsub this whole script, rather than qsubbing Matlab directly.
#!/bin/sh
# matlab_np.sh
# Shell script to run a Matlab function from the bash shell
# Ensure Matlab function is on the path first
# NB Matlab breaks the bash shell, hence stty echo
# stty echo works by itself; stty sane is just-in-case; haven't confirmed that it's necessary.
#
# Example usage: $ matlab_np.sh functionName 'string arg' arg2 ${arg3}...
# Use with Qsub: $ ${QSUB_CMD} matlab_np.sh functionName arguments
# NB do not Qsub matlab directly as your arguments won't be passed to the Matlab function
@nmpowell
nmpowell / qsub_script.sh
Last active July 22, 2016 14:48
Some Sun Grid Engine shortcuts to include in .bashrc
# .bashrc
# simple qsub: assings 8GB memory for 1 hour. Call with: $ nq8 script.sh
alias nq8='qsub -l h_rt=01:00:00 -l tmem=8.0G -l h_vmem=8.0G -l vf=4.0 -l s_stack=10240 -R y -j y -S /bin/csh -b y -cwd -V'
# Shell function to echo the current time along with status updates
echoStatusTime() {
STATUS_TEXT=$1
NOW=$(date +%T)
DATE=$(date +%F)
@nmpowell
nmpowell / np.ahk
Created July 24, 2016 15:05
Some Autohotkey shortcuts
; Some Autohotkey shortcuts I use
#NoEnv
SetWorkingDir %A_ScriptDir%
GroupAdd, Explore, ahk_class CabinetWClass
GroupAdd, Explore, ahk_class ExploreWClass
SetTitleMatchMode, 2
; load many useful global variables
LoadVariables()
{
"version": 1,
"disable_existing_loggers": "False",
"formatters": {
"simple": {
"format": "# {asctime} {name:8s} {levelname:6s} {message}",
"datefmt": "%m/%d/%Y %I:%M:%S %p",
"style": "{"
}
},
@nmpowell
nmpowell / check_list_contents.py
Last active May 25, 2017 08:41
Python snippets to check list contents
# Python snippets to check list contents
# Given two lists, A and B ...
# Check all the items from A are present in B:
set(B).issuperset(set(A))
# Given a list of substrings A and another list of (longer) strings B which might contain those substrings ...
# e.g.
A = ['one', 'two', 'three']
@nmpowell
nmpowell / ApplicationOnTime_Mixed_Argument_Demo.bas
Created July 4, 2017 10:32
Excel VBA macro to demonstrate mixed argument types (Integer and String) to Application.OnTime.
' Demonstrating mixed argument types to Application.OnTime (Integer and String).
' See these pages for more:
' - http://www.markrowlinson.co.uk/articles.php?id=10
' - https://www.mrexcel.com/forum/excel-questions/81724-calling-procedure-parameters.html
' - https://stackoverflow.com/questions/31439866/multiple-variable-arguments-to-application-ontime
Sub RunMe()
Dim testName As String
Dim counter As Integer
@nmpowell
nmpowell / Codes and abbreviations for U.S. states, territories, and other regions.csv
Last active December 21, 2018 11:59
Wikipedia's List of U.S. state abbreviations as of 2018-08-21, cleaned up a little, from https://en.wikipedia.org/wiki/List_of_U.S._state_abbreviations#Table. Lines 1-8 are description; line 9 is column headers.
Codes and abbreviations for U.S. states, territories, and other regions
ISO ISO 3166 codes (2-letter, 3-letter, and 3-digit codes from ISO 3166-1; 2+2-letter codes from ISO 3166-2)
ANSI 2-letter and 2-digit codes from the ANSI standard INCITS 38:2009
USPS 2-letter codes used by the United States Postal Service
USCG 2-letter codes used by the United States Coast Guard (red text shows differences between ANSI and USCG)
Abbreviations:
GPO Older variable-length official US Government Printing Office abbreviations
AP Abbreviations from the AP Stylebook (red text shows differences between GPO and AP)
Name status of region ISO ANSI-alphabetic ANSI-numeric USPS USCG GPO AP Other abbreviations
United States of America Federal state US USA 840 US 00 U.S. U.S. U.S.A.
@nmpowell
nmpowell / python-venv-install-jupyter-qtconsole-notebook.bat
Last active February 22, 2019 17:46
Windows batch script to set up Jupyter's QtConsole and Notebook in a Python3 virtual environment. With shortcuts.
REM Windows batch script to set up Jupyter QtConsole and Notebook in a Python3 virtual environment.
REM Place this script .bat file inside the root venv directory (same level as 'Scripts' and 'Lib' subfolders), and run.
REM Also creates convenience launching scripts.
REM Get current directory name and full path
for %%* in (.) do set VenvDirName=%%~nx*
set VenvDirFullPath=%~dp0
REM Activate the venv
call %VenvDirFullPath%Scripts\activate.bat