Skip to content

Instantly share code, notes, and snippets.

@taowen
taowen / extractTextFromPdf.md
Last active April 15, 2024 08:14
extract text from pdf

这个是油猴脚本。安装了暴力猴插件之后,点击上面这个文件的 Raw 按钮,会提示安装。

实现原理

  • pdf.js 可以提取所有的 TextItem 包括文本和包围盒
  • 根据包围盒可以大致判断一下是否换行了
  • 如果一行中包含了公式,那么一行会有很多个 TextItem,这些行会称之为 complex 的行
  • 多个连续的 complex 行变成了 complex 块
  • 如果有 claude 3 haiku 的账号会对 complex 块做一次基于图片的 OCR 来清洗嘈杂的带公式的文本
@taowen
taowen / generate_typed_dict.js
Last active March 28, 2024 02:51
根据 json 生成 python 的 typed dict。验证 haiku 对 few shot 的指令遵从性
const YOUR_CLAUDE_KEY = ''
async function main() {
const resp = await fetch('https://api.anthropic.com/v1/messages', {
method: 'POST',
headers: {
"x-api-key": YOUR_CLAUDE_KEY,
"anthropic-version": '2023-06-01',
"content-type": "application/json",
},
body: JSON.stringify({
// ==UserScript==
// @name 拷贝任意选中的 HTML
// @description 方便粘贴到 chatgpt 进行问答
// @namespace github.com/taowen
// @match *://*/*
// @version 1.0.0
// @author taowen
// @license MIT
// @grant GM.registerMenuCommand
// @grant GM_setClipboard
// ==UserScript==
// @name youtube转文本到剪贴板
// @description 方便粘贴到 chatgpt 进行问答
// @namespace github.com/taowen
// @match https://www.youtube.com/*
// @version 1.0.0
// @author taowen
// @license MIT
// @grant GM.registerMenuCommand
// @grant GM_setClipboard
// ==UserScript==
// @name arxiv论文转markdown拷贝到剪贴板
// @description 方便粘贴到 chatgpt 进行问答
// @namespace github.com/taowen
// @match https://ar5iv.labs.arxiv.org/*
// @match https://browse.arxiv.org/html/*
// @match https://arxiv.org/html/*
// @version 1.0.1
// @author taowen
// @license MIT

Layout projection: A method for animating browser layouts at 60fps

Introduction

Animating layout is hard. Prohibitively so; how many ambitious designers have provided dev teams dazzling videos of app-quality UI animations, only to be rebuffed?

If you're a web developer, what would your reaction be if asked to realise this kind of App Store-style interaction, where an item opens into a full-screen view when clicked:

Y2Mate.is.-.Inside.Framer.Motion.s.Layout.Animations.-.Matt.Perry-5-JIu0u42Jc-1080p-1651813013467.online-video-cutter.com.mp4
@sources.Scene
export class AccountDemo extends RootSectionModel {
@constraint.required
public name: string;
@constraint.required
public password: string;
private justFailed: boolean;
CREATE TABLE `Account` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL UNIQUE,
`password` varchar(255) NOT NULL,
`status` varchar(255) NOT NULL,
`retryCount` int(11) NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
const MAX_RETRY_COUNT = 3;
@sources.Mysql()
export class Account extends Process {
public name: string;
// plain text, just a demo
public password: string;
public retryCount: number;
@sources.Mysql()
export class User extends Entity {
public id: number;
public name: string;
public inviterId: number;
public get inviter(): User {
return this.scene.load(User, { id: this.inviterId });
}
public get posts() {
return this.scene.query(Post, { authorId: this.id });