Skip to content

Instantly share code, notes, and snippets.

View maartenvanvliet's full-sized avatar
🍊

Maarten van Vliet maartenvanvliet

🍊
View GitHub Profile
@maartenvanvliet
maartenvanvliet / interface_errors.ex
Created September 19, 2022 18:58
Interface errors Stage 6a: Error Union List + Interface
# https://productionreadygraphql.com/2020-08-01-guide-to-graphql-errors
defmodule Absinthe.ErrorInterfaceTest do
use Absinthe.Case, async: true
defmodule TestSchema do
use Absinthe.Schema
query do
field :foo, :string
@maartenvanvliet
maartenvanvliet / skip_introspection.ex
Created January 22, 2022 18:25
removes __schema node from a query.
defmodule SkipIntrospection do
@behaviour Absinthe.Phase
def run(doc, options \\ []) do
node = Absinthe.Blueprint.prewalk(doc, &handle_node/1)
{:ok, node}
end
defp handle_node(%Absinthe.Blueprint.Document.Operation{} = node) do
selections =
@maartenvanvliet
maartenvanvliet / builtin_spec_compliant_int.ex
Created January 4, 2022 07:32
Absinthe spec compliant int pipeline modifier
defmodule Absinthe.Type.BuiltIns.SpecCompliantInt do
use Absinthe.Schema.Notation
@moduledoc false
scalar :integer, name: "Int" do
description """
The `Int` scalar type represents non-fractional signed whole numeric
values between `-2^31` and `2^31 - 1` as outlined in the
[GraphQl spec](ttps://spec.graphql.org/October2021/#sec-Int).
@maartenvanvliet
maartenvanvliet / introspect_blocker.ex
Created November 9, 2019 08:41
block introspection by
defmodule GraphqlService.Schema.IntrospectBlocker do
# by https://github.com/sb8244
@behaviour Absinthe.Middleware
def call(resolution, _config) do
case Absinthe.Resolution.path(resolution) |> IO.inspect do
["__schema" | _] ->
%{resolution | errors: ["__schema introspection is disabled"] }
["__type" | _] ->
@maartenvanvliet
maartenvanvliet / mandrill.ex
Created December 11, 2018 15:34
mandrill webhook
defmodule SimplePlug.Handle do
@behaviour Plug
@behaviour PlugWebhook
def init(options) do
# initialize options
options
end
@maartenvanvliet
maartenvanvliet / cloudfront_signer.ex
Created April 24, 2018 18:55
Elixir Cloudfront signed urls
defmodule CloudfrontSigner do
def signed_url(cloudfront_key_pem, key_pair, url, expiry_time) do
decoded_key = cloudfront_key_pem |> decode_key
expiry_time = :os.system_time(:second) + expiry_time
policy = policy(url, expiry_time)
signature =
:public_key.sign(policy, :sha, decoded_key)
|> Base.encode64()
|> String.replace("+", "-")

Keybase proof

I hereby claim:

  • I am maartenvanvliet on github.
  • I am maartenvanvliet (https://keybase.io/maartenvanvliet) on keybase.
  • I have a public key ASAiGTlG3pGbGtaEU5tVYunmE__A1RubkwGJfRBZjCR9eAo

To claim this, I am signing this object:

@maartenvanvliet
maartenvanvliet / helpers
Last active August 29, 2015 14:05
R convenience helpers
#First differences, NA for first value
diff_na <- function(vector){
return c(NA, diff(value))
}
#Renames column
col.mv <- function(dataframe, old_name, new_name){
names(dataframe)[names(dataframe)==old_name] <- new_name
return dataframe
}