Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View zthxxx's full-sized avatar
🐾
Nyaa~

zthxxx zthxxx

🐾
Nyaa~
View GitHub Profile
{
/**
* pegjs grammar:
* https://github.com/pegjs/pegjs/blob/7d13580855/docs/grammar/README.md
* https://github.com/pegjs/pegjs/blob/7d13580855/docs/grammar/action-execution-environment.md
*
* playground: https://pegjs.org/online
*
* > pegjs expression.pegjs -o parser.js --format es
*/
@zthxxx
zthxxx / gist:2599867d9da448f76cb401c3e2ba094f
Last active January 25, 2022 06:32
spotlight indexing turn off and only enable for specify dir
sudo mdutil -a -i off
sudo mdutil -V /System/Volumes/Data/Applications -i on
git fetch --all
# 7 天内有多少 commit 改动了 package-lock
git log --format=format:'%h' --no-merges --since="7 days ago" --all -- package-lock.json | wc -l
# 7 天内所有 commit 共产生了多少完全无重复的 package-lock
git log --format=format:'%h' --no-merges --since="7 days ago" --all -- package-lock.json | \
xargs -I{} git ls-tree {} package-lock.json | \
sort | uniq | wc -l
git log --name-status --diff-filter=D <file / dir>
import path from 'path'
import SuperExpressive from 'super-expressive'
// https://gist.github.com/zthxxx/0328559c300874139e483240073b12e6
const genImportRegex = ({ pathExpr, pathFollowedAssert }: {
/**
* path match expressive to captured for replace
*
* pathExpr need to include `.namedCapture('importPath')`
@zthxxx
zthxxx / codemod-import-path.ts
Created October 8, 2021 04:21
replace import / import() / export from path
import {
namedTypes as types,
} from 'ast-types'
import type {
Options as RecastOptions,
} from 'recast'
import type {
Transform,
FileInfo,
API,
import typescript from 'typescript'
/**
* let { tsconfig, projectReferences, compilerOptions } = parseTsconfigFile()
*
* console.debug(tsconfig, projectReferences, compilerOptions)
*/
const parseTsconfigFile = (tsconfigFile = './tsconfig.json') => {
const { config: tsconfigRaw } = typescript.readConfigFile(tsconfigFile, typescript.sys.readFile)
module.exports = ({ types: t }) => ({
name: 'require-context',
visitor: {
CallExpression: path => {
if (
t.isMemberExpression(path.node.callee, { computed: false })
&& t.isIdentifier(path.get('callee').node.object, { name: 'require' })
&& t.isIdentifier(path.get('callee').node.property, { name: 'context' })
) {
path.replaceWith(
import path from 'path'
import { promises as fs } from 'fs'
import { camelCase } from 'lodash-es'
const [ , self, dir, mergeFlag] = process.argv
if (!dir) {
console.log(`
usage:
node ${path.relative(process.cwd(), self)} <target-dir> [--merge]
@zthxxx
zthxxx / show-shortcut.sh
Created September 12, 2021 11:18
show bash shortcut
function sheet:shortcut {
echo '
ctrl+A ctrl+E ─┐
┌─────────┬──────────┐ │
│ alt+B │ alt+F │ ├─► Moving
│ ┌──────┼────┐ │ │
▼ ▼ │ ▼ ▼ ─┘
$ cp assets-|files dist/
◄────── ────► ─┐
ctrl+W alt+D │