Skip to content

Instantly share code, notes, and snippets.

@johnghill
johnghill / grammars.coffee
Created December 2, 2015 12:09
[Linux] [atom] [atom-script] Add Stata to list of recognised grammars in rgbkrk / atom-script
Stata:
"Selection Based":
command: "stata"
args: (context) -> [context.getCode()]
"File Based":
command: "stata"
args: (context) -> [context.filepath]
@johnghill
johnghill / stata.cson
Created December 2, 2015 13:59
[atom] [atom-language-stata] [stata] Alternative syntax highlighting for Stata, using rhoconlinux/language-do and jrgcmu/BBStata (Stata 14)
'comment': 'Hybrid of rhoconlinux/language-do and jrgcmu/BBStata'
'fileTypes': [
'do'
'ado'
'mata'
]
'firstLineMatch': '^#!/.*\\bdo\\b'
'foldingStartMarker': '^\\s*(\\w+\\s+)?(def|class|enum)\\s+([.a-zA-Z0-9_ <]+)\\s*(\\((.*)\\))?\\s*:|\\{\\s*$|\\(\\s*$|\\[\\s*$'
'foldingStopMarker': '^\\s*$|^\\s*\\}|^\\s*\\]|^\\s*\\)|^\\s*"""\\s*$'
'name': 'Stata'
@johnghill
johnghill / gist:dd2bee43969612b228f5
Created December 2, 2015 15:23
[stata] [delimit] [delimiter] Regex to convert semi-colon delimited Stata *.do file into <cr> delimited. Verify changes by diff-ing each stage.
# Inspired by http://unix.stackexchange.com/questions/26284/how-can-i-use-sed-to-replace-a-multi-line-string
# Find character sequence [semi-colon newline] not inside a multi-line loop; replace with newline
perl -0777 -i.original -pe 's/\;+(?![^\{]*\})/\n/igs' *.do
# Find newlines within multi-line cond(,,) statement; append to single line
perl -0777 -i.original -pe 's/,\n[\t ]{1,}/,/igs' *.do
# Find multi-line labels denoted by character sequence [newline space nn "label"]; append to single line
# (this regex works in editors but is temperamental on command line; back reference syntax \2 $2 varies by regex flavour)
perl -0777 -i.original -pe 's/(\n[\s]?)([1-9][0-9]?\s\".*\")/ \2/igs' *.do
@johnghill
johnghill / stb
Last active January 26, 2019 20:49
[stata] [make] Wrapper to execute Stata batch files on Linux (stata -b), greps for do file errors and passes appropriate exit code to e.g. make
#!/bin/sh
# Author: Brendan Halpin
# Forked from: http://teaching.sociology.ul.ie/bhalpin/wordpress/?p=122
# Nov 7 2001 21:05:17
# A wrapper for running Stata in batch mode.
# Main purpose is to catch errors and pass them to the calling
# process, typically "make". To do this it catches a couple of
@johnghill
johnghill / key-switch.sh
Last active November 4, 2019 15:02
[BibTeX] [JabRef] [keys] Replace citation keys in existing TeX document after globally altering key generation pattern in JabRef
#!/bin/sh
### STEPS
# JabRef: Back-up original bibtex keys to new var called Orig_bibtexkey
# JabRef: Amend key pattern (as you do...)
# JabRef: Create custom export.layout file below
# echo '\format[GetOpenOfficeType]{\bibtextype},"\bibtexkey","\Orig_bibtexkey",' > jabref-export-keysonly.layout
# JabRef: Exprt to .csv, then to .txt file
# One line per pair of citations, each pair separated by [space]
# Execute this bash script on target .tex file: sh ./key-switch.sh
@johnghill
johnghill / .gitignore
Created December 8, 2015 08:32
[stata] [LaTeX] [thesis] gitignore for a thesis project
## Loosely based on: https://gist.github.com/kogakure/149016
## Alternative everything-but-kitchen-sink version: https://github.com/github/gitignore/blob/master/TeX.gitignore
latex/*.aux
latex/*.glo
latex/*.idx
latex/*.log
latex/*.toc
latex/*.ist
latex/*.acn
latex/*.acr
@johnghill
johnghill / gist:1da3f3747bc8d1c82284
Created December 8, 2015 08:39
[git] [config] git config --list
user.name=John Hill
user.email=*
diff.external=git-meld
diff.tool=meld
merge.tool=git-meld
color.ui=auto
core.editor=subl -n -w
@johnghill
johnghill / compare-local-remote.sh
Created December 10, 2016 18:40
[git] Assert local HEAD and remote ORIGIN on same commit
#!/bin/bash
#
# Asserts that local HEAD and remote ORIGIN are at same commit i.e. avoids a mess
# Based on CodeGnome @ http://stackoverflow.com/a/11181747
#
remote=$(
git ls-remote -h origin master |
awk '{print $1}'
)
local=$(git rev-parse HEAD)
@johnghill
johnghill / stata-curl-SMS.do
Created May 7, 2017 18:32
[Stata] [curl] [SMS] Get a text from Stata using ! curl
* Append to any time consuming operation e.g. -mi impute-
* Receive 1 free generic SMS per day, or buy a personal API key at https://textbelt.com
! curl -X POST https://textbelt.com/text --data-urlencode phone='+44xxxxxxxxxx' --data-urlencode message='Yo! Get back here' -d key=textbelt

Keybase proof

I hereby claim:

  • I am johnghill on github.
  • I am johnhill (https://keybase.io/johnhill) on keybase.
  • I have a public key ASAWpW-lStXD1eEgMwJkJdw7PWTg3-56utGJk0dkgJJcxQo

To claim this, I am signing this object: