Skip to content

Instantly share code, notes, and snippets.

View zaaack's full-sized avatar
Nothing is an absolute reality; all is permitted

Zack Young zaaack

Nothing is an absolute reality; all is permitted
View GitHub Profile
@zaaack
zaaack / BatchFetcher.tsx
Created May 17, 2022 08:39
common batch fetcher
import axios, { AxiosRequestConfig } from 'axios'
export interface Props<P, Data, D> {
url: string
baseParams?: object
aggregateParams: (p1: P, p2: P) => P
selectData: (d: Data, p: P) => D
waitMs?: number
config?: AxiosRequestConfig
}
@zaaack
zaaack / zh_answer.js
Last active December 8, 2021 20:19
知乎想法/答案备份, copy 到 console 执行即可
//知乎答案爬取
var $ = document.querySelector.bind(document)
var $$ = document.querySelectorAll.bind(document)
var zh={
Download:function (content, filename) {
// 创建隐藏的可下载链接
var eleLink = document.createElement('a');
eleLink.download = filename;
eleLink.style.display = 'none';
// 字符内容转变成blob地址
@zaaack
zaaack / SVGAutoWrappedText.jsx
Created August 16, 2018 10:29
SVG auto-wrapped text component for React
import 'core-js/fn/set'
import 'core-js/fn/map'
import React from 'react'
import svgTextSize from 'svg-text-size';
const rightSymbols = new Set(
'“‘[「【﹝〔<‹«{『((<《'.split('')
)
@zaaack
zaaack / test.fs
Created October 15, 2017 03:58
readlink ffi in fsharp
open System
open System.Collections.Generic
open System.Runtime.InteropServices
[<DllImport("libc", SetLastError=true)>]
extern int readlink(string path, byte[] buffer, int buflen);
let readlink2 path =
let buf: byte [] = Array.zeroCreate(512)
import { Struct } from 'immuter'
const struct = Struct({
title: {
zh: '哈利·波特与魔法石',
en: 'Harry Potter and the Philosopher\'s Stone',
},
author: 'J. k. rowling',
tags: ['novel', 'magic'],
})
function doHash(str, seed) {
var m = 0x5bd1e995;
var r = 24;
var h = seed ^ str.length;
var length = str.length;
var currentIndex = 0;
while (length >= 4) {
var k = UInt32(str, currentIndex);
@zaaack
zaaack / file
Created April 27, 2017 02:20
freedom_public
{"0.3984699617225185":"-----BEGIN PGP PUBLIC KEY BLOCK-----\r\nCharset: UTF-8\r\n\r\nxv8AAABSBAAAAAATCCqGSM49AwEHAgME4JCeuCGhYIjKLhTDOXe1o8KbD0OgTBUy\r\nN2tFDZHROjL+ZRIPeqCym03m+iiTysgp71Qszl764+nlI5u4sSyqZ83/AAAACDxn\r\naXRodWI+wv8AAACOBBATCABA/wAAAAWCWQFVXv8AAAACiwn/AAAACZCUFR1PQAQi\r\ntv8AAAAFlQgJCgv/AAAABJYDAQL/AAAAApsD/wAAAAKeAQAAXXYBANoYKPXoiTbd\r\nY56ithXekpS18vVi0zR6J/VtiT5+of+GAP9VgVUTKk/19vBityNvHxh198iqShSu\r\nlC66kj3niDwPgs7/AAAAVgQAAAAAEggqhkjOPQMBBwIDBJkY2u9+S26cM0/cvRP+\r\nEpMzoxOdK3N8jeqhC2y1dRzLl2ZiB5OtrG3m1mB8GhmxeQwM2/qk+/YTohPAh6oH\r\nF04DAQgHwv8AAABtBBgTCAAf/wAAAAWCWQFVXv8AAAAJkJQVHU9ABCK2/wAAAAKb\r\nDAAA7ygA+gLSZjpYh6iTUdf8hI59KBYxyIaKoDlK1l3xiYzyO/8CAQCpoC5jrAs2\r\nu8tKlJEmChqWKPeKGJp+J6MUFn6TCnHO0g==\r\n=tu8N\r\n-----END PGP PUBLIC KEY BLOCK-----\r\n"}
@zaaack
zaaack / react-shave.js
Last active October 6, 2022 14:08
react-shave.js (ellipsis)
// @flow
import shave from 'shave'
import { h, Component } from 'preact'
import shallowCompare from 'shallow-compare'
type Props = {
line?: number,
text: string,
ellipsis?: string,
onEllipsisClick?: ?MouseEventListener,
@zaaack
zaaack / update_git_author_and_mail.sh
Created March 10, 2017 06:29
update_git_author_and_mail.sh
#!/bin/sh
git filter-branch --env-filter '
an="$GIT_AUTHOR_NAME"
am="$GIT_AUTHOR_EMAIL"
cn="$GIT_COMMITTER_NAME"
cm="$GIT_COMMITTER_EMAIL"
old_mail="[Your Old Mail]"
@zaaack
zaaack / SimpleRouter.js
Created November 23, 2016 08:16
SimpleReactRouter using hash
/**
* SimpleRouter
*
*```js
* const routes = [{
* path: '/',
* component: Main,
* }, {
* path: '/user/:id',
* component: User,