Skip to content

Instantly share code, notes, and snippets.

export const reactiveQueryArgs = <T>(cb: () => T) => {
const store = writable<T>();
$effect.pre(() => {
store.set(cb());
});
return store;
};
@o-az
o-az / install_docker_ubuntu.sh
Created October 11, 2024 07:10
install docker on Ubuntu. This will require `sudo` to run `docker`. To run without `sudo`, see `no-sudo.md` for directions
sudo apt update --yes
sudo apt upgrade --yes
sudo apt install --yes \
curl \
apt-transport-https \
ca-certificates \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
echo "http://dl-cdn.alpinelinux.org/alpine/v3.20/main" > /etc/apl/repositories;
echo "http://dl-cdn.alpinelinux.org/alpine/v3.20/community" >> /etc/apl/repositories;
echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apl/repositories;
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apl/repositories;
echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apl/repositories;
echo "http://dl-cdn.alpinelinux.org/alpine/latest-stable/main" >> /etc/apl/repositories;
echo "http://dl-cdn.alpinelinux.org/alpine/latest-stable/community" >> /etc/apk/repositories;
apk update
@o-az
o-az / graphiql.html
Created August 19, 2024 17:58
example of graphiql playground in an html page. Play here https://codepen.io/o-az/pen/poXaZxj?editors=1000
<html lang='en'>
<head>
<title>GraphiQL</title>
<Style>
body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
<!DOCTYPE html>
<html>
<head>
<title>ES6 Demonstration</title>
<style>
.pager { margin: 5px 10px; user-select: none; font-family: sans-serif; }
.page { display: inline-block; padding: 0 5px; cursor: pointer; }
.page:active, .selected { color: red; }
.selected { font-weight: bold; }
#content { font: bold 250% sans-serif; padding: 25px 10px; }
{
"schema": "https://json.schemastore.org/tsconfig.json",
"compilerOptions": {
"strict": true,
"baseUrl": ".",
"noEmit": true,
"allowJs": true,
"checkJs": true,
// depending on the use case
// we might add "DOM" and "DOM.Iterable" as well
@o-az
o-az / auto-commit.yml
Last active September 7, 2024 22:29
This GitHub Action automatically formats code using Prettier when a pull request is opened or updated. It then commits and pushes the formatted code back to the same PR branch, ensuring consistent code style across contributions without manual intervention.
name: 'Auto Commit Prettier'
on:
pull_request:
branches: ['main']
jobs:
auto-commit:
name: 'Auto Commit'
runs-on: ['ubuntu-latest']
@o-az
o-az / sqlite-60k-rps.md
Created July 17, 2024 00:36
How I squeeze 60k RPS out of SQLite on a $5 VPS
  1. Configuring PRAGMAs. We need to send the following PRAGMA commands right after opening the connection:

PRAGMA journal_mode = WAL;

  • enables write-ahead log so that your reads do not block writes and vice-versa.

PRAGMA busy_timeout = 5000;

  • sqlite will wait 5 seconds to obtain a lock before returning SQLITE_BUSY errors, which will significantly reduce them.

PRAGMA synchronous = NORMAL;

@o-az
o-az / git_fzf_log.fish
Last active July 5, 2024 07:45
search through files in past commits with fzf (fish)
function git-fzf-log
git log --oneline --decorate --color=always | fzf --ansi --no-sort --reverse --multi --bind 'ctrl-s:toggle-sort' \
--header 'Press CTRL-S to toggle sort' \
--preview 'git show --color=always {+1}' | awk '{print $1}'
end
git-fzf-log | xargs -I % git diff %^ %

onNavigate, onMount, onDestroy, and beforeUpdate run in a specific order

example:

<script lang="ts">
  import { onNavigate } from '$app/navigation'
  import { onMount, onDestroy, beforeUpdate, tick } from 'svelte'

  beforeUpdate(async () => {
 console.info('beforeUpdate - tick')