Skip to content

Instantly share code, notes, and snippets.

View jrk's full-sized avatar

Jonathan Ragan-Kelley jrk

View GitHub Profile
@jrk
jrk / whats_wrong_with_tex.md
Last active November 21, 2022 03:04
What's wrong with TeX

(Prompted by a thread on HackerNews, which quickly transitioned into debating the merits of LaTeX as a markup language and typesetting system: https://news.ycombinator.com/item?id=7278907.)

[TikZ] is a perfect example of TeX's missed potential: it is an outstandingly well designed DSL for diagram creation, embedded in an insane macro language. The moment you try to do anything nontrivial that exploits the programmatic (rather than purely declarative) nature of TikZ you immediately run into wall after wall trying to express basic programming concepts in the host language, TeX.

For example, two common patterns I have seen frequently arise as perfect uses for a programmatic diagram description:

  • using computed coordinates and transforms to construct complex paths and diagram layouts from the composition of basic geometric reasoning;

  • using abstraction to tersely encapsulate common visual components, both for simple iteration over many similar components, or for higher-order encapsulation of

Keybase proof

I hereby claim:

  • I am jrk on github.
  • I am jrk (https://keybase.io/jrk) on keybase.
  • I have a public key whose fingerprint is F289 7F25 58F7 4987 2540 FB05 A7CB CFB8 7DC2 BDB2

To claim this, I am signing this object:

@jrk
jrk / .gitignore
Last active August 29, 2015 14:01
Halide Mac build test
lesson_01
lesson_01.dSYM
// g++ local_histogram*.cpp -g -I ../include -L ../bin -lHalide -o local_histogram
// DYLD_LIBRARY_PATH=../bin ./local_histogram
#include <Halide.h>
#include <stdio.h>
using namespace Halide;
#include "image_io.h"
int main(int argc, char **argv) {
Var x,y,v;
@jrk
jrk / jpeg_io.h
Last active August 29, 2015 14:13
Halide image_io JPEG saver
#include "jo_jpeg.cpp" // http://www.jonolick.com/uploads/7/9/2/1/7921194/jo_jpeg.cpp
template<typename T>
void save_jpeg(Image<T> im, std::string filename, int quality = 90) {
_assert(im.channels() > 0 && im.channels() < 5,
"Can't write JPEG files that have other than 1, 2, 3, or 4 channels\n");
im.copy_to_host();
// convert to 8-bit and interleave
@jrk
jrk / elf.cpp
Last active August 29, 2015 14:13
Saving an ELF object of LLVM JIT-compiled assembly for a function
#include "elf.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void saveELF(const char *filename, void *buf, size_t len) {
FILE *f = fopen(filename, "w");
struct elf64_hdr {
// This algorithm is meant to be equivalent to CV_TM_CCOEFF_NORMED in OpenCV, and normxcorr2 in MATLAB:
// via http://stackoverflow.com/q/31060974/3815
#include <Halide.h>
typedef uint8_t pixel_t;
void normxcorr( Halide::ImageParam input,
Halide::ImageParam kernel,
Halide::Param<pixel_t> kernel_mean,
@jrk
jrk / README.md
Last active April 7, 2025 18:13
Executable script to run Quartz filters on a PDF file from the shell

This is a simple, should-be-drop-in replacement for the old /System/Library/Printers/Libraries/quartzfilter utility which went away circa OS X 10.8.

Usage:

chmod +x quartzfilter.js
./quartzfilter.js infile.pdf filter.qsfilter outfile.pdf

e.g.,

./quartzfilter.js my-big-pdf.pdf "/System/Library/Filters/Reduce File Size.qfilter" my-less-big-pdf.pdf

@jrk
jrk / DSLs.md
Last active April 22, 2016 00:44

DSL course references

Disclaimer: the boundaries of what really qualifies as "domain-specific" as opposed to "somewhat specialized or different" isn't always crisp, so I'm casting a slightly wide net.

Courses

http://cs448h.stanford.edu

Meta

  • Terra - a language for making high-performance DSLs - staged programming/macro-based embedding - Lua + macros + LLVM
  • Scala LMS - type-based embedding - types!!!
@jrk
jrk / saveGmailAsPDF.js
Created October 4, 2016 02:12
Google Apps Script to save all Gmail messages matching a label/search query as PDFs to a chosen folder on Drive. via https://ctrlq.org/code/19117-save-gmail-as-pdf
function saveGmailAsPDF() {
var gmailLabels = "PDF";
var driveFolder = "My Gmail";
var threads = GmailApp.search("in:" + gmailLabels); // optional count limit:, 0, 5);
if (threads.length > 0) {
/* Google Drive folder where the Files would be saved */