Skip to content

Instantly share code, notes, and snippets.

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

Kay Gosho acro5piano

🏠
Working from home
View GitHub Profile
@acro5piano
acro5piano / prql.ts
Created November 15, 2024 10:04
Bringing PRQL into TypeScript
prql
.query()
.from('invoices')
.derive({
transaction_fee: 0.8,
income: 'total - transaction_fee',
})
.filter('income', '>', 5)
.filter('invoice_date', '>=', '@2010-01-16')
.group('customer_id', {
import { DateTime } from 'luxon'
const a = DateTime.now().setZone('Asia/Tokyo')
const b = DateTime.fromISO('2024-11-07').setZone('Asia/Tokyo').endOf('day')
const c = DateTime.now()
console.log({ a, b, c })
console.log(a < b)
console.log(b < c)
@acro5piano
acro5piano / generateAllMutations.mjs
Created September 7, 2024 17:42
Generate all GraphQL mutations from GraphQL schema IDL
import fs from 'fs'
const header = `
#
# This file is auto generated. Do not edit by hand.
#
`.trimStart()
const schema = fs.readFileSync('path/to/schema.graphql', 'utf8')
const allMutations = generateAllMutations(schema).join('\n')
@acro5piano
acro5piano / rust-to_string-vs-clone.md
Last active July 10, 2024 10:36
Rust to_string vs clone performance comparison
// main.rs

use std::time::Instant;

fn main() {
    let instant = Instant::now();
    let text = "".to_string();
    for _ in 1..100000000 {
        let _ = text.to_string();
@acro5piano
acro5piano / main.sh
Last active July 1, 2024 16:40
Run android emulator on Arch Linux
# Pre installtion notice:
# - The iso image can be downloaed from: https://www.android-x86.org/download.html
# - Linux Zen is recommended. See: https://riq0h.jp/2020/12/07/210053/
# - Also see: https://wiki.archlinux.org/title/QEMU
sudo pacman -S qemu-full
sudo pacman -S qemu-desktop
qemu-img create -f raw android 16G
@acro5piano
acro5piano / readme.md
Created June 28, 2024 09:32
gqtx-like library idea
type ScalarField = 'ID' | 'String'

type ResolvableField<Out extends ObjectType<any>> = {
  type: Out
  resolve: () => Out extends ObjectType<infer Src> ? Src : never
}

export class ObjectType<Src> {
  constructor(public name: string) {}
@acro5piano
acro5piano / main.rs
Created April 11, 2024 10:03
rust server sent event (EventSource) client with infinite reconnect loop
use anyhow::Result;
use eventsource_client::{Client, ReconnectOptions, SSE};
use futures::TryStreamExt;
use std::time::Duration;
const URL: &str = "http://localhost:8000/sse";
#[tokio::main]
async fn main() -> Result<()> {
let client = eventsource_client::ClientBuilder::for_url(URL)?
@acro5piano
acro5piano / readme.md
Last active August 30, 2024 15:27
Arch linux full system upgrade without bluez

Newer bluez is buggy. It makes CPU usage 100% randomly.

5.72 is working fine. Let's keep using it.

sudo pacman -U /var/cache/pacman/pkg/bluez*5.72-2-x86_64.pkg.tar.zst

I need to ignore upgrading bluez until a stable version is released. To do so,

@acro5piano
acro5piano / cloudfront-function.js
Created August 26, 2023 05:28
cloudfront function for static sites
function handler(event) {
var request = event.request
var uri = request.uri
// Check whether the URI is missing a file name.
if (uri.endsWith('/')) {
return {
statusCode: 301,
statusDescription: 'Moved Permanently',
headers: {
@acro5piano
acro5piano / gist:1b1551b547bd7f00a528557f23d22af4
Created August 14, 2023 14:27
マネーフォワードクラウド会計の仕訳画面で、高さ制限なくして快適に入力できるようになる CSS
.caClientJournalBookSpreadsheetAppRoot {
max-height: unset !important;
}