This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #-- convert pdf into single page png images with p01 numbering | |
| for file in *.pdf; do | |
| echo 'converting $file' | |
| convert -density 400 -colorspace sRGB $file -scene 1 -alpha off ${file%.pdf}_p%02d.png; | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # rename repository | |
| # change name on remote repo, copy ssh url from the clone button on main page | |
| mv <old folder> <new folder> | |
| git remote set-url origin git@github.com:genomicsengland/<new repo name> | |
| # compare local copy of file to remote | |
| git fetch origin | |
| git diff origin/master -- <path to file> | |
| # list all branches |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # open up current file (useful for opening markdowns in chrome) | |
| :!open % | |
| # search across folder tree for test | |
| # From within buffer at top most level of folder tree to search | |
| :grep '<searchstring>' **/*.<fileending to search> or grep -R <searchstring> . to recursievely search all files in project | |
| :copen to open the quickfix list, and :ccl to close it | |
| :cn to go to the next on the quickfix list | |
| :cp to go to the previous | |
| # OR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- pg dump of a specific schema from metrics db on index | |
| pg_dump metrics -h 10.1.24.39 -p 5433 -U cdt_user -n <schema_name> > <out>.sql | |
| -- select a random percentage of rows of table | |
| select * from my_table tablesample bernoulli(<percentage in numbers, e.g. 10>) | |
| -- or to select random rows in query | |
| select * from query order by random() limit 100 | |
| -- useful aggregate functions to use with GROUP BY | |
| string_agg(<field>, ';') /* equivalent to R's paste(<field>, collapse = ";") */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # run three times a day (between 9am and 4pm), Mon - Fri | |
| H H(9-16)/3 * * 1-5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # batch renames files with hyphens to underscores | |
| for i in `ls *-*` | |
| do | |
| NEW=`echo $i|tr '-' '_'` | |
| git mv $i $NEW | |
| done | |
| # or do sed on the filename with multiple options | |
| for i in `ls *.sql` | |
| do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # make white transparent | |
| convert <in>.png -transparent white <out>.png | |
| # change image to a4-sized pdf | |
| convert -density 300 -page a4 <in>.png <out>.pdf | |
| # remove large white backgrounds from multiple images | |
| mogrify -trim +repage *.png | |
| # make image grayscale |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # set up the SMTP server | |
| # for qmul: | |
| # host = smtp-mail.outlook.com | |
| # port = 587 | |
| # username, password = full hh..@qmul.ac.uk email address | |
| import smtplib | |
| from os.path import basename | |
| from email.mime.application import MIMEApplication | |
| from email.mime.multipart import MIMEMultipart | |
| from email.mime.text import MIMEText |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Template objects allows you to add ${FIELD_NAME} tags into the file | |
| # and then values can be substituted with | |
| # template_object.substitute(FIELD_NAME = <field_value>) | |
| def read_template(filename): | |
| """ | |
| Returns a Template object comprising the contents of the | |
| file specified by filename. | |
| """ | |
| import Template | |
| with open(filename, 'r', encoding='utf-8') as template_file: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #-- use the CDT Bot API token see https://cnfl.extge.co.uk/display/CDT/Generic+Login+Credentials+Information#GenericLoginCredentialsInformation-SlackCDTBotUser | |
| #-- function to send df (d) to a specific channel with optional message, will break up if there are too many rows | |
| send_df_to_slack_as_msg <- function(d, channel, api_token, msg = NA){ | |
| require(knitr) | |
| require(slackr) | |
| slackr_setup(channel = channel, | |
| api_token = api_token) | |
| d <- kable(d, format = 'rst') | |
| if(!is.na(msg)){ | |
| slackr_msg(msg) |