Skip to content

Instantly share code, notes, and snippets.

View trbngr's full-sized avatar

Chris Martin trbngr

  • Phoenix, AZ, USA
View GitHub Profile
@trbngr
trbngr / .formatter.exs
Last active June 18, 2021 20:12
Phoenix Socket Macros
[
locals_without_parens: [handle_message: 2, handle_message: 3],
import_deps: [:ecto, :phoenix, :cqrs_tools],
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
subdirectories: ["priv/*/migrations"]
]
@trbngr
trbngr / GraphQLService.scala
Created October 13, 2016 23:03
Parse GraphQl Request with Circe.
case class GraphQlRequest(query: String, operation: Option[String], variables: Json)
def parseRequest: Directive1[GraphQlRequest] = {
import cats.data.Xor
import io.circe.ParsingFailure
import io.circe.parser.{parse ⇒ parseJson}
entity(as[Json]).map { json ⇒
val cursor = json.hcursor
val variables = {
@trbngr
trbngr / ord.ex
Last active December 2, 2019 02:28
Beging the Ord protocol
defprotocol Ord do
@doc """
iex> Ord.compare("a", "b")
:EQ
iex> Ord.compare("a", "b", type: :alphabetical)
:LT
"""
def compare(a, b, opts \\ [])
def lt(a, b)
def lte(a, b)
var express = require('express');
var session = require('express-session');
var RedisStore = require('connect-redis')(session);
var Strategy = require('./passport-openidconnect/index').Strategy;
module.exports.configure = function configure(app, passport) {
var identityServer = 'https://users.xxx.com/identity';
var auth = {
@trbngr
trbngr / ADTMacros.scala
Last active July 16, 2019 18:06
DynamoFormats for ADT
package com.company.macros
import scala.reflect.macros.blackbox
class ADTMacros(val c: blackbox.Context) {
import c.universe._
def dynamoFormat[T: c.WeakTypeTag]: Tree = {
generate[T] { (tpe, symbols) =>
@trbngr
trbngr / results
Last active May 24, 2019 03:31
roman numerals benchmarks
Operating System: macOS
CPU Information: Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz
Number of Available Cores: 8
Available memory: 16 GB
Elixir 1.8.1
Erlang 21.2
Benchmark suite executing with the following configuration:
warmup: 2 s
time: 5 s
@trbngr
trbngr / dates.ex
Last active March 23, 2019 01:36
parse dates
defmodule Dates do
@valid_dates [
Date.utc_today() |> Date.to_iso8601(),
NaiveDateTime.utc_now() |> NaiveDateTime.to_iso8601(),
DateTime.utc_now() |> DateTime.to_iso8601()
]
|> Enum.map(&to_string/1)
|> Enum.join(" or ")
@invalid_date_message "Invalid date. Expected formated date. ie #{@valid_dates}"
@trbngr
trbngr / App.js
Last active February 19, 2019 10:20
Render hidden, allow download.
import React from 'react';
import Pdf from './Pdf';
import PdfRenderer from './PdfRenderer';
export default () => (
<PdfRenderer
fileName="settlements.pdf"
buttonClasses="btn btn-secondary view-pdf"
extra={1}
@trbngr
trbngr / retryable.ex
Last active December 20, 2018 22:18
Elixir Retryable
defmodule Retryable do
require Logger
@enforce_keys [:mfa]
defstruct mfa: nil,
retries: 1,
should_retry: nil,
before_execution: nil
@trbngr
trbngr / KnightsDialer.ex
Last active October 10, 2018 04:36
Knights Dialer in Elixir.
defmodule KnightsDialer do
@nieghbors_map %{
1 => [6, 8],
2 => [7, 9],
3 => [4, 8],
4 => [3, 9, 0],
5 => [],
6 => [1, 7, 0],
7 => [2, 6],
8 => [1, 3],