Skip to content

Instantly share code, notes, and snippets.

View hyrious's full-sized avatar
💤
lazy

hyrious hyrious

💤
lazy
View GitHub Profile
@hyrious
hyrious / package.jsonc
Created May 13, 2025 12:28
One config to save you 8MB of eslint dependencies.
"overrides": {
"eslint": {
// Only loaded for `--mcp`.
"@modelcontextprotocol/sdk": "npm:noop-package",
"zod": "npm:noop-package"
}
}
@hyrious
hyrious / mixin.ts
Created May 7, 2025 14:10
Ruby's `include` in JavaScript/TypeScript
function mixin(cls: Function, mod: Function) {
const proto = {
__proto__: Object.getPrototypeOf(cls.prototype)
}
Object.getOwnPropertyNames(mod.prototype).forEach(field => {
if (field == 'constructor') return;
proto[field] = mod.prototype[field]
})
Object.setPrototypeOf(cls.prototype, proto)
return cls
@hyrious
hyrious / finalurl.zsh
Last active April 25, 2025 15:17
Redirect URL from command line
alias finalurl="curl -o /dev/null -sILw '%{url_effective}'"
# Example usage:
# finalurl b23.tv/ovUaDM9 | sed -e 's/?.*//'
@hyrious
hyrious / react-context-portal.tsx
Created April 16, 2025 09:27
Skip possible nested context when passing React children.
import { createContext, use, useState } from 'react';
import { createPortal } from 'react-dom';
import { createRoot } from 'react-dom/client';
const Context = createContext<string>('')
function Test() {
const theme = use(Context)
return <div>"{theme}"</div>
@hyrious
hyrious / val-n.ts
Created April 14, 2025 05:49
Value Enhancer TSX
import { compute, isVal, setValue, subscribe, type ComputeGet, type ReadonlyVal } from 'value-enhancer';
type Value<T> = T | ReadonlyVal<T>;
type ValueOrList<T> = Value<T> | ValueOrList<T>[];
type ValueOrList2<T> = ValueOrList<T> | ValueOrList<ValueOrList<T>>;
type Element = HTMLElement | SVGElement;
type Attributes<T> = Partial<{
[K in keyof T]: T[K] extends Function ? never : T[K] extends object ? Attributes<T[K]> : Value<number | T[K] | undefined | null>;
}>;
type Children = ValueOrList2<Element | string | ObserverNode | undefined>;
@hyrious
hyrious / MoonBit.sublime-syntax
Created January 28, 2025 06:28
Basic MoonBit syntax highlighting support in Sublime Text
%YAML 1.2
---
# - https://www.sublimetext.com/docs/syntax.html
# - https://docs.moonbitlang.com/en/latest/language/introduction.html
# - https://github.com/moonbitlang/moonbit-docs/blob/main/next/_ext/lexer.py
file_extensions:
- mbt
first_line_match: |-
@hyrious
hyrious / goto-region.py
Created December 31, 2024 15:50
Sublime Text fast navigate "//#region"
import sublime, sublime_plugin
import re
class GotoRegion(sublime_plugin.TextCommand):
def is_enabled(self):
name = self.view.file_name()
return name.endswith('.js') or name.endswith('.ts')
def run(self, edit):
regions = self.view.find_all('//#region (.+)')
if w := self.view.window():
@hyrious
hyrious / github-cursor-column.user.js
Created October 16, 2024 10:21
Show caret column on GitHub code page.
// ==UserScript==
// @name GitHub Code Cursor Position
// @namespace caret.github.hyrious.me
// @match https://github.com/*
// @grant none
// @version 1.0
// @author -
// @description Show current column on caret.
// @require https://cdn.jsdelivr.net/npm/[email protected]/selector-set.js
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/index.umd.js
@hyrious
hyrious / matplotlib_custom.py
Created August 28, 2024 03:59
Custom matplotlib and plotly.py's fig.show()
"""matplotlib.use('module://matplotlib_custom'), remember to add this file to PYTHONPATH"""
from matplotlib.backend_bases import Gcf
from matplotlib.backends.backend_agg import FigureCanvasAgg
FigureCanvas = FigureCanvasAgg
def show(*args, **kwargs):
var = globals().get('custom')
if var:
// https://github.com/evanw/esbuild/blob/main/internal/helpers/dataurl.go
const CharCode = {
Tab: 9,
LineFeed: 10,
CarriageReturn: 13,
Space: 32,
Hash: 35,
PercentSign: 37,
}