Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

swyx sw-yx

🎯
Focusing
View GitHub Profile
View manual typography plugin since i got fed up with dark mode.md

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
sw-yx / svelte.md
Last active Nov 20, 2020
Svelte micro-RFC: configurable event modifiers
View svelte.md

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
sw-yx / Newton-1.29.vb
Last active Jan 20, 2021
Newton - my VBA utility library for doing matrix multiplication and other useful automations during my finance days https://twitter.com/swyx/status/1327041894853922816
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
sw-yx / Aprendiendoenpúblico.md
Created Nov 1, 2020
Aprendiendo en público - La forma más rápida de aprender. English: http://swyx.io/learn-in-public
View Aprendiendoenpúblico.md

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
sw-yx / diversity in tech.md
Created Oct 6, 2020
diversity in tech resources and organizations. done as part of research for learninpublic.org
View diversity in tech.md

US Centric (but often Worldwide)

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

Women

  • 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
sw-yx / elderjs-shortcode-motivation.md
Last active Oct 25, 2020
Custom shortcode syntax for Elder.js
View elderjs-shortcode-motivation.md

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. dev.to, 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 dev.to shortcode to what Elder.js expects

View useColorSchemePreference.ts
import React from "react";
export type ColorScheme = "light" | "dark";
export default function useColorSchemePreference(
defaultColorScheme: ColorScheme = "light"
) {
let darkQuery = "(prefers-color-scheme: dark)";
let [colorScheme, setColorScheme] = React.useState<ColorScheme>(
typeof window === "object" && window.matchMedia
@sw-yx
sw-yx / types for estree with JSX.ts
Last active Aug 7, 2020
types for estree with JSX - the default estree types (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/estree/index.d.ts) dont come with JSX definitions so i made a short start on them. pls comment if you have more to add
View types for estree with JSX.ts
interface Location {
start: number;
end: number;
};
interface JSXOpeningElement extends Location {
type: 'JSXOpeningElement',
attributes: JSXAttribute[],
name: JSXIdentifier,
selfClosing: boolean
@sw-yx
sw-yx / mobilenav.svelte
Created Jun 30, 2020
my mobile responsive nav
View mobilenav.svelte
<script>
import { clickOutside } from "./actions.js";
let activeNav = "Home";
let isMobile;
let isMobileAndNavActive = false;
// $: console.log({ isMobile, isMobileAndNavActive });
function handleClickOutside() {
if (isMobile && isMobileAndNavActive) {
isMobileAndNavActive = !isMobileAndNavActive;
@sw-yx
sw-yx / stringify.ts
Created Jun 6, 2020
JSON stringify replacer (no circular deps) pretty printer
View stringify.ts
import parse5 from 'parse5'
var src = `
{#if name}
<script>
console.log('not top level')
</script>
{/if}
<ul>
{#each cats as cat}