Skip to content

Instantly share code, notes, and snippets.

View espresso3389's full-sized avatar

Takashi Kawasaki espresso3389

View GitHub Profile
@espresso3389
espresso3389 / winrt_formatters.h
Created December 9, 2024 03:08
C++23 std::formatter implementations for WinRT classes
#ifndef WINRT_FORMATTERS_H
#define WINRT_FORMATTERS_H
#include <windows.h>
#include <winrt/base.h>
#include <string>
#include <format>
@espresso3389
espresso3389 / html_image_embed.js
Created October 1, 2024 16:06
Node.js program that converts HTML with img files to a single HTML that uses embedded image data using data protocol
const fs = require('fs').promises;
const path = require('path');
const cheerio = require('cheerio');
const sharp = require('sharp');
const zlib = require('zlib');
const util = require('util');
const gzip = util.promisify(zlib.gzip);
async function optimizeAndConvertToDataURI(imagePath, baseDir, useLossless) {
@espresso3389
espresso3389 / pwsh.ps1
Last active May 18, 2026 08:12
A PowerShell script (for Windows), that updates the environment variables; not only the process but the user's environment variables
$envs = @{
#"CHROME_EXECUTABLE" = "%ProgramFiles%\Google\Chrome Dev\Application\chrome.exe"
"PACKAGES_ROOT" = "D:\.packages"
"PUB_CACHE" = "%PACKAGES_ROOT%\pub"
"npm_config_cache" = "%PACKAGES_ROOT%\npm"
"NUGET_PACKAGES" = "%PACKAGES_ROOT%\nuget"
"BUN_INSTALL_CACHE_DIR" = "%PACKAGES_ROOT%\bun\install\cache"
"VCPKG_DEFAULT_BINARY_CACHE" = "%PACKAGES_ROOT%\vcpkg"
"PIP_CACHE_DIR" = "%PACKAGES_ROOT%\pip"
"GRADLE_USER_HOME" = "%PACKAGES_ROOT%\.gradle"
@espresso3389
espresso3389 / flutter-build-env.ps1
Last active February 2, 2024 12:21
Create Flutter Android build environment on Windows
# Need to enable scripting before executing the file
# Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
cd ~
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
scoop install git
scoop bucket add java
@espresso3389
espresso3389 / nfkc.dart
Last active October 30, 2023 08:23
Using icu from Dart/Flutter
import 'dart:ffi';
import 'dart:io';
import 'package:ffi/ffi.dart';
import 'package:unorm_dart/unorm_dart.dart' as unorm_dart; // fallback
String _getLibicuModuleName() {
if (Platform.isAndroid) {
return 'libicu.so';
} else if (Platform.isWindows) {
@espresso3389
espresso3389 / wsl2-rootless-docker.md
Last active January 23, 2026 06:27
WSL2 configuration for developing using rootless docker

NOTE: WORK IN PROGRESS

WSL2 configuration for developing using rootless docker

This document assumes Windows Insider Preview Dev.

Install Ubuntu 22.04

Installing Ubuntu 22.04.1 LTS from Microsoft Store.

@espresso3389
espresso3389 / flutter-#93615.dart
Created November 19, 2021 07:28
Sample repro for flutter #93615
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@espresso3389
espresso3389 / flutter-ffi-async-nativeport.md
Last active August 12, 2025 01:48
Async messaging between Flutter and C++ using Dart ffi NativePort

C++

  • Copy Dart SDK (${FLUTTER_DIR}/bin/cache/dart-sdk/include) to your project, e.g. ios/Classes/
  • Add your own code like the following fragment
#include "dart_api_dl.h"

// Receives NativePort ID from Flutter code
static Dart_Port_DL dart_port = 0;
void main() {
print('''Multiline
String
can be
directly embedded on the code!''');
}

M5Stack Motor Module/Cable

PIN Cable Color RJ12 PIN Description
M+ Black 2 motor +
G Green 4 encoder Vcc (3.3V - 5V)
A Yellow 5 encoder A
B Blue 6 encoder B
V Red 3 encoder GND
1 White 1 motor -