Skip to content

Instantly share code, notes, and snippets.

View NateScarlet's full-sized avatar
🍔
LiangMianBaoJiaZhiShi

NateScarlet NateScarlet

🍔
LiangMianBaoJiaZhiShi
View GitHub Profile
export default function doWaterfallLayout({
container,
columnWidth,
selector = ':scope > *',
}: {
container: HTMLElement;
selector?: string;
columnWidth: number;
}): void {
const columnCount = Math.max(
@NateScarlet
NateScarlet / migrate-to-sfc-script-setup.ts
Created January 28, 2022 10:04
Vue SFC setup script migration
#!/usr/bin/env ts-node-script
import { program } from 'commander';
import * as _fs from 'fs';
import { promisify } from 'util';
import * as ts from 'typescript';
import { ESLint } from 'eslint';
const readFile = promisify(_fs.readFile);
const writeFile = promisify(_fs.writeFile);
@NateScarlet
NateScarlet / message_box.py
Last active May 25, 2021 05:53
pywin32 cancelable message box
import msvcrt
import threading
import time
from typing import Callable, Set, Text
import win32con
import win32gui
def message_box(
import { wrapCallSite } from 'source-map-support';
export default function captureStackTrace(skip = 0): NodeJS.CallSite[] {
const rawPrepareStackTrace = Error.prepareStackTrace;
try {
Error.prepareStackTrace = (_, stack) => stack;
const v: { stack: NodeJS.CallSite[] } = { stack: [] };
Error.captureStackTrace(v);
return v.stack.slice(1 + skip).map(i => wrapCallSite(i));
} finally {
/** Split string to exact n parts, last part may contains splitter. */
export default function splitN(v: string, splitter: string, n: number): string[] {
const parts = v.split(splitter);
const ret = parts.slice(0, n);
while (ret.length < n) {
ret.push('');
}
ret[n - 1] = parts.slice(n - 1).join(splitter);
return ret;
}
@NateScarlet
NateScarlet / cloneDate.ts
Last active November 19, 2020 03:50
clone Date object with a optional offset and data override
/** clone Date object with a optional offset and data override */
export default function cloneDate(
date: Date,
offset?: {
year?: number;
month?: number;
day?: number;
hour?: number;
minute?: number;
seconds?: number;
export function getCommonPrefix(v: string[]): string {
if (v.length === 0) {
return '';
}
if (v.length === 1) {
return v[0];
}
// return range is [0, w)
let w = v[0].length;
@NateScarlet
NateScarlet / html-webpack-stats,js
Last active April 4, 2020 15:30
Use html-webpack-plugin to generate stats.json
new HtmlPlugin({
/** @param {{compilation: import('webpack').compilation.Compilation}} */
templateContent: ({ compilation }) => {
const {
hash,
publicPath,
assetsByChunkName,
assets,
} = compilation.getStats().toJson({ all: true }, true);
return JSON.stringify(
@NateScarlet
NateScarlet / useVirtualScroll.ts
Last active June 8, 2023 10:12
vue composable for implement virtual scroll on x or/and y axis
import type { StyleValue } from 'vue';
import { computed, reactive, ref } from 'vue';
export default function useVirtualScroll({
x,
y,
}: {
x?: {
totalCount: () => number;
itemWidth: () => number;
@NateScarlet
NateScarlet / ModalMixin.ts
Last active January 9, 2020 09:28
element-ui modal show
import { Component, Prop, Vue } from 'vue-property-decorator';
/**
* Mixin for support `dialog.show`
*/
@Component
export class ModalMixin extends Vue {
@Prop({ default: false, type: Boolean })
public visible!: boolean;