Skip to content

Instantly share code, notes, and snippets.

View sahrizvi's full-sized avatar
🌴
On vacation

Haider sahrizvi

🌴
On vacation
View GitHub Profile
@sahrizvi
sahrizvi / keybase.md
Created May 24, 2019 11:01
keybase.md

Keybase proof

I hereby claim:

  • I am sahrizvi on github.
  • I am sahrizvi (https://keybase.io/sahrizvi) on keybase.
  • I have a public key ASCd1-KMrcuNu3PU5b8CVlf4D05JQwP-d1oESZMuT-NSeQo

To claim this, I am signing this object:

@sahrizvi
sahrizvi / postgres-cheatsheet.md
Created August 3, 2017 13:37 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

If run with -E flag, it will describe the underlaying queries of the \ commands (cool for learning!).

Most \d commands support additional param of __schema__.name__ and accept wildcards like *.*

#!/usr/bin/env elixir
defmodule Committer do
defstruct [:name, :email]
def list(repo) do
repo
|> from_repo
|> Stream.unfold(fn str ->
case String.split(str, "\n", parts: 2, trim: true) do
@sahrizvi
sahrizvi / janus-libs-build.sh
Last active May 21, 2017 13:15
Use BoringSSL and updated versions of libwebsockets, libsrtp and janus.
#!/bin/sh
set -eu
JANUS_REV=tags/v0.2.2 #master
CONTAINER=false # if true, delete more for smaller image
JANUS_REPO=meetecho/janus-gateway
PREFIX=/opt/janus-gateway
SRCDIR=$HOME/src
defmodule Persistence.Merchant do
@moduledoc """
"""
use Persistence.Definition, :service
alias Persistence.Account.User
alias Persistence.Merchant.Shop
alias Persistence.Relation.ShopUser
def create(:shop, params, %User{} = user) when is_map(params) do
@sahrizvi
sahrizvi / domain-driven-desire-resources.md
Created December 14, 2016 06:20 — forked from somebox/domain-driven-desire-resources.md
Domain-Driven Desire: Further Reading

Domain-Driven Desire: The Talk from Øredev 2016

🎥 https://vimeo.com/191051851

Links and References

Thanks for watching my talk, Domain-Driven Desire at Øredev 2016. Here's a list of resources that inspired me, and will hopefully inspire you:

Videos

@sahrizvi
sahrizvi / socket_loop.ex
Created September 23, 2016 15:39 — forked from sorentwo/socket_loop.ex
Listen and loop with elixir socket
def loop(socket) do
case socket |> Socket.Web.recv! do
{:text, data} ->
# process data
loop(socket)
{:ping, _ } ->
socket |> Socket.Web.send!({:pong, ""})
end
end
Thanks to @potatosalad for his comment explaning this
Short Answer
A cryptographically secure randomly generated 16 byte (or 128 bit) symmetric oct key for use with signature algorithm HS256 should be sufficient for many HTTP bearer authentication use cases.
## Generate a 128-bit oct JWK
JOSE.JWK.generate_key({:oct, 16}) |> JOSE.JWK.to_map |> elem(1)
# %{"k" => "5Fn8i7r5cRWZW_yyr9Flkg", "kty" => "oct"}
## Configure Guardian to use HS256 and our generated JWK
# within channel
def handle_in("new_msg", %{"uid" => uid, "body" => body}, socket) do
...
broadcast_from! socket, "new_msg", %{uid: uid, body: body}
MyApp.Endpoint.broadcast_from! self(), "rooms:superadmin",
"new_msg", %{uid: uid, body: body}
{:noreply, socket}
end
# within controller