Skip to content

Instantly share code, notes, and snippets.

View CamelCafeRider's full-sized avatar
💭
Beautiful APIs

Camel Rider CamelCafeRider

💭
Beautiful APIs
View GitHub Profile
@CamelCafeRider
CamelCafeRider / a-usage.md
Created August 9, 2025 16:01 — forked from t4sk/a-usage.md
gen_tcp and GenServer example in Elixir (1.5.2)

gen_tcp and GenServer example in Elixir (1.5.2)

Usage

server.ex

Server.start
@CamelCafeRider
CamelCafeRider / GoLang Build JSON with Structs Nested
Created December 28, 2022 08:15
GoLang Build JSON with Structs Nested
package main
import (
"fmt"
"encoding/json"
)
type A struct {
A string
}
@CamelCafeRider
CamelCafeRider / plug.conn.ex
Created July 19, 2022 17:23 — forked from jamonholmgren/plug.conn.ex
Typical Elixir Phoenix Plug.Conn struct contents, in an easy-to-read format. By Jamon Holmgren.
%Plug.Conn{
adapter: {Plug.Adapters.Cowboy.Conn, :...},
assigns: %{
my_assigns: "here"
},
before_send: [
#Function<7.125546534/1 in Phoenix.Controller.fetch_flash/2>,
#Function<1.127904613/1 in Plug.Session.before_send/2>,
#Function<1.43511252/1 in Plug.Logger.call/2>,
#Function<0.70322810/1 in Phoenix.LiveReloader.before_send_inject_reloader/1>
@CamelCafeRider
CamelCafeRider / Remoteip.ex
Created August 7, 2021 12:28
Get IP address in Elixir/Phoenix
defmodule RemoteIp do
def get(conn) do
forwarded_for = List.first(Plug.Conn.get_req_header(conn, "x-forwarded-for"))
if forwarded_for do
String.split(forwarded_for, ",")
|> Enum.map(&String.trim/1)
|> List.first()
else
to_string(:inet_parse.ntoa(conn.remote_ip))