Skip to content

Instantly share code, notes, and snippets.


swyx sw-yx

View GitHub Profile
sw-yx / sample.go
Created Jul 6, 2021
old Temporal code samples
View sample.go
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 + ...
sw-yx / useLocalStorage.js
Last active Jul 2, 2021
SSR friendly version of useLocalStorage hook. you can also use this in a library
View useLocalStorage.js
// 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
View clubhouse blogpost

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).


View manual typography plugin since i got fed up with dark

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 {
sw-yx /
Last active Nov 20, 2020
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.

sw-yx / Newton-1.29.vb
Last active Jul 29, 2021
Newton - my VBA utility library for doing matrix multiplication and other useful automations during my finance days
View Newton-1.29.vb
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
sw-yx / Aprendiendoenpú
Created Nov 1, 2020
Aprendiendo en público - La forma más rápida de aprender. English:
View Aprendiendoenpú

Aprendiendo en público La forma más rápida de aprender

Si existiera una regla de oro sería esta, todas las demás reglas se derivan en mayor o menor medida de esta regla principal.

Está establecido que alguien nunca termina de aprender, sin embargo, la mayor parte de las personas “aprenden en privado” convirtiéndose en observadores pasivos. Consumen información sin generar ninguna. Mientras que este comportamiento no tiene nada de malo, aquí queremos llegar a estar entre el top de nuestra profesión y para conseguirlo es necesario tener el hábito de establecer sistemas para compartir nuestro aprendizaje:

• Crea blogs, tutoriales y cheat sheets.
• Realiza conferencias y meetups.
• Participa en foros como Stackoverflow o Reddit. Evita sitios privados como Slack o Discord.
sw-yx / diversity in
Created Oct 6, 2020
diversity in tech resources and organizations. done as part of research for
View diversity in

US Centric (but often Worldwide)

Don't forget there are many state and city level organizations that can help you too.


  • US centric/Global:
    • Wonder Women Tech - We highlight, celebrate, and educate Women and the Underrepresented in Science, Technology, Engineering, the Arts, Math (STEAM) and Innovation. We nourish the global life cycle of the pipeline through equity, access, and opportunity.
    • FWD: For Women & Diversity Collective - We are a community dedicated to professional inclusion. We host summits & workshops featuring women, P.O.C., and under-represented groups for the experts that we are rather than the boxes that we check.
sw-yx /
Last active Oct 25, 2020
Custom shortcode syntax for Elder.js

why you may need to customize shortcode syntax

  • elder.js self closing shortcodes look like this: {{foo bar="true"/}}. Note the / at the end is for Elder.js to parse both self closing and content wrapping shortcodes.
  • this clashes with other shortcode systems, eg., which uses shortcodes that look like this: {% youtube abc123 %}
  • in elder.config.js you can customize the start and end shortcode: {%foo bar="true"/%}
  • however that / there is non negotiable.
  • this is why you need to customize the shortcode syntax

the strategy is, if you use remark to process the text, to write a custom remark plugin to replace specifically this %} ending code of the shortcode to what Elder.js expects