Skip to content

Instantly share code, notes, and snippets.

View dlukes's full-sized avatar

David Lukes dlukes

View GitHub Profile
@dlukes
dlukes / server.js
Created January 20, 2017 09:29
Pattern for using Promise-based background jobs in Node + Express.
/* A quick reminder on how to use Promises with Node and Express in order to run potentially
* time-consuming jobs asynchronously (assuming the jobs are able to run in the background thanks to
* libuv and actually return Promises).
*
* Start the server, navigate to /startjob, then refresh a few times, the job should be in progress.
* You can navigate elsewhere in the "app" in other browser tabs in the meanwhile (/). After about
* 20s, you should get a result by refreshing the tab where you originally submitted the job.
*
* I hope this pattern will be useful e.g. for processing images with the `sharp` library (see
* <http://sharp.dimens.io>).
@dlukes
dlukes / utf-8-sig.ipynb
Created December 26, 2022 00:21
Comparing the performance of utf-8 vs. utf-8-sig encodings in Python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dlukes
dlukes / app.py
Last active December 2, 2022 15:48
Dispersion plot with Shiny for Python
from collections import Counter
import matplotlib as mpl
import matplotlib.pyplot as plt
import pandas as pd
import regex as re
from shiny import App, reactive, render, ui
mpl.rcParams.update(
{
@dlukes
dlukes / multi_borrow.rs
Created May 6, 2021 06:38
E0499 and function signatures extending mutable borrow lifetimes
// Some instances of E0499 ("cannot borrow X as mutable more than once
// at a time") are straightforward to understand, but some can be
// tricky. Among the latter ones (at least for me) are those related to
// the way a function potentially extends the lifetime of a borrow by
// tying it to another value.
//
// For instance, this function: https://github.com/benhoyt/countwords/blob/5318b1acdd5bd313039d480af535cf79565c2e62/rust/optimized-unsafe/main.rs#L72
//
// Try changing it so that it accepts a &'a mut Vec<u8> instead of a
// &'a Cell<Vec<u8>>. You'll get the following error:
// ==UserScript==
// @version 0.8.1
// @name Zotero ShareLaTeX Cite-as-you-Write
// @namespace https://github.com/dlukes
// @author dlukes
// @description Insert citations from Zotero into ShareLaTeX as you write.
// @match *://sharelatex.korpus.cz/*
// @run-at document-end
// @grant unsafeWindow
// @grant GM.xmlHttpRequest
@dlukes
dlukes / remove_docx_dates.py
Last active May 7, 2019 15:30
Remove dates from comments and tracked edits in docx. Also, a cheatsheet for namespaces in lxml.
#!/usr/bin/env python3
"""Usage: {} AUTHOR_SUBSTRING INPUT.DOCX OUTPUT.DOCX
Remove date metadata from Word document for authors matching
AUTHOR_SUBSTRING. Handy if you don't want other people to know when
exactly you found time to work on their document ;)
In more detail: Read INPUT.DOCX, extract the comments and tracked edits,
manipulate them (cf. functions `modify_comments()` and
`modify_tracked_edits()` -- by default, they remove date metadata
diff -ru a/src/main/java/mpi/eudico/client/annotator/player/VLCJMediaPlayer.java b/src/main/java/mpi/eudico/client/annotator/player/VLCJMediaPlayer.java
--- a/src/main/java/mpi/eudico/client/annotator/player/VLCJMediaPlayer.java 2016-01-14 16:44:42.000000000 +0100
+++ b/src/main/java/mpi/eudico/client/annotator/player/VLCJMediaPlayer.java 2019-04-08 16:39:56.894874290 +0200
@@ -597,6 +597,7 @@
public void setOffset(long offset) {
logger.log(Level.FINE, "set offset {0}", offset);
this.timeOffset = offset;
+ mediaDescriptor.timeOrigin = offset;
}
@dlukes
dlukes / emacs_daemon.scpt
Last active December 10, 2018 04:23
AppleScript wrapper app around Emacs for running it conveniently as a daemon on OS X
(* SETUP
1. Create an Application in Automator.
2. Add a Run AppleScript action.
3. Paste the content of this gist instead of the provided script skeleton.
4. Save the app, drag it to your dock and/or set it as the default app for
the filetypes of your choice using the Open With dialog in Finder.
NOTES ON USAGE
@dlukes
dlukes / explicitly_installed.py
Created November 6, 2017 10:38
List packages explicitly installed with pacman or the AUR on Arch Linux
#!/usr/bin/env python3
"""List packages explicitly installed with pacman or pacaur."""
import re
from collections import namedtuple
from subprocess import check_output
Package = namedtuple("Package", "date name")
@dlukes
dlukes / kontext-v0.9.x-queryBox.js
Last active April 3, 2017 09:05
kontext-v0.9.x-queryBox.js
// ==UserScript==
// @name KonText Interface Layout Switcher
// @namespace https://trnka.korpus.cz/~lukes
// @version 3.2.0 (for KonText v0.9.x)
// @description Adds a quick query box to KonText above the concordance
// @author David Lukeš
// @match https://kontext.korpus.cz/*
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js