Skip to content

Instantly share code, notes, and snippets.

View niw's full-sized avatar
🐱
Meow

Yoshimasa Niwa niw

🐱
Meow
View GitHub Profile
@niw
niw / 20260221.md
Last active February 22, 2026 16:58
Reverse Engineering an NFC Protocol

Reverse Engineering an NFC Protocol

Last week, I purchased a fun toy: a 4.2-inch e-Paper display that works without a battery and can be updated via an NFC wireless signal from a mobile app.

The problem, however, is the app. The manufacturer provides iOS, Android, and PC applications, but the UI is poorly designed and does not allow raw image uploads. Instead, images are always dithered by the app, which significantly reduces display quality.

So, I decided to reverse engineer the NFC protocol and re-implement the app — and that was completed in a day, with the help of an “AI agent.”

Beginning

@niw
niw / EPaperNFCProtocol-ja.md
Last active February 22, 2026 10:11
400x300 4-Color e-Paper NFC Protocol

NFC で書き換えられる電子ペーパーのプロトコル

いま巷で話題の NFC で書き換えできる名札サイズの電子ペーパーのプロトコルを調べました。 @alt-coreさんの追加の調査も参考にしています。

実装

@niw
niw / atkinson_dither.py
Created February 13, 2026 05:14
Applying Atkinson dithering with Red, Yellow, Black and White, mostly for EZSign.
#!/usr/bin/env python3
"""
Apply Atkinson dithering to an input PNG using a fixed 4-color palette:
red, yellow, black, and white.
"""
from __future__ import annotations
import argparse
from pathlib import Path
@niw
niw / README.md
Created November 6, 2025 05:47
Unsafe `Binding` access on SwiftUI

Unsafe Binding Access on SwiftUI

It’s not always safe to access a Binding within a callback that isn’t part of SwiftUI’s event system. An example is illustrated in the following sample code:

extension Notification.Name {
    static let event = Notification.Name("event")
}
@niw
niw / RunOnMainRunLoopExitScheduler.swift
Created November 5, 2025 23:53
A Combine Scheduler to delay on `exit` observer on main run loop.
//
// RunOnMainRunLoopExitScheduler.swift
// RunOnMainRunLoopExitScheduler
//
// Created by Yoshimasa Niwa on 11/5/25.
//
import Combine
import Foundation
@niw
niw / copy_to_documents.py
Last active October 14, 2025 16:22
Copy files to the "documents" folder by using MTP.
# Copy files to the "documents" folder by using MTP.
# Mostly for sending documents locally to recent Kindle devices.
#
# Usage: python3 copy_to_documents.py [file ...]
#
# Requires `aftl` package that can be installed from a non-master branch at
# <https://github.com/niw/android-file-transfer-linux>.
#
# Copyright (c) 2025 Yoshimasa Niwa
#
@niw
niw / Tuple.swift
Created August 16, 2025 11:52
A non-nominal, structual Tuple that conforms Equatable.
//
// Tuple.swift
// Tuple
//
// Created by Yoshimasa Niwa on 8/8/25.
//
public struct Tuple<each T: Equatable>: Equatable {
public static func == (lhs: Tuple<repeat each T>, rhs: Tuple<repeat each T>) -> Bool {
var result = true
#!/bin/bash
# Congratulations! You found the easter egg! ❤️
# おめでとうございます!隠されたサプライズを見つけました!❤️
# Define the text to animate
text="♥PEACE♥FOR♥ALL♥PEACE♥FOR♥ALL♥PEACE♥FOR♥ALL♥PEACE♥FOR♥ALL♥PEACE♥FOR♥ALL♥"
# Get terminal dimensions
cols=$(tput cols)
@niw
niw / UUIDv7.swift
Last active July 25, 2025 19:21
A simple UUIDv7 implementation in Swift.
//
// UUIDv7.swift
// UUIDv7
//
// Created by Yoshimasa Niwa on 7/25/25.
//
import Foundation
import Security
@niw
niw / SeverSentEvent.swift
Last active July 24, 2025 01:02
A simple Sever-Sent Event Client implementation on `URLSession`
import Foundation
public enum ChunkedDataTaskError: Swift.Error {
case notSuccess(_ data: Data, _ httpResponse: HTTPURLResponse)
}
private extension Int {
var isSuccess: Bool {
(200 ..< 300).contains(self)