Skip to content

Instantly share code, notes, and snippets.

View banjun's full-sized avatar

banjun banjun

View GitHub Profile
@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)
}
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 / プリパラDB(仮)用ショートカット.md
Last active September 24, 2018 12:40
プリパラDB(仮)用ショートカット
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 / 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 }
// 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 / SignalProducerFromFuture.swift
Created February 21, 2018 00:57
create SignalProducer that create Future with the autoclosure on start and send a result to the inner observer
extension SignalProducer {
// create SignalProducer that create Future with the autoclosure on start and send a result to the inner observer
init(_ future: @escaping @autoclosure () -> Future<Value, Error>) {
self.init { observer, _ in
future()
.onSuccess {
observer.send(value: $0)
observer.sendCompleted()}
.onFailure {
observer.send(error: $0)}

Keybase proof

I hereby claim:

  • I am banjun on github.
  • I am banjun (https://keybase.io/banjun) on keybase.
  • I have a public key ASCKLh62-ATKJawCqVs88yAl7RXvjVxgeGpW0T1LsZnF8Ao

To claim this, I am signing this object:

@banjun
banjun / ViewController.swift
Created November 3, 2017 03:43
list AVCaptureDevice including iOSScreenCaptureAssistant
import Cocoa
import CoreMediaIO
import AVFoundation
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
var prop = CMIOObjectPropertyAddress(
mSelector: CMIOObjectPropertySelector(kCMIOHardwarePropertyAllowScreenCaptureDevices),
@banjun
banjun / Xcode9TableViewControllerSubclass.swift
Created September 7, 2017 07:30
Xcode 9 beta 6 shows empty section headers & footers for nil value of viewForHeaderInSection. dirty workaround is required.
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
guard let v = self.tableView(tableView, viewForHeaderInSection: section) else { return 0 }
guard #available(iOS 11, *) else {
let h = v.bounds.height
return h > 0 ? h : UITableViewAutomaticDimension
}
return UITableViewAutomaticDimension // super call returns 0 on UITableViewController, though not overriding this cause behaviors like automatic.
}
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {