Skip to content

Instantly share code, notes, and snippets.

Nathan myobie

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 / 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...")
@myobie
myobie / forever.swift
Last active Jul 7, 2019
Subscribers.Sink sucks, so this will receive forever until completion
View forever.swift
import Foundation
import Combine
extension Subscribers {
final public class Forever<Upstream: Publisher>: Subscriber, Cancellable, CustomStringConvertible {
public typealias Input = Upstream.Output
public typealias Failure = Upstream.Failure
private var subscription: Subscription? = nil
private let receiveCompletion: (Subscribers.Completion<Failure>) -> Void
@myobie
myobie / slugify.sql
Created Jun 1, 2019 — forked from kez/slugify.sql
Generating Slugs in Postgres
View slugify.sql
CREATE EXTENSION IF NOT EXISTS "unaccent"
CREATE OR REPLACE FUNCTION slugify("value" TEXT)
RETURNS TEXT AS $$
-- removes accents (diacritic signs) from a given string --
WITH "unaccented" AS (
SELECT unaccent("value") AS "value"
),
-- lowercases the string
"lowercase" AS (
@myobie
myobie / server.sh
Created Nov 17, 2018
Always use heroku local (foreman) for the server
View server.sh
#!/bin/bash
which heroku > /dev/null
if [[ "$?" != "0" ]]; then
echo "You need to brew install heroku"
exit 1
fi
heroku local
@myobie
myobie / rel_config.exs
Last active Oct 10, 2018
Automatically build and digest assets for a phoenix application when building an elixir release with distillery
View rel_config.exs
# rel/config.exs
# ...
environment :prod do
# ...
plugin(Example.Phoenix)
end
# ...
@myobie
myobie / timing.js
Created Aug 24, 2018
A nicer API for performance time measurements in the browser
View timing.js
export function create (name) {
const nameStart = `${name} start`
window.performance.mark(nameStart)
return {
log: () => { log(name) },
end: () => { end(name) }
}
}
@myobie
myobie / image.html
Created Aug 14, 2018
Image short tag that supports retina images, page resources, and falls back to plain urls for Hugo websites
View image.html
{{- $src := .Get "src" }}
{{- $s := newScratch }}
{{- if eq (len (findRE "^/" $src)) 0 }}
{{- $s.Set "res" ($.Page.Resources.GetMatch $src) }}
{{- with ($s.Get "res") }}
{{- $s.Set "src" .Permalink }}
{{- if ne (len (findRE "@2x" .Permalink)) 0 }}
{{- $s.Set "width" (div .Width 2) }}
{{- $s.Set "height" (div .Height 2) }}
@myobie
myobie / actions.js
Created Aug 2, 2018
This is an exploration into the "dream code" I wish I could write to make a quick single page app
View actions.js
// Since es6 exports are statically validated, we have no need to use stringy
// programming to identify which action to run in response to which event
import { render } from 'some-lib'
export function increment ({ state, emit }) {
state.counter += 1
emit(render)
}
You can’t perform that action at this time.