Skip to content

Instantly share code, notes, and snippets.

Sergey Yavnyi blacktaxi

Block or report user

Report or block blacktaxi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@blacktaxi
blacktaxi / polylens.ts
Last active Mar 28, 2018
polymorphic lens in TypeScript 2.8
View polylens.ts
/**
* 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 Sep 1, 2017
Time travel debugging with Focal! (use Redux dev tools browser extension)
View redux-devtools.ts
import { Atom } from '@grammarly/focal'
import { createStore } from 'redux'
declare global {
interface Window {
__REDUX_DEVTOOLS_EXTENSION__?: () => undefined
}
}
/**
@blacktaxi
blacktaxi / roll.py
Last active Jul 10, 2017
DnD die roll script
View roll.py
#!/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 Jul 9, 2017
Cleaning up duplicates in Dropbox's Camera Uploads
View dbdupes.py
#!/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 Apr 17, 2017
webkitSpeechRecognition API usage example
View webkit-speech-recognition.js
// 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 Mar 23, 2017
git alias for tagging commits with Jira ticket IDs
View .gitconfig
[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 Mar 11, 2016
Fixing IDE support for PureScript 0.8.2
View psc-ide-0.8.2.md

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 Feb 26, 2016
Uncaught TypeError with Maybe recursion in Elm
View UncaughtTypeError.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 Jan 16, 2016
elm-package install that works in Docker
View elm-package-install.py
#!/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)
@blacktaxi
blacktaxi / 1930.hs
Created Oct 28, 2015
Ivan's car™
View 1930.hs
#!/usr/bin/env stack
-- stack --resolver lts-3.11 --install-ghc runghc --package array --package containers
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap.Strict as IM
import qualified Data.Map.Strict as M
import qualified Data.Sequence as Seq
import Data.Sequence ((<|), (><))
You can’t perform that action at this time.