Skip to content

Instantly share code, notes, and snippets.

@ka2n
ka2n / main.go
Created March 9, 2023 20:50
echo server
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func main() {
@ka2n
ka2n / index.js
Created January 20, 2023 02:30
Read streaming response with fetch
const http = require('http')
const express = require('express')
const app = express()
app.get('/', (req, res) => {
res.setHeader('Content-Type', 'text/html')
res.setHeader('Transfer-Encoding', 'chunked');
res.send(`<html><body><h1>Hello World</h1>
<ul id="list"></ul>
<script>
@ka2n
ka2n / find-parent-package-dir
Last active January 12, 2023 01:24
Find upwards to package root
#!/bin/bash
ROOT_DIR=$(git rev-parse --show-toplevel)
if [ -z "$ROOT_DIR" ]; then
echo "Not a git repository"
exit 1
fi
if [[ "$PWD" == "$ROOT_DIR" ]]; then
exit 0
@ka2n
ka2n / dmesg.txt
Created December 5, 2022 06:22
USB microphone error log
[ 2405.845251] usb 3-9.2: new full-speed USB device number 11 using xhci_hcd
[ 2405.949108] usb 3-9.2: New USB device found, idVendor=046d, idProduct=0ab1, bcdDevice= 4.0a
[ 2405.949130] usb 3-9.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 2405.949139] usb 3-9.2: Product: Yeti Nano
[ 2405.949145] usb 3-9.2: Manufacturer: Blue Microphones
[ 2405.949150] usb 3-9.2: SerialNumber: XXXXXXXXXXXXXX
[ 2406.047668] input: Blue Microphones Yeti Nano Consumer Control as /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.2/3-9.2:1.3/0003:046D:0AB1.000F/input/input45
[ 2406.099300] input: Blue Microphones Yeti Nano as /devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9.2/3-9.2:1.3/0003:046D:0AB1.000F/input/input46
[ 2406.099531] hid-generic 0003:046D:0AB1.000F: input,hiddev99,hidraw7: USB HID v1.11 Device [Blue Microphones Yeti Nano] on usb-0000:00:14.0-9.2/input3
[ 2406.180739] usb 3-9.2: Not enough bandwidth for new device state.
@ka2n
ka2n / coredump.txt
Last active December 2, 2022 01:09
uim-xim crash
Dec 02 10:04:32 monicle systemd-coredump[29377]: [🡕] Process 29372 (uim-xim) of user 1000 dumped core.
Stack trace of thread 29372:
#0 0x00007fbf105948b4 XwcTextExtents (libX11.so.6 + 0x5d8b4)
#1 0x000055d9974167fe n/a (uim-xim + 0xb7fe)
#2 0x000055d997416a0c n/a (uim-xim + 0xba0c)
#3 0x000055d997416acb n/a (uim-xim + 0xbacb)
#4 0x000055d997416bbd n/a (uim-xim + 0xbbbd)
#5 0x00007fbf10685bea n/a (libuim.so.8 + 0xbbea)
#6 0x00007fbf106a2674 n/a (libuim-scm.so.0 + 0xd674)
@ka2n
ka2n / superquerylib.md
Last active November 10, 2022 14:21
future-query-library

Components

const List = () => {
  return useQuery(gql`items(variant: "recent")` { min: 10 })
    .map(({ id: idPromise }) => <Item id={idPromise} />)
}

const Item = ({ id: idPromise }) => {
 const data = useQuery(gql`node(id: $id)`, { id: idPromise })
@ka2n
ka2n / gist:d462d3c1ef0a234b80289ac23ee5a39a
Last active August 29, 2022 06:41
Delete some environments from GitHub
owner=
repo=
gh api repos/{owner}/{repo}/environments\?per_page=100 |
jq '.environments[] | select(.name | (contains("production") or contains("preview")) | not) | .node_id' |
xargs -n1 -I% sh -c "
gh api graphql -F query='
mutation {
deleteEnvironment(input: { id: \"%\"}) {
clientMutationId
@ka2n
ka2n / open-source.ts
Created December 27, 2021 05:56
Open source code location in VS Code without babel plugin
declare global {
interface Window {
__openSourceHandlers: {
teardown: () => unknown
} | null
}
}
if (process.env.NODE_ENV === "development") {
;(function () {
@ka2n
ka2n / slim_annotate.rb
Created December 24, 2021 01:39
Rails: alt-clickでクリックしたpartialをVSCodeで開きます
module TempleRailsAnnotate
def call(template, source = nil)
opts = {}.update(self.class.options).update(file: template.identifier)
result = ''
if ActionView::Base.annotate_rendered_view_with_filenames && template.format == :html
whatpartial = "(file://#{template.identifier})"
result << "@output_buffer.safe_concat('<!-- BEGIN #{template.short_identifier}#{whatpartial} -->');"
end
result << self.class.compile((source || template.source), opts)
if ActionView::Base.annotate_rendered_view_with_filenames && template.format == :html
@ka2n
ka2n / hydrate-client.tsx
Created February 25, 2021 08:33
Hydrate from Javascript
/// <reference types="requestidlecallback-polyfill" />
import React, { createElement, useEffect, useState } from "react"
if (typeof window !== "undefined") {
require("requestidlecallback-polyfill")
}
const components = {
Test: () => {
return <div>Hello!</div>