Skip to content

Instantly share code, notes, and snippets.

View niw's full-sized avatar
🐱
Meow

Yoshimasa Niwa niw

🐱
Meow
  • San Francisco, CA
  • X @niw
View GitHub Profile
@niw
niw / main.swift
Last active November 29, 2023 05:28
Texting line height on NSTextView with TextKit 2
import AppKit
import Foundation
final class MainView: NSView {
private let textView: NSTextView
override init(frame frameRect: NSRect) {
textView = NSTextView(usingTextLayoutManager: true)
super.init(frame: frameRect)
@niw
niw / test.py
Last active August 27, 2023 13:26
Use CodeLlama on macOS with MPS quickly
# Usage
# =====
#
# ## Prerequisite
#
# Prepare Python 3, for exmaple, install Homebrew and `brew install python`.
#
# ## Install dependencies
#
# $ python3 -m venv .venv
@niw
niw / main.swift
Created July 13, 2023 06:29
Simple parser combinator, lexer, paresr and evaluator for double value math for simple logic configuration
import Foundation
extension String: Error {}
// MARK: - Parser Combinator
typealias ParserFunction<Element, Output> =
(any Collection<Element>) throws -> (Output, any Collection<Element>)
protocol Parser<Element, Output> {
@niw
niw / main.swift
Created July 12, 2023 04:15
Tiny SExpr Interpretor
import Foundation
extension String: Error {}
// MARK: - Evaluation
enum Atom {
case symbol(String)
case number(Double)
}
@niw
niw / a.m
Created July 7, 2023 09:23
A parser for the visual format string
@import AppKit;
@import Foundation;
#include <stdio.h>
int main(int argc, char *argv[]) {
@try {
if (argc < 2) {
printf("Usage: %s [visual format for a 'view']\n", argv[0]);
return 0;
@niw
niw / opencalm-7b-peft-lora.ipynb
Created May 21, 2023 03:23
OpenCALM-7B を PEFT を使って LoRA でファインチューンする.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@niw
niw / main.swift
Last active April 25, 2023 05:39
A problemtic code
// With Swift 5.8, it crashes on runtime due to reference count problem.
// With Swift 5.9-dev (LLVM d59f7189924eff9, Swift 12f2c2eb92c4c6a), today's nightly, it crashes due to an assertion.
class Box<T> {
private var value: T
init(_ value: T) {
self.value = value
}
@niw
niw / __tpad_act.plist
Created March 5, 2023 00:58
MultitouchSupport __TEXT __tpad_act_plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Version</key>
<integer>2</integer>
<key>Actuator_1</key>
<array>
<dict>
<key>ActuationID</key>
sudo launchctl list | grep CoreSimu | awk '{print $3}' | xargs -n1 sudo launchctl remove; \
launchctl list | grep CoreSimu | awk '{print $3}' | xargs -n 1 launchctl remove; \
sleep 5; \
ps auxww | grep -i '[c]oresimu'
@niw
niw / Gateron_Low_Profile_Socket.kicad_mod
Last active January 11, 2024 00:26
KiCad footprint for Gateron Low Profile socket
(footprint "Gateron_Low_Profile_Socket" (version 20211014) (generator pcbnew)
(layer "F.Cu")
(tedit 5E123764)
(descr "Hot Swap Socket for Gateron Low Profile Switch")
(attr smd)
(fp_text reference "REF**" (at 0 9.5) (layer "B.SilkS")
(effects (font (size 1 1) (thickness 0.15)) (justify mirror))
(tstamp 1b4a9a9f-50fb-40ce-9b05-77578a9b9c54)
)
(fp_text value "Gateron_Low_Profile_Socket" (at 0 8.5) (layer "F.Fab")