Skip to content

Instantly share code, notes, and snippets.

@lsshawn
lsshawn / +page.svelte
Created October 13, 2025 11:46
svelte await to load data
<script lang="ts">
let data = $state(null);
async function loadSmallData() {
const response = await fetch('https://meowfacts.herokuapp.com/?count=2');
if (!response.ok) {
throw new Error(`Failed to fetch data: ${response.statusText}`);
}
data = (await response.json()).data;
}
{
"timezones": [{
"name": "Pacific/Niue",
"offset": "(GMT-11:00) Niue"
}, {
"name": "Pacific/Pago_Pago",
"offset": "(GMT-11:00) Pago Pago"
}, {
"name": "Pacific/Honolulu",
"offset": "(GMT-10:00) Hawaii Time"
@lsshawn
lsshawn / SlVueTree.vue
Created April 26, 2020 00:54
Attempting to rewrite SlVueTree in Typescript
<template>
<div
class="sl-vue-tree"
:class="{ 'sl-vue-tree-root': isRoot }"
@mousemove="onMousemoveHandler"
@mouseleave="onMouseleaveHandler"
@dragend="onDragendHandler(null, $event)"
>
<div ref="nodes" class="sl-vue-tree-nodes-list">
<div
const categories = [
{
_id: 1,
index: 1000,
name: 'pictures',
level: 1,
children: []
},
{
_id: 2,
@lsshawn
lsshawn / templateStringFromJson.ts
Created November 8, 2019 15:01
Template string from JSON
// ASIDE: replace multiple ${} in a string with a JSON reference.
const replacer = (str: string, obj: object) : object => {
const keys = Object.keys(obj);
const func = Function(...keys, "return `" + str + "`;");
return func(...keys.map(k => obj[k]));
}
let s = "I'm ${name} from ${country}"
let replaced = replacer(s, {name: 'SS', country: 'MSIA'})
console.log(replaced)