Skip to content

Instantly share code, notes, and snippets.

@scrogson
scrogson / playground.rs
Created May 16, 2020 21:13 — forked from anonymous/playground.rs
Shared via Rust Playground
#[macro_use]
extern crate hyper;
extern crate reqwest;
use reqwest;
use std::io::Read;
header! { (ContentType, "Content-Type") => [String] }
header! { (ContentLength, "Content-Length") => [usize] }
FROM node:12.2-slim as assets
WORKDIR /app/assets
COPY assets/package*.json ./
RUN npm install
# Copy the entire app so we can put files into /app/priv/static
COPY . /app
// 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
defmodule MyApp.CommentView do
use MyApp.Web, :view
@attributes ~W(id name inserted_at)
def render("index.json", %{data: comments}) do
for comment <- comments, do: render("show.json", %{data: comment})
end
def render("show.json", %{data: comment}) do
comment