Skip to content

Instantly share code, notes, and snippets.

View peat-psuwit's full-sized avatar

Ratchanan Srirattanamet peat-psuwit

View GitHub Profile
@peat-psuwit
peat-psuwit / streamingHTML.mjs
Created April 23, 2024 17:46
streamingHTML, v2 (now works with Firefox)
/*
* Simple HTML streaming concept, inspired by how NextJS do it, but without
* React.
*
* It works by initially sending a skeleton HTML to the browser, but,
* importantly, this skeleton is unclosed, which allows server to stream in
* more content. However, you cannot go back to edit the HTML content you've
* already sent. Or can you???
*
* Turns out, if the additional content is a <script> tag which changes the
@peat-psuwit
peat-psuwit / streamingHTML.mjs
Created April 23, 2024 07:06
streamingHTML
import { setTimeout } from "node:timers/promises";
import express from "express";
/* Simple HTML streaming concept, inspired by now NextJS do it, but without React.
* TODO: figure out why in the world does Firefox not show the "Loading..." as soon
* as it's received.
*/
async function getContent() {
await setTimeout(5000);
<html>
<head>
<style>
button[aria-hidden="true"] {
opacity: 0;
padding: 0;
height: 0;
width: 0;
overflow: hidden;
}
function bindWeakImpl<
TFn extends (...args: any) => any,
TTarget extends object,
>(fn: TFn, weakTarget: WeakRef<TTarget>, defaultReturn: ReturnType<TFn>)
{
return function(...args: Parameters<TFn>): ReturnType<TFn> {
const target = weakTarget.deref();
if (target === undefined) {
console.debug(`bindWeak: target of ${fn} is now unreachable. Return ${defaultReturn}`);
return defaultReturn;
# User: replace "system-update" below to your plugin of interest.
BEGIN {
plugin_name = "system-update"
plugin_pat = "/plugins/" plugin_name "/"
}
$0 ~ /^#\. TRANSLATORS: This is a keyword or name for the / {
if ($11 == plugin_name) {
has_keyword=1
@peat-psuwit
peat-psuwit / automatic-gitpod-setup.sh
Last active March 29, 2022 19:08
Automatically setup a GitPod working environment
#!/bin/sh
if [ -e debian/ubports.source_location ] && ! [ -e .pc/ ]; then
# Fetch & extract source
sudo apt install --no-install-recommends -y devscripts quilt
(
{ read -r url; read -r file; } < debian/ubports.source_location
wget -O "../${file}" "$url"
)
origtargz --unpack
@peat-psuwit
peat-psuwit / Android.mk
Created September 17, 2020 20:32
Test loader's behavior regarding loaded library at exit
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libpeat-test
LOCAL_SRC_FILES := lib.cpp
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := peat-test-app
LOCAL_SRC_FILES := app.c
@peat-psuwit
peat-psuwit / .pbuilderrc
Created February 4, 2020 18:09
Build a minimalist Debian packages build server (UBports repo)
CCACHEDIR=/var/cache/pbuilder/ccache/
EXTRAPACKAGES=pkg-create-dbgsym
export DEB_BUILD_OPTIONS=parallel=`nproc`
@peat-psuwit
peat-psuwit / qcamerasvr_wrapper.sh
Created August 21, 2019 07:10
How to run a daemon and collect ftrace from it. (The example is mm-qcamera-daemon)
#!/system/bin/sh
echo 'function_graph' >/sys/kernel/debug/tracing/current_tracer
echo 96000 > /d/tracing/buffer_size_kb
echo $$ > /sys/kernel/debug/tracing/set_ftrace_pid
echo 1 > /sys/kernel/debug/tracing/tracing_on
(
sleep 10 # stop tracing after this second.
@echo off
rem set the version of jdk you would like to use (1.4, 1.5, 1.6, etc)
set JDK_Version=1.8
set Located=
echo.
echo Locating JDK %JDK_Version%
for /d %%i in ("%ProgramFiles%\Java\jdk%jdk_Version%*") do (set Located=%%i)
rem check if JDK was located