Skip to content

Instantly share code, notes, and snippets.

@BjRo
BjRo / keyword_lists.ex
Last active February 21, 2016 08:52
Trying to unquote a map from a macro does not compile
defmodule Test do
defmacro __using__(opts) do
quote do
import unquote(__MODULE__), only: [map_test: 0]
end
end
#works as expected
defmacro map_test do
bar = [foo: "bar"]
@BjRo
BjRo / Timex.ex
Last active April 22, 2016 08:45
Dialyzer, who knows what's going on?
defmodule Messages.Time do
use Timex
@spec timestamp() :: Timex.DateTime.t
def timestamp, do: Timex.DateTime.now(:utc)
@type ts :: Timex.Convertable.t | none
@spec timestamp_iso8601(ts) :: binary
def timestamp_iso8601(ts \\ __MODULE__.timestamp) do
{:ok, iso8601} = Timex.format(ts, "{ISO:Extended}")
@BjRo
BjRo / Messages.Time.ex
Created April 22, 2016 14:47
Dialyzer is our friend again :-)
defmodule Messages.Time do
use Timex
alias Timex.DateTime
@spec timestamp() :: DateTime.t
def timestamp, do: DateTime.now(:utc)
@spec timestamp_iso8601() :: String.t
@dialyzer {:nowarn_function, timestamp_iso8601: 0}
def timestamp_iso8601 do
# Move around the buffer in vim style
setw -g mode-keys vi
# Shortcuts
bind r source-file ~/.tmux.conf\; display "Reloaded!" #reload configuration
bind | split-window -h -c '#{pane_current_path}' #split window horizontally
bind - split-window -v -c '#{pane_current_path}' #split window vertically
bind h select-pane -L #vim style pane navigation
bind j select-pane -D #vim style pane navigation
bind k select-pane -U #vim style pane navigation
@BjRo
BjRo / logjam_zmq.ex
Created August 25, 2016 10:00
Logjam ZMQ info headers
@meta_info_version 1
@meta_info_tag 0xcabd
@meta_info_device_number 0
@compression_method 0
def pack_info(sequence) do
<<@meta_info_tag::big-integer-unsigned-size(16),
@compression_method::big-integer-unsigned-size(8),
@meta_info_version::integer-unsigned-size(8),
@meta_info_device_number::big-integer-unsigned-size(32),
zclock_time::big-integer-unsigned-size(64),
val routes =
(post & path("graphql")) {
optionalHeaderValueByName("ACCEPT_LANGUAGE") { accept_language =>
entity(as[JsValue]) { requestJson =>
val context = Context.from(accept_language)
println("ACCEPT_LANGUAGE: " + context.language)
graphQLEndpoint(requestJson, context)
}
}
} ~
@BjRo
BjRo / unions.scala
Created February 10, 2017 16:56
union types in sangria
object ProfileRef {
val inactiveDefinition = ObjectType(
"InactiveProfileRef",
"An inactive profile",
fields = fields[UserContext, JsObject](
Field("id", IntType, None, resolve = ctx => (ctx.value \ "id").as[Int])
)
)
val activeDefinition = ObjectType(
@BjRo
BjRo / scenario.graphql
Last active February 22, 2017 18:22
Batching experiments with different server-side GraphQL implementations
fragment profileFragment on ProfileRef {
__typename
... on ActiveProfileRef {
id
firstName
lastName
}
... on InactiveProfileRef {
@BjRo
BjRo / xing-one-dsl.scala
Created June 21, 2017 16:15
XING One DSL example
object Address extends ApiDSL {
val t = ApiObjectType(
"Address",
"A standard container for representing an address",
interfaces(Addressable.t),
fields(
optionalApiField("city", StringType),
optionalApiField("province", StringType),
optionalApiField("street", StringType),
optionalApiField("zip", StringType),
@BjRo
BjRo / sangria_error.txt
Created December 4, 2017 09:57
Parser errors after upgrade to 1.3.3
[error] sangria.parser.SyntaxError: Syntax error while parsing GraphQL query. Invalid input ""/test") {\n}", expected ValueConst, ArgumentConst, DirectiveConst or InputValueDefinition (line 7, column 32):
[error] input MyResolver @httpGet(url: "/test") {
[error] ^ (QueryParser.scala:433)