Skip to content

Instantly share code, notes, and snippets.

Avatar

Sean Zhu szhu

  • San Francisco Bay Area
  • Twitter @sfzhu
View GitHub Profile
@szhu
szhu / object-object.md
Last active February 10, 2023 20:34
[object Object]
View object-object.md

This code:

1  formResults = { ... };
2  console.log("first name: " + formResults.firstName);
3  console.log("last name: " + formResults.lastName);
4  console.log("email: " + formResults);

has the following output:

@szhu
szhu / figmaScrollToZoom.hs.lua
Created December 20, 2022 18:49
HammerSpoon script for scroll to zoom with no modifiers
View figmaScrollToZoom.hs.lua
-- https://forum.kicad.info/t/zoom-with-scroll-wheel-but-pan-with-trackpad-on-macos/11974
figmaScrollToZoom = hs.eventtap.new({hs.eventtap.event.types.scrollWheel}, function(e)
-- Trackpad scroll events are continuous, mouse scroll events are not.
if 0 == e:getProperty(hs.eventtap.event.properties.scrollWheelEventIsContinuous) then
local front = hs.application.frontmostApplication()
if "Figma" == front:name() then
-- local title = front:focusedWindow():title()
-- if "Eeschema" == title:sub(0, 8) or "Pcbnew" == title:sub(0, 6) then
local flags = e:getFlags()
View set-pdf-thumbnails.sh
#!/bin/bash
# Add thumbnails to images. This works well for document images (like PDFs),
# where the top of the image is the most important.
for file in "$@"; do
# `--cropOffset 0 0` doesn't do anything, so we use a small offset.
sips \
-s format png \
--resampleWidth 512 \
--cropOffset 0 0.001 \
@szhu
szhu / flatten-image-masks-in-svg.js
Last active November 30, 2022 21:43
Makes it so that I can import Keynote/Pages/Numbers drawings into Figma.
View flatten-image-masks-in-svg.js
// 1. Export the file to PDF.
//
// 2. Convert it to SVG:
//
// inkscape $file.pdf -o $file.svg --export-text-to-path
//
// Note: Don't use pdftocairo or pdf2svg; they don't work properly with the next steps.
//
// 3. Open the SVG file in your browser.
//
@szhu
szhu / page-summary-overlay.user.js
Last active February 3, 2023 22:15
Use OpenAI GPT-3 to summarize the text on the page into 3 key points.
View page-summary-overlay.user.js
// ==UserScript==
// @name Summarize Page Text
// @namespace https://github.com/szhu
// @description Use OpenAI GPT-3 to summarize the text on the page into 3 key points.
// @match *://*/*
// ==/UserScript==
// @ts-strict
const API_KEY = "API_KEY";
@szhu
szhu / stickes-hole-window.swift
Created November 3, 2022 16:10
Open 4 Stickies windows and drag them around to create a "hole".
View stickes-hole-window.swift
import AppKit
import ApplicationServices
import CoreFoundation
import Foundation
// Helpers
// https://github.com/keith/ModMove/blob/main/ModMove/AXValue%2BHelper.swift
extension AXValue {
func toValue<T>() -> T? {
View node_modules.sh
#!/bin/sh
# File formatted with shell-format.
#
# This tool creates a disk image to put node_modules in. This makes it so that
# when the disk image is not mounted, it is treated as a single file by
# Spotlight and other tools to do expensive tasks on a per-file basis.
set -e
# Utils
View gmail-sender-utils.user.js
// ==UserScript==
// @name Gmail Sender Utils
// @namespace https://github.com/szhu
// @match https://mail.google.com/mail/u/*
// @version 1.1
// @author Sean Zhu
// ==/UserScript==
//
// This script does two things:
//
View svg-extract-images.js
for (let image of document.querySelectorAll("image")) {
let url = (image.getAttribute("xlink:href"));
fetch(url).then(res => res.blob()).then(blob => open(URL.createObjectURL(blob)));
}
@szhu
szhu / git-autosave
Last active January 14, 2022 17:24
Creates a backup of your uncommitted changes.
View git-autosave
#!/bin/bash
set -e
old_stash_count=$(git stash list | wc -l)
git stash push --keep-index --include-untracked --quiet
if test "$old_stash_count" == "$(git stash list | wc -l)"; then
echo "All changes have been committed."
exit 0
fi