Skip to content

Instantly share code, notes, and snippets.

@iskolbin
iskolbin / luabsp.lua
Created July 19, 2016 09:07
Lua BSP room generation
local unpack, floor, random = table.unpack or unpack, math.floor, math.random
local Bsp = {}
function Bsp.splitTree( x, y, w, h, l, kwargs )
local maxlevel = kwargs.maxlevel or 4
local deviation = kwargs.leafdeviation or 0.1
if w < 4 or h < 4 or l > maxlevel then
return {x,y,w,h}
else
@iskolbin
iskolbin / define.js
Created May 10, 2017 15:30
Tiny AMD define implementation only for fast prototyping purposes. Working only in browsers
(function(){var b=window;b.define=function(c,a,d){a=[,b[c]||{}].concat(a.slice(2).map(function(a){b[a]=b[a]||{};return b[a]}));d.apply(null,a);b[c]=a[1]}})();
@iskolbin
iskolbin / pairingheap.lua
Created February 28, 2018 16:45
Persistent Pairing Heap in Lua
local PairingHeap = {}
function PairingHeap.make()
return {}
end
function PairingHeap.merge( self, other )
if not self or self[2] == nil then
return other
elseif not other or other[2] == nil then
#!/usr/bin/env python
from PIL import Image
import os
import sys
from xml.dom import minidom
def main():
if len( sys.argv ) < 2:
@iskolbin
iskolbin / unpacker.sh
Created March 28, 2018 11:25
Texture packer unpacker (jq and imagmagick (convert) required)
#!/bin/bash
if [ -z $1 ]; then
echo "Atlas cropper 2018 v666 by Ilya Kolbin"
echo "Usage: ./crop_atlas.sh <atlas.json> <output_path>"
echo "Atlas is json like {"frames":{<filename>:<frame>:{x,y,w,h}}}"
fi
IMG=$(cat $1 | jq -j ".meta.image")
#ifndef LIQUID_CELLUAR_H_
#define LIQUID_CELLUAR_H_
#ifndef LC_NO_STDLIB
#include <stdlib.h>
#define LC_MALLOC malloc
#define LC_FREE free
#else
#ifndef LC_MALLOC
#error "No stdlib mode, but LC_MALLOC not defined"
@iskolbin
iskolbin / tmate_for_ssh.md
Last active January 15, 2024 13:30
Ubuntu(systemd) tmate service for ssh

The motivation is: ssh to remote computer without port forwading, dynamic DNS and so on, the only thing needed is that the remote is connected to the Internet.

  1. On remote get tmate, put it in /usr/local/bin (apt version as of 18.04LTS is too old):
curl -L https://github.com/tmate-io/tmate/releases/download/2.4.0/tmate-2.4.0-static-linux-amd64.tar.xz|tar xJv
sudo mv tmate-2.4.0-static-linux-amd/tmate /usr/local/bin
  1. Put public keys in ~/.ssh/authorized_keys
@iskolbin
iskolbin / unpack_texture_packer_json.sh
Last active March 10, 2022 10:05
Unpack TexturePacker JSON into images
#!/bin/bash
if [ -z $1 ]; then
echo "Usage:\n sh crop_atlas.sh <ATLAS>.json"
exit 1
fi
IMG=$(cat $1 | jq -j ".meta.image")
KEYS=$(cat $1 | jq -j --unbuffered '.frames|keys|join(" ")')
EXT="${IMG##*.}"
NAME="${IMG%.*}"
mkdir -p ${NAME}
function shuffle(array) {
for (let i = array.length-1; i > 0; i--) {
var j = Math.floor(Math.random() * (i+1));
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
}
return array;
}
@iskolbin
iskolbin / find.js
Last active September 28, 2021 16:48
find key or value in object
function findKey(obj, key, callback = path => {console.warn(JSON.stringify(path));}, eq = (a,b) => a===b, path = [], visited = new Set()) {
if (!obj || visited.has(obj) || typeof obj !== "object") return;
visited.add(obj);
for (const k in obj) {
path.push(k);
try {
if (eq(k, key)) callback(path.slice());
findKey(obj[k], key, callback, eq, path, visited);
} catch (e) {
}