Skip to content

Instantly share code, notes, and snippets.

@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)
}
@myobie
myobie / embed.html
Last active Jul 10, 2018
Embed things into the markdown content of a hugo site
View embed.html
<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 }}
View document.js
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'] }),
View port_server.ex
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")},
@myobie
myobie / authorization_request.ex
Created Apr 5, 2018
A simplified example of storing an authorization request for an openeid connect valid code flow request
View authorization_request.ex
defmodule App.AuthorizationRequest do
use Ecto.Schema
schema "authorization_requests" do
field(:client_id, :string)
field(:code, :string)
field(:nonce, :string)
field(:access_token, :string)
field(:refresh_token, :string)
field(:scope, :string)
@myobie
myobie / example_to_download_file.ex
Created Apr 3, 2018
Send a file in phoenix (plug)
View example_to_download_file.ex
defmodule AppWeb.Controller do
use AppWeb, :controller
# sending bytes
def show(conn, %{"id" => id}) do
data = Storage.get_data_for_file_id(id)
conn
|> put_resp_header(
"content-disposition",
You can’t perform that action at this time.