Skip to content

Instantly share code, notes, and snippets.

View jrk's full-sized avatar

Jonathan Ragan-Kelley jrk

View GitHub Profile
@jrk
jrk / 55-bytes-of-css.md
Created September 26, 2022 06:27 — forked from JoeyBurzynski/55-bytes-of-css.md
58 bytes of css to look great nearly everywhere

58 bytes of CSS to look great nearly everywhere

When making this website, i wanted a simple, reasonable way to make it look good on most displays. Not counting any minimization techniques, the following 58 bytes worked well for me:

main {
  max-width: 38rem;
  padding: 2rem;
  margin: auto;
}
@jrk
jrk / dbshare2.py
Created April 16, 2020 16:32
Simple script to upload files to Dropbox and generate a URL for embedding elsewhere
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# via: https://github.com/macedotavares/Glass-Dome
import sys, os, requests, json, time
file_path = sys.argv[1]
db_token = sys.argv[2]
db_folder = sys.argv[3]
@jrk
jrk / Makefile
Created February 9, 2018 20:10
Trivial PyBind11 test module
PYBIND11_INCLUDE ?= # -Ipath/to/pybind/include if not in other paths
PREFIX ?= $(shell python3-config --prefix)
INCLUDES = ${PYBIND11_INCLUDE} -I${PREFIX}/include/python3.6m -I${PREFIX}/include
CFLAGS = -std=c++11 ${INCLUDES}
LDFLAGS = -arch x86_64 -L${PREFIX}/lib -lpython3.6m -ldl
foobar.so: foobar.cpp
@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 */
@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 / README.md
Last active April 30, 2024 16:10
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

// 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 / 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 {
@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
// 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;