Skip to content

Instantly share code, notes, and snippets.

👻
A ghost

Nathan myobie

👻
A ghost
Block or report user

Report or block myobie

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
@myobie
myobie / timer.swift
Created Feb 17, 2020
GCD Timer using DispatchSourceTimer that is much simpler
View timer.swift
import Foundation
class Timer {
private let source: DispatchSourceTimer
private let block: () -> ()
public let isRepeating: Bool
init(_ interval: DispatchTimeInterval, repeat shouldRepeat: Bool = false, block: @escaping () -> ()) {
self.source = DispatchSource.makeTimerSource()
@myobie
myobie / timer.swift
Last active Feb 15, 2020
GCD Timer using DispatchSourceTimer
View timer.swift
import Cocoa
import Combine
class Timer: Cancellable, Publisher {
enum Error: Swift.Error {
case cancelled
}
typealias Output = Never
typealias Failure = Error
@myobie
myobie / fig-shortcode.html
Created Nov 21, 2019
A shortcode for Hugo to render a figure + img supporting 2x and 3x images automatically from the filename (max size is hard coded as 1200px)
View fig-shortcode.html
{{- $original := .Page.Resources.GetMatch (printf "*%s*" (.Get "src")) -}}
{{- if findRE ".*@2x*." $original.Name -}}
{{- .Scratch.Set "image" ($original.Fit "2400x2400 q40") -}}
{{- else if findRE ".*@3x*." $original.Name -}}
{{- .Scratch.Set "image" ($original.Fit "3600x3600 q40") -}}
{{- else -}}
{{- .Scratch.Set "image" ($original.Fit "1200x1200 q55") -}}
{{- end -}}
@myobie
myobie / now.yml
Last active Jan 7, 2020
Zeit's now preview and prod deploy Actions Workflow – emulates how Zeit's Now GitHub integration works, but is even better because it forces a rebuild even if the source code hasn't changed
View now.yml
name: now
on:
push:
jobs:
deploy-prod:
name: Deploy prod
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
@myobie
myobie / _zeit_now_plus_hugo
Last active Nov 13, 2019
Zeit Now + Hugo current best setup
View crap.js
const hyperx = require('hyperx')
const hx = hyperx((componentName, properties, children) => {
return ['createElement', componentName, properties, children]
}, (children) => {
return ['createFragment', children]
})
class Header {
async fetch (ctx) {
@myobie
myobie / colorize.js
Last active Aug 2, 2019
How the color changing works on nathanherald.com
View colorize.js
function sorter () { return 0.5 - Math.random() }
var styles = [ 'blaze', 'sunshine', 'dusk', 'blood', 'puce' ]
function colorize () {
var style = styles.sort(sorter)[0]
document.body.className = style
}
colorize()
setInterval(colorize, 10000)
@myobie
myobie / URLAppendingQueryItems.swift
Created Jul 17, 2019
Append query items just as easily as path components
View URLAppendingQueryItems.swift
extension URL {
func appendingQueryItems(_ items: [String: String]) -> URL {
guard var components = URLComponents(url: self, resolvingAgainstBaseURL: false) else {
fatalError()
}
var query = components.queryItems ?? []
items.forEach { (name, value) in
query.append(URLQueryItem(name: name, value: value))
@myobie
myobie / ExampleSimplePublisher.swift
Last active Jul 17, 2019
Make any class a super simple publisher with publish() and complete() functions
View ExampleSimplePublisher.swift
class Names: SimplePublisher {
typealias Output = Result<String, Error>
var subscriptions = [SimpleSubscription<Output, Failure>]()
let names = ["Alice", "Bob", "Claris", "Doug"]
shoutName() {
if let name = names.randomElement() {
publish(.success(name))
} else {
assertionFailure("There are def some names in there...")
You can’t perform that action at this time.