Skip to content

Instantly share code, notes, and snippets.

@inian
inian / rpc_pokemon.sql
Created January 16, 2024 05:28
Vercel plv8 bundle
CREATE OR REPLACE FUNCTION public.rpc_pokemon()
RETURNS text
LANGUAGE plv8
STRICT
AS $function$
var __rpc=(()=>{var mo=Object.create;var Ie=Object.defineProperty;var vo=Object.getOwnPropertyDescriptor;var go=Object.getOwnPropertyNames;var So=Object.getPrototypeOf,xo=Object.prototype.hasOwnProperty;var re=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ko=(e,t)=>{for(var r in t)Ie(e,r,{get:t[r],enumerable:!0})},nr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of go(t))!xo.call(e,l)&&l!==r&&Ie(e,l,{get:()=>t[l],enumerable:!(n=vo(t,l))||n.enumerable});return e};var Me=(e,t,r)=>(r=e!=null?mo(So(e)):{},nr(t||!e||!e.__esModule?Ie(r,"default",{value:e,enumerable:!0}):r,e)),wo=e=>nr(Ie({},"__esModule",{value:!0}),e);var lr=re(or=>{"use strict";(function(e){function t(){}function r(){}var n=String.fromCharCode,l={}.toString,o=l.call(e.SharedArrayBuffer),u=l(),i=e.Uint8Array,s=i||Array,a=i?ArrayBuffer:s,c=a.isView||function(y){return y&&"length"in y},h=l.call(a.prototype);a=r.proto
@inian
inian / test.ts
Last active November 15, 2022 14:02
test
import { Application } from "https://deno.land/x/[email protected]/mod.ts";
const app = new Application();
app.use((ctx) => {
ctx.response.body = "Hello World! ini1";
console.log(ctx);
});
await app.listen({ port: 8000 });
@inian
inian / index.js
Created January 19, 2022 06:18
Move Supabase storage objects between projects
const { createClient } = require("@supabase/supabase-js");
const OLD_PROJECT_URL = "https://xxx.supabase.co";
const OLD_PROJECT_SERVICE_KEY = "old-project-service-key-xxx";
const NEW_PROJECT_URL = "https://yyy.supabase.co";
const NEW_PROJECT_SERVICE_KEY = "new-project-service-key-yyy";
(async () => {
const oldSupabaseRestClient = createClient(
@inian
inian / split.sh
Created June 27, 2019 09:18
Convert image to Y, Cb, Cr components
convert image.png -colorspace YUV -sampling-factor 4:2:2 -separate \
\( -clone 0 \) \
\( -clone 1 -fill black -colorize 100% \) \
\( -clone 1 -negate \) \
\( -clone 1 \) \
image_b_temp.png
convert image_b_temp-4.png image_b_temp-5.png image_b_temp-6.png -channel RGB -combine image_b.png
convert image.png -colorspace YUV -sampling-factor 4:2:2 -separate \
@inian
inian / async-decoding.html
Last active June 13, 2019 12:44
Image decoding
<html>
<body>
<div class="jank-detector">
Random numbers, to highlight jank:
<span class="rand"></span>
</div>
<script>
const rand = document.querySelector(".rand");
function randFrame() {
rand.textContent = Math.random();
const img = new Image();
img.src = "cat.png";
img.decode().then(() => {
// image fully decoded and can be safely rendered on the screen
const orig = document.getElementById("orig");
orig.parentElement.replaceChild(img, orig);
});
@inian
inian / network-aware-sw.js
Last active June 11, 2019 18:15
Network aware asset optimization
function modifyURL(url) {
// ect can be 'slow-2g', '2g', '3g', or '4g'.
const connectionType = navigator.connection.effectiveType;
if (connectionType === "slow-2g" || connectionType === "2g") {
return url + "?opt=aggressive";
} else if (connectionType === "4g") {
return url + "?opt=mild";
} else {
return url + "?opt=default";
}
@inian
inian / hapi.js
Last active August 30, 2019 04:15
Node Frameworks using http2
var fs = require('fs');
var Hapi = require('hapi');
var http2 = require('http2');
var options = {
key: fs.readFileSync('./selfsigned.key'),
cert: fs.readFileSync('./selfsigned.crt'),
};
var server = new Hapi.Server();
@inian
inian / http2-compatibility-api.js
Last active November 4, 2017 12:55
Creating a zero-dependency Node.js static file server
const http2 = require('http2');
const fs = require('fs');
const options = {
key: fs.readFileSync('./selfsigned.key'),
cert: fs.readFileSync('./selfsigned.crt'),
allowHTTP1: true
}
const server = http2.createSecureServer(options, (req, res) => {
@inian
inian / unregister.js
Last active June 2, 2018 08:20
Unregister Dexecure Service Worker registrations
try {
navigator.serviceWorker.getRegistrations().then(function(registrations) {
registrations.forEach(function(registration) {
if (registration.active && registration.active.scriptURL.includes("dexecure")) {
console.log('removing registration', registration);
registration.unregister();
}
})
})
} catch (e) {