Skip to content

Instantly share code, notes, and snippets.

View swyxio's full-sized avatar
🎯
Focusing

swyx.io swyxio

🎯
Focusing
View GitHub Profile
@swyxio
swyxio / AutoHotkey.ahk
Last active December 7, 2021 10:37
swyx's autohotkey circa 2014. i used this thing extensively from 2010-2014. In one case it was at least responsible for automating away part of my own job.
Settitlematchmode, 2
F12::
winmove, A,, 1,1,600,600
return
#IfWinActive, Microsoft Word
::sigma::
;Send {Backspace 1}
@swyxio
swyxio / extra.css
Created December 3, 2021 07:53
the custom css/js for https://swyx.transistor.fm/
.site-intro {
font-size: 1.25rem;
width: 60ch;
margin: 0 auto;
}
.site-credits {
position: fixed;
width: 100vw;
bottom: 0;
@swyxio
swyxio / workflow apis tweak.md
Last active October 25, 2021 18:53
workflow apis tweak.md

now that we have a cohesive look at workflow APIs, some issues remain:

  • createActivityHandle isnt really a handle, in the way that createWorkflowHandle and createChildWorkflowHandle are. it returns a function that you call.
    • users are confused by the proxy destructure which a very fancy way of doing type safety and ensuring consistent naming
  • defineSignal/Query dont add much value since they just create an object
    • extra setListener api that is doing the real work, basically 2 different functions branching by def.type

just taking another crack at api design.

simplified query and signal api

@swyxio
swyxio / sample.go
Created July 6, 2021 20:09
old Temporal code samples
func mainWorkflow(ctx workflow.Context, userId) error {
// ...
selector.AddReceive(signalChannel, func(c workflow.ReceiveChannel, more bool) {
c.Receive(ctx, &signalVal) // receive user signals!
})
timerFuture := workflow.NewTimer(childCtx, 30 * time.Day) // sleep for 30 days!
selector.AddFuture(timerFuture, func(f workflow.Future) {
_ = workflow.ExecuteActivity(ctx, SendEmailActivity).Get(ctx, nil) // timeouts and retries!
})
// Scale to Millions + Write Tests + Encrypt Data + Migrate Versions + ...
@swyxio
swyxio / useLocalStorage.js
Last active March 14, 2023 18:27
SSR friendly version of useLocalStorage hook. you can also use this in a library https://github.com/astoilkov/use-local-storage-state
// usage
function Comp() {
const [language, setLanguage] = useLocalStorage('mykey', 'typescript')
}
// definition
function useLocalStorage(key, initialValue) {
const [storedValue, setStoredValue] = React.useState(initialValue);
React.useEffect(() => {
// Get from local storage by key
@swyxio
swyxio / svelte-for-the-curious.md
Last active June 25, 2022 01:54
Svelte for the Intellectually Curious - a talk at UI.dev
@swyxio
swyxio / clubhouse blogpost old.md
Created February 5, 2021 16:00
clubhouse blogpost old

Clubhouse is a great way to access celebrities but a terrible listening experience. They got all the growth factors right, but none of the retention and compounding factors.

Andrew Chen, Ryan Hoover, Michael Grinich and Sahil Lavingia think it could be a $100b company — and they have insider knowledge of metrics. I don't think Clubhouse is a zero - it has genuinely created a new category - it's just not very valuable. I'm taking the other side of that bet (but of course wish them well).

Context:

this is what i use so far, its obviously not a 100% replica of the typography plugin but looks good enough on my site

  /* replace typography plugin */
  .prose {
    @apply text-gray-700 dark:text-gray-300
  }
  .prose {
    & p {
@swyxio
swyxio / svelte.md
Last active November 20, 2020 14:45
Svelte micro-RFC: configurable event modifiers

This is a micro RFC because i'm just jotting down an idea that I would love to have for Svelte, but I'm not sure if it belongs as an official RFC yet. the official RFC process offers no room for lightweight proposals so i am writing a gist.

see also Twitter discussion


The Problem

Svelte offers very useful event modifiers like preventDefault and once.

@swyxio
swyxio / Newton-1.29.vb
Last active July 10, 2022 08:34
Newton - my VBA utility library for doing matrix multiplication and other useful automations during my finance days https://twitter.com/swyx/status/1327041894853922816
Attribute VB_Name = "Newton"
'Newton Utilities, written by swyx
'Project initiated Jan 1 2012
'V1 released Feb 5 2012
'V1.1 added and renamed functions, updated helpfiles Apr 8 2012
'V1.2 spline interp extraction from surface, n_RandomWalk. released Jun 15 2012
'V1.21 n_Corr, n_TangencyPortfolio, n_CovMat subsumed into n_Cov, fixed n_GetTimeSeries, n_AutoCorr, n_Lag, n_Pval, added PValues to n_Regress, n_Payback, n_ChartMakeScatter
'V1.22 n_Granger, pval for n_Corr, n_Divide, n_Curve, n_PriceIRS, upgraded n_BuildCurve
'V1.23 n_PriceFwd/Rate, n_AutoRegress/n_Remove_AutoRegress (needs work), augmented n_PriceOption for pricing FXO, digitals, and returning greeks
'V1.24 n_FXOVolCurve, n_FormatAsPercent linked to ctrl+shift+5, n_FormatInc/DecreaseDecimalPlace