Skip to content

Instantly share code, notes, and snippets.

View cristovao-trevisan's full-sized avatar

Cristóvão Trevisan cristovao-trevisan

View GitHub Profile
@cristovao-trevisan
cristovao-trevisan / Tabs.svelte
Last active February 4, 2021 11:57
svelte-tabs
<script lang="ts">
interface Tab {
title: string
}
export let tabs: Tab[]
export let selected = 0
</script>
<ul class="flex w-full border-b">
const semanticVersionRegex = /^\d+(\.?[\d]+){0,2}$/
@cristovao-trevisan
cristovao-trevisan / location.js
Last active December 5, 2020 15:15
Svelte Geolocation API
import { writable, get } from 'svelte/store'
const initialState = {
supported: false,
allowed: false,
error: null,
location: null,
loading: false,
timestamp: -1,
}
@cristovao-trevisan
cristovao-trevisan / use-store.ts
Last active March 18, 2022 16:53
Using svelte/store with react hooks (useStore)
interface Setter<T> {
(value: T): void
}
export function useStore <T> (store: Writable<T>) : [T, Setter<T>]{
const initialValue: T = get(store);
const [value, setValue] = useState(initialValue);
useEffect(() => store.subscribe(setValue), []);
return [value, store.set];
}
@cristovao-trevisan
cristovao-trevisan / install-esp-idf.sh
Last active February 7, 2020 21:03
Install ESP IDF
echo "\n\nCloning IDF v3.3.1\n\n"
mkdir -p ~/esp
cd ~/esp
git clone --branch v3.3.1 --recursive git@github.com:espressif/esp-idf.git
echo "Installing components\n\n"
cd esp-idf
./install.sh
echo "Setting up environment\n\n"
@cristovao-trevisan
cristovao-trevisan / definition.ts
Last active October 22, 2019 17:40
Async Library API
// 1. Internal API
interface Resource<Data, Props = any> {
// here goes the INTERNAL API provided by the core that
// should be used by other libraries/frameworks to provide
// the real user interface
// We can also provide an API for debugging and other tools
subscribe: (cb: () => Data) => UnsubscribeFunction,
run: (props: Props, options: RunOptions) => Data,
abort: () => void,
update: (props: Props, currentData: Data) => Data,
@cristovao-trevisan
cristovao-trevisan / copy-and-paste.js
Last active October 11, 2021 14:05
Open torrent links
// get page links
const elements = document.getElementsByTagName('a')
const links = []
for(const link of elements) links.push(link)
// filter wanted torrents
const hrefs = links
.filter(l => l.innerText === '720p')
.map(l => l.href)
const torrents = hrefs
.map(href => /magnet.*/.exec(href))
@cristovao-trevisan
cristovao-trevisan / 1 - .zshrc
Last active June 9, 2021 15:19
zsh configuration using zinit
# # SDKMAN
# export SDKMAN_DIR="$HOME/.sdkman"
# [[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"
# GO
export PATH="$PATH:$HOME/go/bin"
# ZINIT
if [[ ! -f $HOME/.zinit/bin/zinit.zsh ]]; then