Skip to content

Instantly share code, notes, and snippets.

View antfu's full-sized avatar

Anthony Fu antfu

View GitHub Profile
type GetComponentProps<T> = T extends React.ComponentType<infer P>
? P
: T extends (props: any) => any
? Parameters<T>
: never;
class ClassComponent extends React.Component<{ a: number }> {
render() {
return <div />;
@antfu
antfu / resume.json
Last active November 28, 2023 17:15
{
"basics": {
"name": "Anthony Fu",
"picture": "https://antfu.me/avatar.png",
"label": "Software Engineer",
"headline": "A ship in harbor is safe, but that is not what ships are built for.",
"summary": "My name is Anthony Fu, a master of computer science student and a freelance software engineer. My passion for software lies with dreaming up ideas and making them come true with elegant interfaces. I take great care in the experience, architecture, and code quality of the things I build.\n\nI am also an open-source enthusiast and maintainer. I love how collaboration and knowledge sharing happens through open-source and I am happy to see what I do could eventually feedback to the community and industry.",
"website": "https://antfu.me",
"address": "",
"projects_url": "https://antfu.me/projects",
@antfu
antfu / 📊 Weekly development breakdown
Last active November 20, 2023 10:25
📊 Weekly development breakdown
TypeScript 21 hrs 47 mins ████████████████▒░░░ 67.1%
Vue.js 6 hrs 21 mins ██████▓░░░░░░░░░░░░░ 19.6%
JSON 2 hrs 10 mins ████▒░░░░░░░░░░░░░░░ 6.7%
JavaScript 46 mins ███▒░░░░░░░░░░░░░░░░ 2.4%
@antfu
antfu / doc-table.md
Last active October 14, 2023 20:09
Doc Table in Markdown

Example

Name

Description


@antfu
antfu / html2pdf.js
Created May 5, 2020 18:06
HTML to PDF
import puppeteer from 'puppeteer'
import fs from 'fs'
async function buildPDF(htmlString) {
const browser = await puppeteer.launch({ headless: true })
const page = await browser.newPage();
await page.setContent(htmlString, { waitUntil: 'networkidle0' })
const pdf = await page.pdf({
format: 'A4',
displayHeaderFooter: false,
@antfu
antfu / requestAnimationFrame.js
Created May 21, 2018 08:17
requestAnimationFrame Pollyfile
window.requestAnimationFrame = (function () {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback) {
window.setTimeout(callback, 1000 / 60);
};
})();
@antfu
antfu / run.ts
Created January 12, 2023 19:51
Remove members with no team from GitHub's org
import 'dotenv/config'
import { Octokit } from '@octokit/core'
const org = process.env.SPONSORS_ORG!
const token = process.env.SPONSORS_TOKEN!
const octokit = new Octokit({ auth: token })
const allMembers = await fetchMembers(org)
const membersWithoutTeam = new Set(allMembers.map(m => m.login))
@antfu
antfu / semantic-commit-messages.md
Created April 19, 2019 17:25 — forked from joshbuchea/semantic-commit-messages.md
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@antfu
antfu / download.js
Created November 16, 2016 03:07
[JS] Download file
function download(data, filename, type) {
var a = document.createElement('a')
var file = new Blob([data], { type: type })
if (window.navigator.msSaveOrOpenBlob) // IE10+
window.navigator.msSaveOrOpenBlob(file, filename)
else { // Others
var url = URL.createObjectURL(file)
a.href = url
a.download = filename
document.body.appendChild(a)
// port form https://github.com/bermi/element-xpath
// Create a safe reference to the getElementXpath object for use below.
const getElementXpath = function (el, callback) {
var err, result, nodes, i, n, segments, siblings, id_count;
try {
if (callback && (typeof callback !== "function")) {
throw new Error("Invalid callback supplied");
}