Skip to content

Instantly share code, notes, and snippets.

View zentrope's full-sized avatar

Keith Irwin zentrope

  • Portland, Oregon
View GitHub Profile
(def (do-post)
(http-post "http://localhost:9515/session"
headers: '(("Content-Type" . "application/json; charset=utf-8")
("Accept-Encoding" . "identity")
("Accept" . "*/*"))
data: (json-object->string capabilities)))
(def (get-session)
(let (req (do-post))
(for-each (lambda (h) (printf "~s~%" h)) (request-headers req))
(define (http:resolve url)
(define resolved-url
(make-parameter (uri-reference url)))
(define (update-resolved-url r)
(resolved-url (request-uri r))
(default-prepare-request r))
(parameterize ((prepare-request update-resolved-url))
(define (http:resolve url)
(max-redirect-depth 0)
(let* ((uri (uri-reference url))
(request (make-request uri: uri headers: basic-headers)))
(display "calling\n")
(handle-exceptions exn
(lambda (exn)
@zentrope
zentrope / drafts-to-oo.js
Last active March 21, 2020 16:01
Drafts to OO
let blurb = { "text": "", "date": "", "link": "", "title": "" }
const isValidDate = (d) => d instanceof Date && !isNaN(d)
draft.content.split("\n").forEach((text) => {
const line = text.trim()
if (line.startsWith("text:")) {
blurb.text = line.replace("text:", "").trim()
if (blurb.text.trim() == "") {
override func splitView(_ splitView: NSSplitView, additionalEffectiveRectOfDividerAt dividerIndex: Int) -> NSRect {
super.splitView(splitView, additionalEffectiveRectOfDividerAt: dividerIndex)
assert(splitViewItems.count == 2)
if splitViewItems.count != 2 { return .zero }
if !splitViewItems[1].isCollapsed { return .zero }
return NSMakeRect(splitView.bounds.maxX-6, 0, 6, splitView.bounds.height)
}
private func handleMessage(_ message: IRC.Message) {
if let storage = chatTextView.textStorage,
let render = format(message) {
storage.append(render)
//storage.insert(render, at: storage.length)
}
chatTextView.scrollToEndOfDocument(self)
}
private let chatFont = NSFont.systemFont(ofSize: 14)
import Cocoa
class ActivityManager {
var activityUpdate: NSBackgroundActivityScheduler?
var serialize = DispatchQueue(label: "sync", qos: .background)
func backgroundActivitiesSetup() {
print("Setting up activity runner.")
activityUpdate = NSBackgroundActivityScheduler(identifier: "…")
var activityUpdate: NSBackgroundActivityScheduler?
func backgroundActivitiesSetup() {
activityUpdate = NSBackgroundActivityScheduler(identifier: "…")
activityUpdate?.interval = 1 * 60 // every 1 minute
activityUpdate?.repeats = true
activityUpdate?.schedule { completion in
updateNewItems(completion)
}
}
var activity: NSBackgroundActivityScheduler?
func runActivity() {
activity = NSBackgroundActivityScheduler(identifier: "lkasjdlaksjdaslkjd")
activity?.repeats = true
activity?.interval = 15
activity?.schedule { completion in
// This doesn't make sense: defer should be periodically checked in
// the middle of a long job.