Skip to content

Instantly share code, notes, and snippets.

View dlukes's full-sized avatar

David Lukes dlukes

View GitHub Profile
@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 / kontext-interface-layout-switcher.js
Last active August 29, 2015 14:15
A Greasemonkey/Tampermonkey userscript to tweak the layout of the KonText corpus concordancer (https://kontext.korpus.cz).
// ==UserScript==
// @name KonText Interface Layout Switcher
// @namespace https://trnka.korpus.cz/~lukes
// @version 0.1.2
// @description turns the KonText topbar into a sidebar, adds a query box
// @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
// ==UserScript==
// @name KonText vertical menu v2
// @namespace https://trnka.korpus.cz/~lukes
// @version 0.1
// @description enter something useful
// @author David Lukeš
// @match https://kontext.korpus.cz/*
// @grant none
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @require https://code.jquery.com/jquery-1.11.2.min.js
@dlukes
dlukes / kontext-interface-layout-switcher-enhanced.js
Last active August 29, 2015 14:21
An improved version of my Greasemonkey/Tampermonkey userscript to tweak the layout of the KonText corpus concordancer (https://kontext.korpus.cz).
// ==UserScript==
// @name KonText Interface Layout Switcher
// @namespace https://trnka.korpus.cz/~lukes
// @version 1.0.0
// @description turns the KonText topbar into a sidebar, adds a query box
// @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
@dlukes
dlukes / stretchy_div.html
Last active February 3, 2016 19:44
A stretchy div between other divs on one line.
<!-- How to have a div stretch between divs on the left and right. Useful e.g. for -->
<!-- Bootstrap navbar et al. -->
<style>
.inner-navbar {
border: 2px solid black;
padding: 5px;
width: 100%;
}
.left {
@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
@dlukes
dlukes / mysql_collation.py
Last active September 1, 2016 12:42
Case-insensitive, diacritic-sensitive collation with MySQL demo
# Case-insensitive, diacritic-sensitive collation with MySQL demo
#
# Dependencies -- install ``python3``, then:
#
# $ pip3 install --user pymysql sqlalchemy
#
# Replace <user>, <passwd> and <db> in the create_engine() URL with suitable
# values corresponding to your local MySQL setup.
#
# Usage:
@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 / this_regular_vs_arrow_functions.js
Last active January 25, 2017 12:09
A review of `this` in regular vs. arrow functions in JavaScript.
/* With regular functions, `this` is bound purely depending on how the function is called. If it's
* bound to an object (either explicitly or via the `instance.funcName()` sugar), `this` refers to
* that object. Otherwise, it's `undefined` (or `window`, depending on your exact environment and
* whether `"use strict";` is in effect).
*
* In particular, it doesn't matter whether the function is attached to the object itself as a
* property, i.e. each instance has its own version of the function created during initialization,
* (see `Class2`), or whether it exists on the object's `prototype` as a method and all instances
* share it (see `Class1`). `this` is always resolved dynamically, i.e. depending on the call site.
* Neither of these is well suited for yanking out of the context of the original object and using
#!/usr/bin/env python3
import time
import subprocess as sp
import concurrent.futures as cf
start = time.time()
with cf.ThreadPoolExecutor() as e:
futures = [e.submit(sp.check_output, f"sleep 2s && echo Done {i}.", shell=True) for i in range(3)]