Skip to content

Instantly share code, notes, and snippets.

@swarn
swarn / serialize.py
Created January 8, 2025 03:52
Dataclass serialization
import json
from dataclasses import MISSING, fields, is_dataclass
from inspect import isabstract, isclass
from types import GenericAlias, NoneType
from typing import Any, TypeAliasType, get_origin
import numpy as np
from numpy.typing import NDArray
type JSON = (
@swarn
swarn / sample.lua
Created December 4, 2024 23:35
multicursor.nvim match textobjects
local mc = require "multicursor-nvim.core"
local TERM_CODES = require "multicursor-nvim.term-codes"
--- @param a Cursor
--- @param b Cursor
--- @return boolean past If the beginning of b is after the end of a
local function visual_past(a, b)
local _, a_end = a:getVisual()
local b_start, _ = b:getVisual()
return b_start[1] > a_end[1] or b_start[1] == a_end[1] and b_start[2] > a_end[2]
@swarn
swarn / gist:b94f04bd7ceab8fd64da63a7e37f99f5
Created August 17, 2019 17:03
Karbiner Elements: Caps alone is Esc; Caps with another key is Ctrl; Caps with Shift is Caps
{
"description": "Caps alone is Esc; Caps with another key is Ctrl; Caps with Shift is Caps",
"manipulators": [
{
"from": {
"key_code": "caps_lock",
"modifiers": {
"mandatory": [
"shift"
],
@swarn
swarn / isoD.py
Created October 13, 2018 16:27
Textmate-style isoD snippet for SublimeText
import sublime, sublime_plugin
from datetime import datetime
class TimestampCommand(sublime_plugin.EventListener):
"""Expand `isoD` to YYYY-MM-DD."""
def on_query_completions(self, view, prefix, locations):
if prefix == 'isoD':
val = datetime.now().strftime('%Y-%m-%d')
else:
val = None
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
# p4p1 is WAN interface, #p1p1 is LAN interface
-A POSTROUTING -o p4p1 -j MASQUERADE
# NAT pinhole: HTTP from WAN to LAN