Skip to content

Instantly share code, notes, and snippets.

View thekarel's full-sized avatar

Charles Szilagyi thekarel

View GitHub Profile
@thekarel
thekarel / country-bounding-boxes.py
Created December 15, 2024 15:56 — forked from graydon/country-bounding-boxes.py
country bounding boxes
# extracted from http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip
# under public domain terms
country_bounding_boxes = {
'AF': ('Afghanistan', (60.5284298033, 29.318572496, 75.1580277851, 38.4862816432)),
'AO': ('Angola', (11.6400960629, -17.9306364885, 24.0799052263, -4.43802336998)),
'AL': ('Albania', (19.3044861183, 39.624997667, 21.0200403175, 42.6882473822)),
'AE': ('United Arab Emirates', (51.5795186705, 22.4969475367, 56.3968473651, 26.055464179)),
'AR': ('Argentina', (-73.4154357571, -55.25, -53.628348965, -21.8323104794)),
'AM': ('Armenia', (43.5827458026, 38.7412014837, 46.5057198423, 41.2481285671)),
@thekarel
thekarel / reset.css
Created November 22, 2024 08:01
Modern CSS reset by Andy Bell
/* Copy of the CSS at https://piccalil.li/blog/a-more-modern-css-reset/ */
/* Box sizing rules */
*,
*::before,
*::after {
box-sizing: border-box;
}
/* Prevent font size inflation */
@thekarel
thekarel / +page.server.ts
Created November 17, 2024 13:58
Revoke a GitHub Oauth app grant via REST
// This will remove the grant, i.e. as if the user never registered with the app.
// They will have to go trough the consent screen again
await ky
.delete(`https://api.github.com/applications/${event.locals.env.AUTH_GITHUB_ID}/grant`, {
headers: {
Accept: 'application/vnd.github+json',
Authorization: `Basic ${btoa(`${event.locals.env.AUTH_GITHUB_ID}:${event.locals.env.AUTH_GITHUB_SECRET}`)}`,
'X-GitHub-Api-Version': '2022-11-28',
},
json: {
@thekarel
thekarel / debounce.ts
Created November 6, 2024 12:08
svelte input debounce
/**
* Debounce the input value change event
*
* Copied from https://github.com/svelte-seoul/svelte-debounce/blob/master/index.js and added types
*
* Example: run console.log after 750ms of the last input event, no matter how many input events are fired
*
* ```svelte
* <input use:debounce={{callback: console.log}} />
* ```
@thekarel
thekarel / TypeIDSchema.ts
Last active November 1, 2024 15:18
TypeID Valibot Schema
import {fromString, type TypeID} from 'typeid-js'
import * as v from 'valibot'
/**
* Create a Valibot schema for a TypeID with a given prefix
*
* Example:
*
* ```ts
* const PigIdSchema = TypeIDSchema('pig')
@thekarel
thekarel / caseInsensitiveFilter.ts
Created July 15, 2021 16:25
antd Cascader case-insensitive search
import {CascaderOptionType, FilledFieldNamesType} from 'antd/lib/cascader'
export const caseInsensitiveFilter = (inputValue: string, path: CascaderOptionType[], names: FilledFieldNamesType) =>
path.some((option) => option[names.label].toLowerCase().includes(inputValue.toLowerCase()))
@thekarel
thekarel / validate_and_squash_this_branch.sh
Created August 31, 2020 08:27
Validate and squash this branch
validate_and_squash_this_branch () {
BRANCH=`git branch --show-current`
yarn validate && \
git checkout master && \
git merge --squash $BRANCH && \
git commit -v -a
}
@thekarel
thekarel / native-mobile-share.js
Created May 3, 2020 10:47
Native mobile share experience on mobile browsers
// Share Url
shareUrl = function() {
if (!navigator.share) return;
navigator.share({
url: "https://mywebsite.com",
title: "Sharing Cool things",
text: "Checkout my really cool website."
})
.then(() => { console.log("Shared YEEEE!!!!!"); })
@thekarel
thekarel / fetchOnceAndSaveToDiskWithBuffer.js
Created March 2, 2020 12:48
fetchOnceAndSaveToDiskWithBuffer
async function fetchOnceAndSaveToDiskWithBuffer(url, filename) {
return new Promise(resolve => {
if (fs.existsSync(filename)) {
resolve(readFile(filename));
return;
}
const file = fs.createWriteStream(filename);