Skip to content

Instantly share code, notes, and snippets.

View mpjdem's full-sized avatar

Maarten Demeyer mpjdem

View GitHub Profile
@mpjdem
mpjdem / pyws.ipynb
Last active December 25, 2015 15:09
Interactive course file for the LEP Python Workshop 2013
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mpjdem
mpjdem / scientific_python.ipynb
Last active August 29, 2015 13:56
Scientific Python
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mpjdem
mpjdem / rstudio_screenshot.R
Last active July 29, 2019 23:44
Take a screenshot of your RStudio window in Linux
rstudio_screenshot <- function(partial_name = "") {
look_behind <- "(?<=\\s)"
xwid_pattern <- "0x[a-f0-9]+"
look_ahead <-
paste0("(?=\\s\".*",
partial_name,
".*\":\\s\\(\"rstudio\"\\s\"RStudio\"\\)\\s+[0-9]{4}x[0-9]{3,4})")
xwid <-
@mpjdem
mpjdem / take_screenshot.R
Created August 5, 2019 18:51
Root window screenshot
take_screenshot <- function() {
xwid <-
system("xwininfo -root | sed -n 2p | grep -oP 0x[a-f0-9]+",
intern = TRUE)
magick::image_write(magick::image_read(paste0("x:", xwid)),
path = format(Sys.time(), "ss-%Y%m%d-%H%M%S.png"),
format = "png")
@mpjdem
mpjdem / datatable_basics.py
Created August 7, 2019 10:47
Basic operations in Python datatable
import numpy as np
import datatable as dt
from datatable import f, by, mean
# Reading a CSV
url = "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv"
tbl = dt.fread(url)
# Filtering rows
tbl = tbl[f.species != "setosa", :]
@mpjdem
mpjdem / dp_command.R
Created August 30, 2019 08:09
'Command' design pattern in R
compose_quote <- function(body_part, creature_name) {
cat(paste0("Go for the ", body_part, ", ", creature_name, "!\n"))
}
execute <- function(fn, ...) {
Sys.sleep(1)
fn(...)
# Or: do.call(fn, list(...))
# Or: rlang::exec(fn, ...)
}
@mpjdem
mpjdem / dp_command.clj
Last active September 3, 2019 16:55
'Command' design pattern in Clojure
(defn compose-quote [body-part creature-name]
(println (str "Go for the " body-part ", " creature-name "!")))
(defn execute [command & args]
(Thread/sleep 1000)
(apply command args))
(execute compose-quote "eyes" "Boo")
@mpjdem
mpjdem / dp_strategy.clj
Created September 3, 2019 16:39
'Strategy' design pattern in Clojure
(def users [{:name "John Doe" :subscription 0}
{:name "Jane Doe" :subscription 1}
{:name "John Dur" :subscription 1}
{:name "Sara Der" :subscription 1}])
(defn alphabetic-sort [u1 u2]
(cond
(= (:subscription u1)
(:subscription u2)) (neg? (compare (:name u1)
(:name u2)))
@mpjdem
mpjdem / dp_strategy.R
Last active September 3, 2019 16:41
'Strategy' design pattern in R
qsort <- function(inp, cfun) {
if (length(inp) > 1) {
cres <- cfun(inp, inp[[length(inp)]])
c(qsort(inp[cres < 0], cfun), inp[cres == 0], qsort(inp[cres > 0], cfun))
} else {
inp
}
}
users <- list(list(name = "John Doe", subscription = 0),