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
@blacktaxi
blacktaxi / ruby-fmt.clj
Created January 25, 2012 14:42
Ruby-like string interpolation in Clojure
; Ruby has an awesome feature -- string interpolation. Read about it on the internet.
; On the other hand, Clojure only has cumbersome Java string formatting, which can not be
; used without pain after you've tried Ruby.
; So here's this simple macro that basically allows you to do most things you could do
; with Ruby string interpolation in Clojure.
(ns eis.stuff
(:require [clojure.string]))
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 / oop.lua
Created July 6, 2012 12:58
Another basic OOP in lua with inheritance and virtual methods.
-- creates a class table which has a "new" method to create object instances.
class = function (parentclass, classdef)
local cls = {
__classdef__ = classdef or {},
__parent__ = parentclass or {},
-- instance constructor
new = function(cls, ...)
local instance = {
super = cls.__parent__.__classdef__,
@blacktaxi
blacktaxi / random-ua.py
Created June 18, 2012 07:22
Statistically plausible random User-Agent string generation.
user_agents = [
(30.7, '''Mozilla/4.0 (compatible; MSIE 5.0; Windows NT;)
Mozilla/4.0 (Windows; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; GTB5; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506; InfoPath.2; OfficeLiveConnector.1.3; OfficeLivePatch.0.0)
Mozilla/4.0 (Mozilla/4.0; MSIE 7.0; Windows NT 5.1; FDM; SV1; .NET CLR 3.0.04506.30)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0; .NET CLR 2.0.50727)
Mozilla/4.0 (compatible; MSIE 5.0b1; Mac_PowerPC)
Mozilla/2.0 (compatible; MSIE 4.0; Windows 98)
Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)
Mozilla/4.0 (compatible; MSIE 5.23; Mac_PowerPC)
@blacktaxi
blacktaxi / custom-clojure-map.clj
Created January 27, 2012 07:04 — forked from david-mcneil/custom-clojure-map.clj
Creating a custom Clojure map type
(ns people
(:use [clojure.string :only (join)]
[clojure.pprint :only (pprint simple-dispatch)]))
;; we can make maps using the special literal form:
{:a 100
:b 200}
(class {:a 100 :b 200})
@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 / fsm.clj
Created January 27, 2012 07:07 — forked from Pet3ris/fsm.clj
Finite State Machine in Clojure core.logic
(ns fsm
(:refer-clojure :exclude [==])
(:use [clojure.core.logic]))
;; Encoding a Finite State Machine and recognizing strings in its language in Clojure core.logic
;; We will encode the following FSM:
;;
;; (ok) --+---b---> (fail)
;; ^ |