Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mathematicalcoffee's full-sized avatar

Amy Chan mathematicalcoffee

  • Australia
View GitHub Profile
@mathematicalcoffee
mathematicalcoffee / chapter.hs
Last active February 23, 2021 07:10
Pandoc extension to insert the metadata of a file as headings of levels 1, 2 and 3. This is so that if you have (say) each chapter of a thesis in its own file with its own title block, you can still compile the lot together to the one final thesis. See the file for more details.
#!/usr/bin/env runhaskell
-- Filter that adds the metadata block as h1, h2, h3 (title, author, date).
--
-- Usage::
-- chmod +x ./chapter.hs
--
-- # (where each chapter is in its own md file and I want to compile them
-- # into one document preserving the title/author/date for each chapter):
--
-- for f in Chapter*.md; do \
@mathematicalcoffee
mathematicalcoffee / list_windows.py
Last active February 20, 2019 12:11
see https://askubuntu.com/questions/648010/is-there-a-text-based-window-switcher-for-unity/648044 . A zenity window for alt-tab. I modified to (a) permit a host name of "N/A" in the `wmctrl -lpG` output (for some reason all the windows get the correct host name except for Rstudio which gets "N/A"), (b) shell-quote the window titles and (c) use f…
#!/usr/bin/env python3.6
# credit https://askubuntu.com/questions/648010/is-there-a-text-based-window-switcher-for-unity/648044
# need 3.6 for fstrings
# @TODO esc to quit zenity window
import subprocess
import socket
import sys
import re
from shlex import quote
#!/usr/bin/env python3.6
# credit https://askubuntu.com/questions/648010/is-there-a-text-based-window-switcher-for-unity/648044
# need 3.6 for fstrings
# @TODO esc to quit zenity window
import subprocess
import socket
import sys
import re
from shlex import quote
@mathematicalcoffee
mathematicalcoffee / README.md
Last active September 17, 2017 01:39
Prism language definition for R
@mathematicalcoffee
mathematicalcoffee / test-that-extras.r
Created March 19, 2013 06:30
Extra functions to extend Hadley WIckham's testthat package. (See http://journal.r-project.org/archive/2011-1/RJournal_2011-1_Wickham.pdf for an introduction to testthat). I may eventually submit these as pull requests to the testthat repo or just package them up for easiness.
# This file has a set of extra tests, expectations and structures extending
# the excellent testthat package[1].
#
# I suggest you read Hadley's introductory article[2] to become acquainted
# with testthat.
#
# THIS IS NOT A POLISHED PRODUCT.
#
# Helpful functions provided
# - describe : almost the same as a context, for grouping tests
@mathematicalcoffee
mathematicalcoffee / pre-commit
Last active June 1, 2016 12:12
precommit hook for R package. Adds a 'GitCommit' to the DESCRIPTION field.
#!/bin/sh
#
# This updates the GitCommit field of the DESCRIPTION file with the git commit
# sha (and branch). You should commit before building to make sure yours line up.
# Then going to that sha will give you that version of the package.
#
# It goes in ~/phd/.git/modules/rphd/hooks (or if not a submodule, in .git/hooks)
#echo $(pwd) ~/phd/rphd
BRANCH=$(git rev-parse --abbrev-ref --verify HEAD )
@mathematicalcoffee
mathematicalcoffee / autocaption_knitr.r
Created April 23, 2013 07:12
Automatically set knitr's figure caption option to the title of the ggplot in the chunk. The gist has the R code you should put in your document, as well as an example Rmd with the compiled output.
# Include the following in a chunk up the top of your document
# Then in your plot chunk, use 'fig.cap=cap()'.
# Set the title of your ggplot via `labs(title="mytitle")`, and
# it will automatically be substituted into the chunk options
# as 'fig.cap'
library(knitr)
opts_knit$set(eval.after='fig.cap')
cap <- function () {
p <- last_plot()
if (!is.null(p) && !is.null(p$labels$title)) {
@mathematicalcoffee
mathematicalcoffee / knit2
Last active December 16, 2015 07:49
Knit a Rmd straight to a PDF (HTML too but then you could just use `knit2html`).
library(knitr)
#' Knits a Rmd to a pdf or HTML
#'
#' In the case of output='html', you may as well just use `knit2html`
#' (although this doesn't clutter your workspace with the intermediate
#' outputs like the .md file).
#'
#' In the case of output='pdf', we knit the Rmd to md (markdown) and then
#' use `pandoc` to convert to PDF.
@mathematicalcoffee
mathematicalcoffee / gist:4385143
Created December 27, 2012 03:10
doing chat from gnome 3.6 gnome shell extension.
On 19/12/12 07:46, Stefano Ciancio wrote:
> is possible to launch an empathy chat window from an extension in gnome 3.6?
Yes, request a Telepathy text channel (and make Empathy be the preferred
Handler, if you want).
examples/client/python/ensure-channel.py in the telepathy-glib source
tree is something similar, but in Python. The important bits are that it:
* gets an Account object from the AccountManager (in a Shell extension
@mathematicalcoffee
mathematicalcoffee / popupDoubleSliderMenuItem.js
Created December 12, 2012 00:01
Some javascript classes for gnome-shell extensions that create handy Popup Menu Items. PopupDoubleSliderMenuItem: a PopupSliderMenuItem with two sliders, for a lower and upper limit. PopupSliderMenuItemWithLabel: a PopupSliderMenuItem with a convenience label showing the current value. You can specify the lower/upper limits of the slider.
/* A SliderMenuItem with two slidable things, for
* selecting a range. Basically a modified PopupSliderMenuItem.
* It has no scroll or key-press event as it's hard to tell which
* blob the user meant to scroll.
*/
function PopupDoubleSliderMenuItem() {
this._init.apply(this, arguments);
}
PopupDoubleSliderMenuItem.prototype = {
__proto__: PopupMenu.PopupBaseMenuItem.prototype,