Skip to content

Instantly share code, notes, and snippets.

@scrogson
scrogson / assigns.rs
Created July 10, 2017 17:21
Assigns like Plug's conn.assigns - but type safe
use ::std::collections::HashMap;
use ::std::any::{TypeId, Any};
struct Assigns {
map: HashMap<TypeId, Box<Any>>,
}
trait AssignHandle {
type MapsTo;
}
@scrogson
scrogson / router.rs
Created July 8, 2017 21:54
Basic Rust HTTP Router
#![allow(dead_code)]
use std::collections::HashMap;
type Headers = HashMap<String, String>;
type BoxedCallback = Box<Fn(Conn) -> Conn>;
#[derive(Default)]
struct Request {
method: String,
url: String,
@scrogson
scrogson / main.go
Last active July 10, 2017 15:47
Fetch current on call users from Pager Duty for a given schedule_id
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"net/url"
"time"
@scrogson
scrogson / docs.publish.ex
Last active July 10, 2017 15:48
A Mix Task to Publish docs to GitHub Pages
defmodule Mix.Tasks.Docs.Publish do
use Mix.Task
@shortdoc "Publishes docs to GitHub Pages"
@moduledoc """
Publishes docs to GitHub Pages.
mix docs.publish [git-remote]
defp gen_jwk_set do
{:ok, pem} = genrsa(2048)
pem
|> JOSE.JWK.from_pem()
|> JOSE.JWK.to_public()
|> JOSE.JWK.to_record()
|> List.wrap()
|> :jose_jwk_set.to_map(%{})
|> Poison.encode()
// OK so to start with here's the EventHandler trait, just like slack-rs
pub trait EventHandler {
// I don't know what kind of thing EventData should be.
// maybe Json? whatever events actually are in phoenix.
fn on_event(&mut self, channel_name: &str, event_type: &str, event_data: EventData);
fn on_connect(&mut self, ...);
fn on_close(&mut self, ...);
}
fn login_and_run<H: EventHandler>(handler: H, ...) {...}
@scrogson
scrogson / README
Last active March 13, 2020 13:56 — forked from ciastek/README
Use bootstrap-sass npm package with Phoenix's brunch
1) install npm packages
2) update brunch-config.js
3) remove Bootstrap from web/static/css/app.css
4) rename web/static/css/app.css to web/static/css/app.scss
5) update web/static/css/app.scss
@scrogson
scrogson / observer.md
Created November 7, 2015 18:21 — forked from pnc/observer.md
Using Erlang observer/appmon remotely

Using OTP's observer (appmon replacement) remotely

$ ssh remote-host "epmd -names"
epmd: up and running on port 4369 with data:
name some_node at port 58769

Note the running on port for epmd itself and the port of the node you're interested in debugging. Reconnect to the remote host with these ports forwarded:

$ ssh -L 4369:localhost:4369 -L 58769:localhost:58769 remote-host
@scrogson
scrogson / simple_sup.ex
Created October 8, 2015 01:51 — forked from fishcakez/simple_sup.ex
Examples of supervision trees for `:simple_one_for_one` supervisors
defmodule SimpleSup do
@moduledoc """
This file shows methods for starting a configurable number of children under
a `:simple_one_for_one` supervisor.
When the supervision tree is first started all methods behave the same, `size`
children are started and the `:starter` returns `:ignore`. However if the
restart limit for those children is reached the `:simple_one_for_one`
supervisor will be restarted and then the `:starter`. It is possible that the
`:simple_one_for_one` is restarted successfully but the `:starter` fails to
;;; init.el ---
;;; Commentary:
;;
;;; Code:
(package-initialize)
(require 'cask "/usr/local/share/emacs/site-lisp/cask.el")