Skip to content

Instantly share code, notes, and snippets.

View leingang's full-sized avatar

leingang

  • Department of Mathematics, Courant Institute of Mathematical Sciences, New York University @nyumathclinic
  • New York, New York
View GitHub Profile
@idleberg
idleberg / vscode-macos-context-menu.md
Last active May 1, 2024 12:01
“Open in Visual Studio Code” in macOS context-menu

Open in Visual Studio Code

  • Open Automator
  • Create a new document
  • Select Quick Action
  • Set “Service receives selected” to files or folders in any application
  • Add a Run Shell Script action
    • your default shell should already be selected, otherwise use /bin/zsh for macOS 10.15 (”Catalina”) or later
    • older versions of macOS use /bin/bash
  • if you're using something else, you probably know what to do 😉
@hmenke
hmenke / pdf-to-svg.lua
Last active February 18, 2023 13:33
Render an SVG image as PDF using librsvg2 and cairo.
local ffi = require"ffi"
ffi.cdef[[
// Cairo types
typedef struct _cairo_surface cairo_surface_t;
typedef int cairo_status_t;
typedef struct _cairo cairo_t;
// Poppler types
typedef struct _PopplerPage PopplerPage;
@doobeh
doobeh / button_field_example.py
Created February 17, 2016 21:01
WTForms ButtonField Example
from flask import Flask, render_template_string
from flask_wtf import Form
from wtforms import StringField
from wtforms.widgets import html_params, HTMLString
app = Flask(__name__)
app.secret_key = 'SHH!'
class ButtonWidget(object):
@sloria
sloria / bobp-python.md
Last active May 1, 2024 08:37
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@guifromrio
guifromrio / compress-pdf-with-gs.md
Created August 30, 2013 14:39
Compress PDF files with ghostscript

This can reduce files to ~15% of their size (2.3M to 345K, in one case) with no obvious degradation of quality.

ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

Other options for PDFSETTINGS:

  • /screen selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting.
  • /ebook selects medium-resolution output similar to the Acrobat Distiller "eBook" setting.
  • /printer selects output similar to the Acrobat Distiller "Print Optimized" setting.
  • /prepress selects output similar to Acrobat Distiller "Prepress Optimized" setting.
@doitian
doitian / README.md
Last active April 1, 2021 23:37
Scripts to control Vitamin-R

Usage

osascript Start.applescript "objective" "tag1,tag2"
osascript Stop.applescript

I have skipped most Vitamin-R workflows. See the attached settings snapshot. If you have them enabled, you need to update the script to handle different steps.

I use the scripts in my org pomodoro script

@cowboy
cowboy / sudo-keepalive-example.sh
Created July 15, 2012 20:55
Bash: Sudo keep-alive (good for long-running scripts that need sudo internally but shouldn't be run with sudo)
#!/bin/bash
# Might as well ask for password up-front, right?
sudo -v
# Keep-alive: update existing sudo time stamp if set, otherwise do nothing.
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# Example: do stuff over the next 30+ mins that requires sudo here or there.
function wait() {
@kgaughan
kgaughan / gist:2491663
Created April 25, 2012 17:54
Parsing a comma-separated list of numbers and range specifications in Python
from itertools import chain
def parse_range(rng):
parts = rng.split('-')
if 1 > len(parts) > 2:
raise ValueError("Bad range: '%s'" % (rng,))
parts = [int(i) for i in parts]
start = parts[0]
end = start if len(parts) == 1 else parts[1]
if start > end:
@CristinaSolana
CristinaSolana / gist:1885435
Created February 22, 2012 14:56
Keeping a fork up to date

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream