Skip to content

Instantly share code, notes, and snippets.

View blacktaxi's full-sized avatar
🇺🇦
russia is a terrorist state, russians are a terrorist nation

Serhii Yavnyi blacktaxi

🇺🇦
russia is a terrorist state, russians are a terrorist nation
View GitHub Profile
Hello, world!
Pick a random code below, then go to https://marginalia.bandcamp.com/yum for a free download!
aqxn-h5hz
8gcv-jrpg
x7u6-vs7v
hmlt-gda9
jbpt-ul3t
9xf3-jjd7
@blacktaxi
blacktaxi / polylens.ts
Last active March 28, 2018 20:57
polymorphic lens in TypeScript 2.8
/**
* Gives you an object type compatible with given key type TKey.
*
* For example,
*
* type Example = ObjFor<'a'>
*
* is expanded to
*
* type Example = {
@blacktaxi
blacktaxi / redux-devtools.ts
Created September 1, 2017 17:34
Time travel debugging with Focal! (use Redux dev tools browser extension)
import { Atom } from '@grammarly/focal'
import { createStore } from 'redux'
declare global {
interface Window {
__REDUX_DEVTOOLS_EXTENSION__?: () => undefined
}
}
/**
@blacktaxi
blacktaxi / roll.py
Last active July 10, 2017 17:17
DnD die roll script
#!/usr/bin/env python
if __name__ == '__main__':
import sys, random, re
roll_re = r'(?P<rolls>\d+)d(?P<die>\d+)((?P<mod>(\+|-)\d+))?'
parsed = re.match(roll_re, sys.argv[1].strip()) if len(sys.argv) == 2 else None
if parsed is not None:
d = parsed.groupdict()
rolls, die, mod = int(d['rolls']), int(d['die']), (int(d['mod']) if d['mod'] is not None else 0)
@blacktaxi
blacktaxi / dbdupes.py
Created July 9, 2017 17:38
Cleaning up duplicates in Dropbox's Camera Uploads
#!/usr/bin/env python
import sys, os, re
from PIL import Image, ImageChops
def find(root, pattern):
for root, dns, fns in os.walk(root):
for fn in fns:
if re.match(pattern, fn):
yield (root, fn)
@blacktaxi
blacktaxi / webkit-speech-recognition.js
Created April 17, 2017 00:24
webkitSpeechRecognition API usage example
// copy-paste this into a Chrome new tab console and allow mirophone input
// when prompted
var r = new webkitSpeechRecognition()
r.continuous = true
r.interimResults = true
r.onresult = e =>
console.log(
[...e.results].map(
@blacktaxi
blacktaxi / .gitconfig
Created March 23, 2017 23:49
git alias for tagging commits with Jira ticket IDs
[alias]
# commit with Jira ticket ID tag in commit message.
# current branch name has to start with a valid Jira ticket ID, in upper case.
c = "!f() { \
if [[ -z $1 ]]; \
then \
echo "Error: No commit message provided."; \
exit 1; \
else \
local ticketId=$(git rev-parse --abbrev-ref HEAD | grep -Eo "^[A-Z]+-[0-9]+"); \
@blacktaxi
blacktaxi / psc-ide-0.8.2.md
Last active March 11, 2016 18:55
Fixing IDE support for PureScript 0.8.2

PureScript includes the IDE tools (psd-ide-server, psc-ide-client) with the compiler package since 0.8.2. The purescript package on npm for version 0.8.2 doesn't ship with psc-ide-* executables. So if you're using PureScript by globally installing it from npm (npm install -g purescript), you may find that your editor integration will not work. To fix this, you'll need to build and install PureScript from sources. It can be a pain to use Cabal for this, so we will use Stack. But since PureScript has not updated to 0.8.2 yet in the LTS Stackage, we will need to tweak the stack's global config a bit.

  1. Uninstall npm installation of PureScript: npm uninstall purescript
  2. Install Stack
  3. In your ~/.stack/global/stack.yaml, add this line: extra-deps: ["purescript-0.8.2.0"]
  4. Run stack install purescript
  5. Check that it worked by running psc --version, psc-ide-server.
@blacktaxi
blacktaxi / UncaughtTypeError.elm
Last active February 26, 2016 17:55
Uncaught TypeError with Maybe recursion in Elm
-- This gives an 'Uncaught TypeError: three is not a function' at runtime, when
-- ran in the view function of a start-app app (probably irrelevant).
-- A better error message would certainly help.
one = Just <| three ()
two = one |> Maybe.map identity
three () = two |> Maybe.map (always ())
@blacktaxi
blacktaxi / elm-package-install.py
Created January 16, 2016 18:21
elm-package install that works in Docker
#!/usr/bin/env python2.7
import tempfile, os, sys, shutil, json
from subprocess import call
ELM_STUFF = 'elm-stuff'
DEPS_PATH = 'exact-dependencies.json'
def download_to(url, fileName):
call('wget -O "{fileName}" "{url}"'.format(**locals()), shell=True)