Skip to content

Instantly share code, notes, and snippets.

View perjerz's full-sized avatar
🏠
Working from home

Siwat Kaolueng perjerz

🏠
Working from home
View GitHub Profile
const TMDB_IMAGE_BASE_URL = 'https://image.tmdb.org/t/p/';
addEventListener("fetch", e => {
const url = new URL(e.request.url);
if (url.pathname === "/image") {
e.respondWith((async () => {
const width = url.searchParams.get("width");
const path = url.searchParams.get("path");
try {
return await fetch(`${TMDB_IMAGE_BASE_URL}/w${width}${path}`, {mode: "no-cors"});
addEventListener("fetch", e => {
if (e.request.destination !== "image" || // Only do this when requesting an image
request.mode === "no-cors") // We don't know the status of no-cors images
return;
e.respondWith((async () => {
try {
const response = await fetch(e.request);
if (response.ok)
return response;
@pjlamb12
pjlamb12 / data-table.component.html
Created November 26, 2022 23:49
Angular Data Table Component
<content-section
[csTitle]="title"
[collapsible]="collapsible"
[state]="state"
[locked]="locked"
[noButtons]="noButtons"
[buttons]="_buttons"
>
<!-- Custom controls -->
<ng-content></ng-content>
@peerreynders
peerreynders / README.md
Last active September 14, 2022 14:19
µsignal 0.4.2 performance comparison

Sample run on Ubuntu 22.04 LTS [i7-4900MQ CPU @ 2.80GHz/32GB] Chromium 105.0.5195.102

Solid (solid.html)

Created 205760 nodes.
278 ms; sum: 9.11303444731602e+305

@preact/signals (preactive.html)

@acoshift
acoshift / index.html
Last active January 30, 2022 10:11
<!doctype html>
<html lang=en>
<script src="https://cdn.jsdelivr.net/npm/ethers@5.5.3/dist/ethers.umd.min.js" defer></script>
<script src="https://cdn.jsdelivr.net/npm/@metamask/detect-provider@1.2.0/dist/detect-provider.min.js" defer></script>
<script src="https://cdn.jsdelivr.net/npm/alpinejs@3.8.1/dist/cdn.min.js" defer></script>
<script>
window.abi = {
'IERC20': [
{
@steveruizok
steveruizok / cacheflowelike.ts
Created June 27, 2021 21:05
A beautiful shape for tldraw.
// Run this code on tldraw.com
// By @steveruizok
// Based on an awesome image by @cacheflowe: https://twitter.com/cacheflowe/status/1408902719130288130
new NumberControl({
label: 'radius',
value: 200,
min: 50,
max: 500,
})
@armanozak
armanozak / rxjs-7_retry-resetOnSuccess.ts
Created May 3, 2021 09:17
[What's New in RxJS 7] RxJS 7 retry resetOnSuccess #blog #rxjs
import { defer, from } from "rxjs";
import { retry, tap } from "rxjs/operators";
const values = ["_", 0, 1, 0, 2, 0, 3, 0, 0, 0, 4];
defer(() => {
values.shift();
return from(values);
})
.pipe(
@sindresorhus
sindresorhus / esm-package.md
Last active June 18, 2024 23:18
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
// Playground link: https://www.typescriptlang.org/play?#code/PTAEHEEsGcBdQG4FMBO1IHsB2AuUALWWAB2hxAHMZYA6K2fAVwCMaBjDAW2ACUelkaVMABMAZgCMbMQDYAHAFZFAQwAmCkWwAMSACwB2VXJHN98hQu1IFAWABQ92AE9iSUAFEAHkjYAeAMJcnMpYqtAANKAAyrDKsG4AvKAA3qBwymwA1ngA2gC6kQA2GGzKhWQpAL6glQB8oAn2oKCBnMGh0KBInvEdoDmQWABmqC1BIaqRNNODIyig-HB5TaAA-B7efouwkV4+re2qvjFxSJEHE7W1K3gn8QDc9o4ubgDygiiQqki+r8wAVpEAHLKThnUAANTKjCQ9SSILBXR6SD6cE+WAoaxSKxyAGlQINQAAKTJIJwYIagP7-ACUoAAPqAEUg8nh8d1emEmaC3OsoYUYaA8NS8aAAGTE0nkynUmnLOzVPBYASoR4OOzOVwQJCwfkw34A4E8uHcxEclFcqUUqkArEi5l5IWgZWCNXPLUAFUYxEKPyBSM5nSwjE4zFQkR4AYtnRCTnyDX6eRNPByAHJfRiGKnHea+v71pG8F6fX7IjlY1Npjwk267IN4ighhk3ECkBQgSGwyhfABBZidXNc4Oh1D1VLKihxSDIPB9zqVd0ttu+D0mj1RvNtjsj7uzUZz+rrOdO9eDoOd0brVvti-d1dOl2qp4al6gOcrtcbrnX7dd3x7+Y53vI9+3XIsv3PHcsTA50VRQWtNTcHtiB9JwokgCgsBXSIAAUMAHZE+mYDAMF9EITTwgjA1AWAUEFdYYOvD8ENfcAdXQzCPwTU9CO-Ldb18Ycu0PUAm3KNw8FomEWK1ABZRhCg4rCe0iAAhE0chU0BVJzXjOhyKTwUMx1GRyMToHBcyWSxQynSsmS3CiENf1QXsIOdW81PcoTRwTHJphoYtfV7WpK0C71gvUvI0wzCgs0dCUfPg59EOiFggp+Ht3NjfIvLPUAcq
@ClickerMonkey
ClickerMonkey / types.ts
Last active June 18, 2024 17:13
Typescript Helper Types
// when T is any|unknown, Y is returned, otherwise N
type IsAnyUnknown<T, Y, N> = unknown extends T ? Y : N;
// when T is never, Y is returned, otherwise N
type IsNever<T, Y = true, N = false> = [T] extends [never] ? Y : N;
// when T is a tuple, Y is returned, otherwise N
// valid tuples = [string], [string, boolean],
// invalid tuples = [], string[], (string | number)[]