Skip to content

Instantly share code, notes, and snippets.

@un-def
un-def / luaversion.lua
Last active October 20, 2024 18:44
A simple function to detect Lua version
local luaversion = function()
if ({false, [1] = true})[1] then -- luacheck: ignore 314
return 'LuaJIT'
elseif 1 / 0 == 1 / '-0' then
return 0 + '0' .. '' == '0' and 'Lua 5.4' or 'Lua 5.3'
end
local f = function() return function() end end
return f() == f() and 'Lua 5.2' or 'Lua 5.1'
end
@un-def
un-def / wikirender.sh
Created July 4, 2020 20:05
Render wikitext to HTML using Wikipedia API
#!/bin/sh
curl https://en.wikipedia.org/w/api.php -F format=json -F action=parse -F contentmodel=wikitext -F text='<-' 2> /dev/null | jq -r '.parse.text["*"]'
@un-def
un-def / lua-cmsgpack-0.4.0-0.rockspec
Created June 15, 2020 21:42
lua-cmsgpack patch for null values in hash tables
package = "lua-cmsgpack"
version = "0.4.0-0"
source = {
url = "git://github.com/antirez/lua-cmsgpack.git",
tag = "0.4.0"
}
description = {
summary = "MessagePack C implementation and bindings for Lua 5.1/5.2/5.3",
homepage = "http://github.com/antirez/lua-cmsgpack",
license = "Two-clause BSD",
@un-def
un-def / _just
Created January 13, 2020 18:52
ohmyzsh just autocompletion
#compdef _just just
#autoload
_just() {
local -a subcmds
subcmds=($(just --summary)) 2> /dev/null || return 1
_describe 'command' subcmds
}
@un-def
un-def / config.lua
Created March 22, 2019 12:35
nginx lua balancer example
return {
servers = {
foo = {'127.0.0.1', 9001},
bar = {'127.0.0.1', 9002},
baz = {'127.0.0.1', 9003},
}
}
@un-def
un-def / tpb.js
Created February 17, 2019 20:40
tpb extract all magnets
console.log(Array.from(document.querySelectorAll('a[title="Download this torrent using magnet"]')).map(e => e.href).join('\n'))
@un-def
un-def / metaclass_decorator.py
Created February 13, 2019 12:43
metaclass decorator Python 2/3
from __future__ import print_function, unicode_literals
def metaclass(meta):
def metaclass_decorator(cls):
dct = cls.__dict__.copy()
slots = dct.get('__slots__')
if slots is not None:
if not isinstance(slots, (list, tuple)):
@un-def
un-def / jira-sub-tasks-keys.user.js
Last active January 29, 2019 09:47
Jira sub-tasks keys userscript
// ==UserScript==
// @name Jira sub-tasks keys
// @version 1
// @grant none
// @include http://*.atlassian.net/browse/*
// @include https://*.atlassian.net/browse/*
// ==/UserScript==
document.querySelectorAll('#issuetable tr.issuerow').forEach(el => el.insertBefore(document.createElement('td').appendChild(document.createTextNode(el.dataset.issuekey)).parentNode, el.firstChild))
@un-def
un-def / pytest_asyncio_automarker.py
Created August 10, 2018 15:19
[pytest-asyncio] mark all coroutinefunction tests with 'asyncio' marker
def pytest_collection_modifyitems(items):
for item in items:
if inspect.iscoroutinefunction(item.function):
item.add_marker('asyncio')
@un-def
un-def / pytest_inline_fixtures.py
Last active August 1, 2018 17:34
pytest inline fixtures
from inspect import isfunction, signature, Parameter
import pytest
def make_fixture(value, scope='function'):
if isfunction(value):
sig = signature(value)
if 'self' in sig.parameters:
fixture = lambda self, **fxs: value(self, **fxs) # noqa: E731