Skip to content

Instantly share code, notes, and snippets.

@myobie
myobie / forever.swift
Last active July 7, 2019 12:57
Subscribers.Sink sucks, so this will receive forever until completion
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 June 1, 2019 16:19 — forked from kez/slugify.sql
Generating Slugs in Postgres
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 November 17, 2018 20:35
Always use heroku local (foreman) for the server
#!/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 October 10, 2018 21:17
Automatically build and digest assets for a phoenix application when building an elixir release with distillery
# rel/config.exs
# ...
environment :prod do
# ...
plugin(Example.Phoenix)
end
# ...
@myobie
myobie / timing.js
Created August 24, 2018 10:26
A nicer API for performance time measurements in the browser
export function create (name) {
const nameStart = `${name} start`
window.performance.mark(nameStart)
return {
log: () => { log(name) },
end: () => { end(name) }
}
}
@myobie
myobie / image.html
Created August 14, 2018 11:04
Image short tag that supports retina images, page resources, and falls back to plain urls for Hugo websites
{{- $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 August 2, 2018 15:28
This is an exploration into the "dream code" I wish I could write to make a quick single page app
// 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)
}
@myobie
myobie / embed.html
Last active July 10, 2018 17:16
Embed things into the markdown content of a hugo site
<div class="embed">
{{ $file := .Get "src" }}
{{ if fileExists $file }}
{{ if eq (.Get "markdown") "true" }}
{{ $file | readFile | markdownify }}
{{ else }}
{{ if or (eq (.Get "javascript") "true") (eq (.Get "js") "true") }}
<script>
{{ $file | readFile | safeJS }}
export const document = [
newBlock([
newPart('Hello world '),
newPart('**', { type: 'control', controlType: 'bold', styles: ['bold'] }),
newPart('hooray for ', { styles: ['bold', 'italic'] }),
newPart('_', { type: 'control', controlType: 'italic', styles: ['bold', 'italic'] }),
newPart('nested italic', { styles: ['bold', 'italic'] }),
newPart('_', { type: 'control', controlType: 'italic', styles: ['bold', 'italic'] }),
newPart(' text', { styles: ['bold'] }),
newPart('**', { type: 'control', controlType: 'bold', styles: ['bold'] }),
defmodule App.Thing do
use GenServer
def init(%{code: code}) do
Process.flag(:trap_exit, true)
handler = self()
{:ok, task} = Task.start_link(fn ->
port = Port.open(
{:spawn_executable, System.find_executable("npm")},