Skip to content

Instantly share code, notes, and snippets.

Keith Irwin zentrope

Block or report user

Report or block zentrope

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
zentrope / sema.swift
Last active Jan 19, 2020
Use a semaphore to block
View sema.swift
func xmlDocument(url: String) -> Document? {
var doc: Document?
let semaphore = DispatchSemaphore(value: 0)
AF.request(url).response { response in
if let data =, let xml = String(data: data, encoding: .utf8) {
do {
doc = try SwiftSoup.parse(xml, "", Parser.xmlParser())
} catch {
print("error: \(error.localizedDescription)")
zentrope / OverlapViewController.swift
Created Aug 25, 2019
Overlapping views in a view controller
View OverlapViewController.swift
override func loadView() {
let view = NSView(frame: .zero)
vfxView.translatesAutoresizingMaskIntoConstraints = false
webView.configuration.preferences.javaScriptEnabled = true
webView.setValue(false, forKey: "drawsBackground")
zentrope / offscreen.js
Created Jan 18, 2015
three.js detect off-screen objects?
View offscreen.js
var frustum = new THREE.Frustum();
var cameraViewProjectionMatrix = new THREE.Matrix4();
// every time the camera or objects change position (or every frame)
camera.updateMatrixWorld(); // make sure the camera matrix is updated
camera.matrixWorldInverse.getInverse( camera.matrixWorld );
cameraViewProjectionMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
frustum.setFromMatrix( cameraViewProjectionMatrix );
zentrope / grib2-local.scala
Created Jun 27, 2011
Fragment: decoding weather strings in a grib2 file
View grib2-local.scala
// convert a byte into a list of ones and zeros
def bits(num: Int): List[Int] = (for (i <- Range(0,8)) yield (((num << i) & 0xff) >>> 7)).toList
// given a list, take the first N bits
def next(bits: List[Int], numBits: Int) = {
val filler = List[Int](8 - numBits) map (_ => 0)
val bitList = filler ++ bits.take(numBits)
zentrope / AppDelegate.swift
Last active Jun 19, 2019
Open a window programmatically
View AppDelegate.swift
// AppDelegate.swift
import Cocoa
class AppDelegate: NSObject, NSApplicationDelegate {
private var preferencesWindow = NSWindowController()
zentrope / webviewInject.swift
Last active Dec 23, 2018
Set dark/light for web content
View webviewInject.swift
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 / number-format.cljs
Created Dec 22, 2016
A comma for thousands separator in Clojurescript using goog closure libs.
View number-format.cljs
(ns client.ui
(goog.i18n NumberFormat)
(goog.i18n.NumberFormat Format)))
(def nff
(NumberFormat. Format/DECIMAL))
zentrope /
Last active Jun 10, 2018
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.


Probably should have Xcode installed, but at least try:

zentrope / transform.scala
Created Dec 4, 2010
Transforming XML using RewriteRule and RuleTransformer
View transform.scala
// Import the magic libraries
import scala.xml._
import scala.xml.transform._
// Source xml. In Scala, xml is literal.
val xml =
zentrope / core.clj
Created Jan 21, 2016
core.logic scratch
View core.clj
(ns ls.core
(:refer-clojure :exclude [==])
(:require [clojure.core.logic :refer :all]
[clojure.core.logic.pldb :refer :all]))
;; Interesting Links
You can’t perform that action at this time.