Skip to content

Instantly share code, notes, and snippets.

(Come in under the shadow of this red rock)

Derrick Turk derrickturk

(Come in under the shadow of this red rock)
View GitHub Profile
derrickturk /
Created Aug 26, 2015
Split (for e.g. poster-printing) a PDF into rows and columns, using pdfinfo and ghostscript.
import sys
import os
import subprocess
import tempfile
PDFINFO_BINARY = 'pdfinfo'
GS_BINARY = 'gswin64c'
class ShellCmdError(Exception):
derrickturk /
Created Jan 29, 2014
In the game of web scraping, you win... or you die.
from urllib import request
from sys import argv, stdout, stderr
from time import sleep
from random import randrange
import re
def main(argv):
if len(argv) == 1:
with open(argv[0], 'r') as f:
derrickturk / iife.R
Created Feb 6, 2014
Javascript style "immediately invoked function expressions" plus on.exit for scope guards in R. Cleanup actions get carried out regardless of clean or error exit from block.
View iife.R
(function() {
derrickturk / hsv_scale.R
Last active Aug 29, 2015
Handy function for HSV-scale-izing real-valued data.
View hsv_scale.R
hsv.scale <- function (var, hmin, hmax=hmin, smin=1, smax=smin, vmin=1, vmax=vmin,
na.col=rgb(0.75, 0.75, 0.75))
var.min <- min(var, na.rm=TRUE)
var.max <- max(var, na.rm=TRUE)
h.f <- approxfun(c(var.min, var.max), c(hmin, hmax))
s.f <- approxfun(c(var.min, var.max), c(smin, smax))
v.f <- approxfun(c(var.min, var.max), c(vmin, vmax))
tmp <- var
View columns.html
<!DOCTYPE html>
<meta charset="utf-8">
<style type="text/css">
body {
-moz-columns: 20em;
-webkit-columns: 20em;
columns: 20em;
-moz-column-gap: 2em;
View double.cpp
#include <iostream>
#include <ios>
#include <iomanip>
#include <cstring>
#include <cstdlib>
int main(int argc, char **argv)
if (argc != 2) {
std::cerr << "Usage: " << (argc ? argv[0] : "double") << " <number>\n";
derrickturk / build.bat
Created Feb 25, 2014
Dinking around with building windows DLLs with MinGW again. And figured out where the [[gnu::stdcall]] goes.
View build.bat
g++ -std=c++11 -Wall -Wextra -c dlltest.cpp
g++ -shared -static-libgcc -static-libstdc++ -o dlltest.dll dlltest.o -Wl,--add-stdcall-alias
View fun_with_c++11.cpp
#include <iostream>
constexpr int fac(int n)
return n <= 0 ? 1 : n * fac(n - 1);
struct [[weenie]] C {
void f() && { std::cout << "dying C's last gasp!\n"; }
void f() & { std::cout << "living, breathing C\n"; }
derrickturk / Makefile
Created Mar 6, 2014
Callback functions in VBA: VBA calls DLL calls VBA.
View Makefile
CXXOPTS=-std=c++11 -pedantic -Wall -Wextra -Werror -static-libgcc -static-libstdc++
OPTOPTS=-O3 -fno-exceptions -fno-rtti -ffast-math -mfpmath=387 -msse3 -mtune=core2 -funroll-loops -s
callback.dll: callback.o
$(CXX) $(CXXOPTS) $(LOG) $(OPTOPTS) $(DLLOPTS) -o callback.dll callback.o $(LINKOPTS)
You can’t perform that action at this time.