Skip to content

Instantly share code, notes, and snippets.

View hyrious's full-sized avatar
💤
lazy

hyrious hyrious

💤
lazy
View GitHub Profile
@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,
}
@hyrious
hyrious / duf.sh
Created June 22, 2024 00:48
Get free disk space, requires Node.js >= 18.15
node -p 'var s=fs.statfsSync(".");s.bsize*s.bavail' | pretty-bytes
@hyrious
hyrious / lezer-fmt.ts
Last active July 14, 2024 14:01
Write you a code formatter
import {parser} from '@lezer/javascript'
export function format(input: string) {
let tree = parser.parse(input)
let spaceAfter = (s: string) => s + ' '
let spaceBefore = (s: string) => ' ' + s
let spaceAround = (s: string) => ' ' + s + ' '
let spec = {
@hyrious
hyrious / cn-date.user.js
Created June 14, 2024 01:48
Translate English date string to Chinese representation.
// ==UserScript==
// @name Translate Date
// @name:zh-CN 翻译日期到中文格式
// @namespace translate-date.hyrious.me
// @match *://*/*
// @exclude *://*.bilibili.com/video/*
// @grant none
// @version 1.0
// @author hyrious
// @description May 25 -> 3月25日
// Reference: https://github.com/SukkaW/react-compiler-webpack
import fs from 'node:fs'
import babel from '@babel/core'
import BabelPluginReactCompiler from 'babel-plugin-react-compiler'
/** @returns {import('esbuild').Plugin} */
export function reactCompiler(options = {}) {
const filter = options.filter || /\.[jt]sx$/
const reactCompilerConfig = options.reactCompilerConfig || {}
@hyrious
hyrious / subl-replace-comma.py
Created March 26, 2024 02:52
Replace chinese comma "," with ", " seaminglessly.
import sublime, sublime_plugin
have_a_rest = False
class FixCjkCommaListener(sublime_plugin.TextChangeListener):
def on_text_changed(self, changes):
global have_a_rest
if len(changes) != 1 or have_a_rest: return
c = changes[0]
if c.str != ',': return