Skip to content

Instantly share code, notes, and snippets.

@viking
viking / left-justify-signature.sh
Last active Sep 3, 2020
Process signature file with line under it in order to left-justify the actual signature
View left-justify-signature.sh
convert signature_2020-08-26_1857.png \
-region 395x2+33+91 \
-fuzz 10% \
-transparent 'gray(100)' \
-transparent 'graya(99,0.294118)' \
+region +fuzz \
-fill green \
-draw 'point 230,0' \
-draw 'point 230,114' \
-trim \
View redcap.lark
start: expr
expr: grouped_expr | ungrouped_expr
grouped_expr: "(" ungrouped_expr ")"
ungrouped_expr: comparison | and_expr | or_expr
and_expr: expr "and"i expr
View gist:4d9988c1c14ad27a6a8c7b44d34b343b
ffmpeg -thread_queue_size 512 -f v4l2 -i /dev/video0 -i ~/ownCloud/Projects/webcam/ds9-computer.png -filter_complex 'nullsrc=size=960x544 [base]; [0:v] scale=w=665:h=377,eq=brightness=-0.1 [cam]; [base][cam] overlay=138:44 [tmp1]; [tmp1][1:v] overlay' -f v4l2 -vcodec rawvideo -pix_fmt rgb24 -r 10 /dev/video2
@viking
viking / app.py
Created Mar 6, 2020
Python WSGI injector example
View app.py
import re
import json
from injector import inject, Injector
from waitress import serve
class IndexAction:
def run(self, params):
return({"message": "Hello!"})
class HomeController:
@viking
viking / remote-failure-handling-example.R
Created Mar 4, 2020
Shiny example for handling important/unimportant remote transactions
View remote-failure-handling-example.R
library(shiny)
timeout <- function(amount) amount
POST <- function(timeout, succeed) {
if (succeed) {
Sys.sleep(1)
return("the POST succeeded")
} else {
Sys.sleep(timeout)
@viking
viking / down-detector-example.R
Created Feb 20, 2020
Shiny example for detecting downtime of REDCap (or some other remote service)
View down-detector-example.R
library(shiny)
lastREDCapFailure <- reactiveVal(NULL)
retryREDCapInterval <- 10
numPosts <- 0
doPost <- function() {
lastFailure <- isolate(lastREDCapFailure())
diff <- if (is.null(lastFailure)) NULL else
difftime(Sys.time(), lastFailure, units = "secs")
@viking
viking / bug.R
Created Nov 6, 2019
Issue in the with_mock() function in the testthat package
View bug.R
foo <- function(x) paste0("foo", x)
bar <- function(x) foo(x)
baz <- function(expr, envir = parent.frame()) {
#envir
expr <- substitute(expr)
with_mock(foo = function(x) paste0("junk", x), {
eval(expr, envir = envir)
})
}
@viking
viking / keepalive-example.R
Last active Aug 14, 2019
Shiny workaround for terminating sessions that won't time out properly
View keepalive-example.R
library(shiny)
script <- HTML("
var keepAliveInterval;
$(document).on('shiny:sessioninitialized', function(event) {
keepAliveInterval = setInterval(function() {
var d = new Date();
console.log('pinging shiny at', d);
Shiny.onInputChange('alive', d);
}, 1000);
@viking
viking / diet_bf_age_stop.txt
Last active Jul 26, 2019
Monster REDCap branching logic
View diet_bf_age_stop.txt
(
[event-name] = "1_month_arm_1" and
[2_weeks_arm_1][diet_breastmilk] = 1 and
[diet_breastmilk] <> 1
) or
(
[event-name] = "2_months_arm_1" and (
[2_weeks_arm_1][diet_breastmilk] = 1 or
[1_month_arm_1][diet_breastmilk] = 1
) and
@viking
viking / busy-example.R
Last active Jul 10, 2019
Example shiny application that displays a "busy" page to other users when there's a long-running flush cycle
View busy-example.R
library(shiny)
library(httpuv)
busy <- FALSE
ui <- fluidPage(h1("Foo"),
textOutput("date"),
actionButton("sleep", "Sleep"))
server <- function(input, output, session) {
You can’t perform that action at this time.