Skip to content

Instantly share code, notes, and snippets.

View stefaneng's full-sized avatar

Stefan Eng stefaneng

View GitHub Profile
find . -not -path "*/\.*" -type f -exec sed -i -e 's/SubpopulationModule/SubpopulationManagerModule/g' {}\;
@stefaneng
stefaneng / jq_group_by_count.sh
Created March 21, 2018 17:00
jq - Group by count
echo '[{"key": 1}, {"key": 2}, {"key": 1}]' | jq 'group_by (.key)[] | {key: .[0].key, length: length}'
@stefaneng
stefaneng / sig_variables_glm.R
Last active August 29, 2015 14:23
Get significant variables in glm R
# From http://stackoverflow.com/a/16154053/1351718
# x is a 10 x 3 matrix
x = matrix(rnorm(3*10), ncol=3)
y = rnorm(10)
res = glm(y~x)
# ignore the intercept pval
summary(res)$coeff[-1,4] < 0.05
@stefaneng
stefaneng / pretty_lambda.el
Last active December 28, 2015 11:19
Pretty Lambdas
;; See: http://www.emacswiki.org/emacs/PrettyLambda
(defun pretty-lambdas ()
(font-lock-add-keywords
nil `(("(\\(lambda\\>\\)"
(0 (progn (compose-region (match-beginning 1) (match-end 1)
,(make-char 'greek-iso8859-7 107))
nil))))))
;; Insert lambda
@stefaneng
stefaneng / ensure-installed-package.el
Last active December 28, 2015 01:19
Emacs macro to ensure that a package is installed before configuring
(defmacro ensure-installed-package (package &rest body)
"Ensures PACKAGE is installed and then performs body. Place package configurations in BODY"
(declare (indent 1))
`(progn
(when (not (package-installed-p ,package))
(package-install ,package))
,@body))
;; USAGE:
@stefaneng
stefaneng / get_branch.sh
Last active December 25, 2015 09:59
Get the current git branch in the working directory. Use in PS1 or something.
function get_branch() {
git branch --no-color 2>/dev/null | awk '/\*/ {print $2}'
}