Skip to content

Instantly share code, notes, and snippets.

View pengx17's full-sized avatar
🛫

Peng Xiao pengx17

🛫
View GitHub Profile
@pengx17
pengx17 / graph.js
Created April 9, 2024 15:14
Draw affine workspace graph
function preparePageNodes() {
// id -> links
const pages = Array.from(currentWorkspace.docCollection.meta.docs).filter(p => p.title);
const edges = pages.flatMap((page) =>
getPageLinks(page.id).map((target) => [page.id, target])
);
return {
nodes: pages.map((page) => ({ id: page.id, label: page.title })),
edges: edges.map(([source, target]) => ({ source, target })),
};
@pengx17
pengx17 / patch.sh
Last active March 28, 2024 16:38
patch AppRun
# Adopted from https://gist.github.com/neilcsmith-net/69bcb23bcc6698815438dc4e3df6caa3
# INPUT_APPIMAGE must be absolute path
INPUT_APPIMAGE=$1
# System architecture to create AppImage for - see options at https://github.com/AppImage/AppImageKit/releases/continuous/
SYSTEM_ARCH="x86_64"
APPIMAGETOOL_URL="https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-$SYSTEM_ARCH.AppImage"
TMP_DIR=$(mktemp -d)
@pengx17
pengx17 / main.ts
Created January 27, 2024 15:16
transform to cssVar
import * as babel from "@babel/core";
import * as fs from "fs";
import plugin from "./plugin";
const code = fs.readFileSync('./input.ts', 'utf8');
const out = babel.transformSync(code, {
plugins: [plugin],
filename: './input.ts',
presets: [require.resolve("@babel/preset-typescript")],
@pengx17
pengx17 / export.js
Last active December 26, 2023 10:12
export current workspace snapshot in affine
(async () => {
// make sure ZipTransformer is imported and attached to window
const { ZipTransformer } = window;
await Promise.all([...currentWorkspace.blockSuiteWorkspace.pages.values()].map(p => p.load()));
// wait for a few more seconds
await new Promise(resolve => setTimeout(resolve, 5000));
const zipblob = await ZipTransformer.exportPages(currentWorkspace.blockSuiteWorkspace, [...currentWorkspace.blockSuiteWorkspace.pages.values()]);
const url = URL.createObjectURL(zipblob);
const a = document.createElement('a');
a.setAttribute('href', url);
@pengx17
pengx17 / export.js
Last active September 4, 2023 13:31
Export app.affine.pro and import into AFFiNE client
(async () => {
async function blobToBase64(blob) {
return await new Promise((resolve) => {
const reader = new FileReader();
reader.onload = function() {
resolve(reader.result.split(',')[1]);
}
reader.readAsDataURL(blob);
});
}
@pengx17
pengx17 / footprints.js
Last active April 11, 2023 01:49
get blocksuite size footsprints
(async () => {
const { getBlocksuiteReader } = await import(
"https://unpkg.com/blocksuite-reader@0.0.6/dist/index.js"
);
const workspace = window.currentBlockSuiteWorkspace;
const workspaceId = workspace.room;
const reader = getBlocksuiteReader({
workspaceId: workspaceId,
Y: workspace.constructor.Y,
});
@charset "utf-8";/*! tailwindcss v2.2.4 | MIT License | https://tailwindcss.com *//*! modern-normalize v1.1.0 | MIT License | https://github.com/sindresorhus/modern-normalize */*,::after,::before{box-sizing:border-box}html{-moz-tab-size:4;tab-size:4}html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}body{font-family:system-ui,-apple-system,'Segoe UI',Roboto,Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji'}hr{height:0;color:inherit}abbr[title]{text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Consolas,'Liberation Mono',Menlo,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:
@pengx17
pengx17 / custom.js
Created March 29, 2022 03:26
auto pairing double quotes
let currentRepo = logseq.api.get_current_graph().path;
function isActive() {
return logseq.api.get_current_graph().path === currentRepo;
}
function isEditing() {
return logseq.api.check_editing();
}
@pengx17
pengx17 / get-global-vars.js
Created February 28, 2022 08:42
Get all non standard variables defined in the global context
// make sure it doesn't count my own properties
(function () {
var results, currentWindow,
// create an iframe and append to body to load a clean window object
iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
// get the current list of properties on window
currentWindow = Object.getOwnPropertyNames(window);
// filter the list against the properties that exist in the clean window
const assert = require("assert");
let xrange = [241, 273];
let yrange = [-97, -63];
function check([x, y], [vx, vy], maxHeight = 0, inShoot = false) {
[x, y] = [x + vx, y + vy];
// console.log([x, y], [vx, vy], maxHeight, inShoot);
vx = vx > 0 ? vx - 1 : vx < 0 ? vx + 1 : 0;