Skip to content

Instantly share code, notes, and snippets.

View banjun's full-sized avatar

banjun banjun

View GitHub Profile
// inspection whether repdocuces or not, SR-2750
// devxoul/Then a.k.a. `.then`
// banjun/ikemen a.k.a. `※`
func testWithTypeAnnotation() {
let user = User().then {
$0. // success completion
}
}
@banjun
banjun / WindowCapture.swift
Last active January 31, 2024 18:44
specific window capture implementation memo for https://github.com/mzp/HeartVoice
import Cocoa
import CoreGraphics
import Vision
struct TargetWindow {
let id: CGWindowID
let bounds: CGRect
init?(appName: String, windowTitle: String) {
guard let windows = CGWindowListCopyWindowInfo(.optionAll, kCGNullWindowID) as? [[String: Any]] else { return nil }
import Cocoa
class ViewController: NSViewController {
let model = NSMutableDictionary()
private(set) lazy var controller: NSObjectController = .init(content: model)
let textView1 = NSTextView()
let textView2 = NSTextView()
override func viewDidLoad() {
super.viewDidLoad()
@banjun
banjun / プリパラDB(仮)用ショートカット.md
Last active September 24, 2018 12:40
プリパラDB(仮)用ショートカット
final class FakeFirebaseInstanceID: NSObject {
@objc class func instanceID() -> FakeFirebaseInstanceID? { return nil }
static private let once: Void = {
method_exchangeImplementations(
class_getClassMethod(NSClassFromString("FIRInstanceID"), #selector(FakeFirebaseInstanceID.instanceID))!,
class_getClassMethod(FakeFirebaseInstanceID.self, #selector(FakeFirebaseInstanceID.instanceID))!)
}()
static func silenceFirebaseCheckin() {
@banjun
banjun / im@sparql-playground.swift
Created December 23, 2018 06:41
im@sparql playground
import Foundation
var str = "Hello, playground"
enum RDFT {
case iri(IRI)
case rdfl(RDFL)
// case rdfb(RDFB)
}
@banjun
banjun / beaconcapture.swift
Created January 24, 2019 05:35
Capture iBeacon packets and show them in Touch Bar
#!/usr/bin/swift
import CoreBluetooth
import AppKit
class AppDelegate: NSResponder, CBCentralManagerDelegate, NSTouchBarDelegate, NSApplicationDelegate {
let manager: CBCentralManager
var advertises: [Advertise] = []
override init() {
manager = CBCentralManager(delegate: nil, queue: DispatchQueue.main)
@banjun
banjun / MediaLibraryAccess.swift
Created May 1, 2019 09:39
macOS screenshots Photos access via MLMediaLibrary
import Cocoa
import MediaLibrary
/// requires NSPhotoLibraryUsageDescription in info.plist
/// requires Pictures access in sandbox settings
final class PhotoSource: NSObject {
let photosLibrary = MLMediaLibrary(options: [
MLMediaLoadSourceTypesKey: MLMediaSourceType.image.rawValue,
MLMediaLoadIncludeSourcesKey: [MLMediaSourcePhotosIdentifier],
MLMediaLoadExcludeSourcesKey: [MLMediaSourcePhotoBoothIdentifier],
@banjun
banjun / generate-prismdb-characters.jisyo.md
Created December 28, 2019 10:33
generate-prismdb-characters.jisyo.md

oneliner

curl 'https://prismdb.takanakahiko.me/sparql?default-graph-uri=&query=PREFIX+prism%3A+%3Chttps%3A%2F%2Fprismdb.takanakahiko.me%2Fprism-schema.ttl%23%3E%0D%0A%0D%0ASELECT+concat%28%22%5Cn%3B%3B+okuri-ari+entries.%5Cn%3B%3B+okuri-nasi+entries.%5Cn%5Cn%22%2C%0D%0Agroup_concat%28concat%28replace%28%3Fckana%2C+%22+%22%2C+%22%22%29%2C+%22+%2F%22%2C+replace%28%3Fcname%2C+%22+%22%2C+%22%22%29%2C+%22%3B%22%2C+%3Fcclass%2C+if%28bound%28%3Fccv%29%2C+concat%28%22+CV%3A%22%2C+%3Fccv%29%2C+%22%22%29%2C+%22%2F%22%29%3B+separator%3D%22%5Cn%22%29%29%0D%0AWHERE+%7B%0D%0A++++%3Fc+a+prism%3ACharacter%3B%0D%0A++++++++prism%3Aname+%3Fcname%3B%0D%0A++++++++prism%3Aname_kana+%3Fckana%3B%0D%0A++++++++a%2Frdfs%3Alabel+%3Fcclass.%0D%0A++++optional+%7B%3Fc+prism%3Acv+%3Fccv.%7D%0D%0A++++bind%28%22%22+as+%3Fg%29%0D%0A%7D%0D%0Agroup+by+%3Fg&format=text%2Fcsv' | tail +3 | LC_ALL=C sort > prismdb-characters.jisyo

SPARQL

@banjun
banjun / sample.rq
Last active January 2, 2020 07:03 — forked from takanakahiko/sample.rq
そらみスマイルのライブ一覧
PREFIX prism: <https://prismdb.takanakahiko.me/prism-schema.ttl#>
SELECT ?n ?st ?title
WHERE {
?live a prism:Live;
prism:performer/prism:name_kana "そらみすまいる";
prism:songPerformed/prism:name ?title;
prism:liveOfEpisode ?ep.
?ep a prism:Episode;
prism:話数 ?n;