Skip to content

Instantly share code, notes, and snippets.

View zentrope's full-sized avatar

Keith Irwin zentrope

  • Portland, Oregon
View GitHub Profile
@zentrope
zentrope / sema.swift
Last active January 19, 2020 04:34
Use a semaphore to block
func xmlDocument(url: String) -> Document? {
var doc: Document?
let semaphore = DispatchSemaphore(value: 0)
AF.request(url).response { response in
if let data = response.data, let xml = String(data: data, encoding: .utf8) {
do {
doc = try SwiftSoup.parse(xml, "", Parser.xmlParser())
} catch {
print("error: \(error.localizedDescription)")
@zentrope
zentrope / OverlapViewController.swift
Created August 25, 2019 18:58
Overlapping views in a view controller
override func loadView() {
let view = NSView(frame: .zero)
view.addSubview(vfxView)
view.addSubview(webView)
vfxView.translatesAutoresizingMaskIntoConstraints = false
webView.configuration.preferences.javaScriptEnabled = true
webView.setValue(false, forKey: "drawsBackground")
@zentrope
zentrope / AppDelegate.swift
Last active June 19, 2019 19:08
Open a window programmatically
//
// AppDelegate.swift
//
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
private var preferencesWindow = NSWindowController()
@zentrope
zentrope / webviewInject.swift
Last active December 23, 2018 21:44
Set dark/light for web content
private func setMode(_ isDark: Bool) {
let mode = isDark ? "add" : "remove"
let script = "document.body.classList.\(mode)(\"dark\");"
webView.evaluateJavaScript(script) { result, error in
if let err = error {
os_log("%{public}s", log: logger, type: .error, "js error: \(err).")
}
}
}
@zentrope
zentrope / buildemacs.md
Last active June 10, 2018 03:04
Build emacs on macOS

Build emacs on macOS

Build from scratch because most of the packages you use have updated to the nearly-completed next version, so why not pull that?

An alternative is to use home brew HEAD, but this is more fun.

Xcode

Probably should have Xcode installed, but at least try:

@zentrope
zentrope / number-format.cljs
Created December 22, 2016 03:07
A comma for thousands separator in Clojurescript using goog closure libs.
(ns client.ui
(:require
[goog.i18n.NumberFormat.Format])
(:import
(goog.i18n NumberFormat)
(goog.i18n.NumberFormat Format)))
(def nff
(NumberFormat. Format/DECIMAL))
@zentrope
zentrope / utils.clj
Last active April 22, 2016 07:23
Find out the jar you're running in: Clojure
(ns engine.lib.utils
(:require
[clojure.string :as s]
[clojure.java.io :as io]))
;;-----------------------------------------------------------------------------
(def ^:private path-sep
(System/getProperty "path.separator"))
@zentrope
zentrope / pingweb.go
Last active April 18, 2016 04:53
ping web
package main
import (
"encoding/json"
"io"
"log"
"net/http"
"os"
"os/signal"
)
@zentrope
zentrope / core.clj
Created January 21, 2016 17:49
core.logic scratch
(ns ls.core
(:gen-class)
(:refer-clojure :exclude [==])
(:require [clojure.core.logic :refer :all]
[clojure.core.logic.pldb :refer :all]))
;;-----------------------------------------------------------------------------
;; Interesting Links
;;
;; http://michaelrbernste.in/2013/05/12/featurec-and-maps.html
@zentrope
zentrope / clojars.txt
Created December 19, 2015 20:01
Clojars access forbidden, yet jars are there?
> lein deploy clojars
Created /Users/keith/Desktop/quiescent/target/quiescent-0.2.2.jar
Wrote /Users/keith/Desktop/quiescent/pom.xml
You need a passphrase to unlock the secret key for
user: "Keith Irwin <keith@zentrope.com>"
2048-bit RSA key, ID B0FDA7A9, created 2015-12-19
You need a passphrase to unlock the secret key for