Skip to content

Instantly share code, notes, and snippets.

View collegeimprovements's full-sized avatar
💭
☀️

Arpit Shah collegeimprovements

💭
☀️
View GitHub Profile
@collegeimprovements
collegeimprovements / python-mojave
Created December 9, 2018 15:33
python-mojave installation
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
defmodule KeycloakSync.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
def start(_type, _args) do
# List all child processes to be supervised
import Supervisor.Spec
@collegeimprovements
collegeimprovements / periodic_task.ex
Created December 6, 2018 03:43 — forked from trestrantham/periodic_task.ex
Run a task periodically natively in Elixir
defmodule MyApp.Periodically do
use GenServer
def start_link do
GenServer.start_link(__MODULE__, %{})
end
def init(state) do
Process.send_after(self(), :work, 2 * 60 * 60 * 1000) # In 2 hours
{:ok, state}
version: "3"
services:
postgres:
image: postgres:11.1
volumes:
- ./postgres_data:/var/lib/postgresql/data
environment:
POSTGRES_DB: keycloak
POSTGRES_USER: keycloak
defmodule PushButton do
@behaviour :gen_statem
@name :pushbutton_statem
# Client API
def start do
:gen_statem.start({:local,@name}, __MODULE__, [], [])
end
I have heard it said in the Erlang world that you start out writing functions to process lists using tail recursion, because that's what the books talk about. Then you realize that you can use functions in the standard library e.g. :lists.map. Then you realize that the syntax for list comprehensions is nicer for common cases. Then you come full circle and write functions which handle control flow, like Plug or "railway oriented programming"
Elixir has more powerful comprehensions with nicer syntax, and there are more patterns in Enum, and there are macros, but it's generally the same kind of progression
Pipe chains are generally best when you can organize things to have a consistent first argument style. It can conflict with the pattern of returning {:ok, value} or {:error, reason}, which is generally a good thing
So pipes are nice when they happen more or less naturally, but don't force things.
So if you have a series of transformations on data which basically can't fail, then great. Otherwise, maybe not.
A
Hey team :wave::skin-tone-5: , would anyone have an example of using field metadata with middleware for auth?
Say something to take in roles allowed for a field
rhnonose [10:33 PM]
I do that in the resolver, but would be interested if there's a good way of doing it with middlewares
wackyzacck [10:39 PM]
@rhnonose yeah so someone gave the the solution a few weeks here, you can do it in the middleware I expect its a case of using the metadata (edited)
avotre [11:01 PM]
@collegeimprovements
collegeimprovements / gist:760ca3b327232a88351739c15767ee0b
Created August 4, 2018 16:55 — forked from mtigas/gist:952344
Mini tutorial for configuring client-side SSL certificates.

Client-side SSL

For excessively paranoid client authentication.

Using self-signed certificate.

Create a Certificate Authority root (which represents this server)

Organization & Common Name: Some human identifier for this server CA.

openssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 365 -key ca.key -out ca.crt
{:async_with, "~> 0.3.0"},
{:ex_sync, "~> 0.0.4"},
{:witchcraft, "~> 1.0"},
{:tesla, "~> 1.1"},
{:jason, "~> 1.1"},
{:absinthe, "~> 1.4"},
{:absinthe_phoenix, "~> 1.4"},
{:absinthe_plug, "~> 1.4"},
{:absinthe_ecto, "~> 0.1.3"},
{:ex_aws, "~> 2.1"},