Skip to content

Instantly share code, notes, and snippets.

View bruce's full-sized avatar
🤝
Here to help!

Bruce Williams bruce

🤝
Here to help!
View GitHub Profile
@bruce
bruce / fill.rb
Last active October 27, 2021 20:09
A rough script to update a memex project with all issues from a repository (requires faraday)
abort 'Usage: ruby fill.rb <PROJECT_NUMBER> <NWO> <PAT>' unless ARGV.length == 3
require 'bundler/setup'
require 'fileutils'
require 'json'
require 'faraday'
class ProjectSync
@bruce
bruce / sync-zotero-refs.rb
Created November 22, 2020 03:12
A hack to build references in Obsidian for Zotero items
#!/usr/bin/env ruby
require "net/http"
require "uri"
require "yaml"
require "json"
require "fileutils"
class String
def dasherize
@bruce
bruce / absinthe.md
Last active November 2, 2019 16:03
Very brief description of how Absinthe processes GraphQL
@bruce
bruce / Dockerfile.dev
Created March 8, 2019 17:21
docker-compose + development Phoenix
FROM cargosense/elixir-ubuntu:20.2-v1.6.2
# Install debian packages
RUN apt-get update
RUN apt-get install -y build-essential inotify-tools postgresql-client
# Install Phoenix packages
RUN mix local.hex --force
RUN mix local.rebar --force
RUN mix archive.install --force https://github.com/phoenixframework/archives/raw/master/phx_new.ez

Here's a quick workaround (at least for local use) that involves downloading the assets:

First, make sure you're running absinthe_plug from master (you need an unreleased fix for HTTPS downloads):

In your mix.exs:

defp deps do
  [
    # ...
@bruce
bruce / router.ex
Created February 13, 2018 03:39
Forwarding to two Absinthe schemas, what I'm sure is just an ugly hack
defmodule CoryWeb.Router do
use CoryWeb, :router
defmodule SchemaOnePlug do
def init(_), do: Absinthe.Plug.init(schema: CoryWeb.SchemaOne)
def call(conn, opts), do: Absinthe.Plug.call(conn, opts)
end
defmodule SchemaTwoPlug do
def init(_), do: Absinthe.Plug.init(schema: CoryWeb.SchemaTwo)
@bruce
bruce / schema.ex
Created July 17, 2017 16:12
Simple example of a field result being returned as a GraphQL type
mutation do
field :create_foo, :create_foo_result do
resolve fn _, _ ->
# Return an :ok w/ a :create_foo_result
# containing a `foo` and/or `errors`
end
end
end
@desc "The result of creating a Foo"
@bruce
bruce / company_queries.ex
Created June 21, 2017 05:24
Use of import_types and import_fields
defmodule MyApp.Web.Schema.Types.Company do
use Absinthe.Schema.Notation
object :company_queries do
field :companies, list_of(:company) do
# ...
end
field :company, type: :company do
@bruce
bruce / schema.ex
Created June 19, 2017 01:56
A useful Absinthe resolve_type pattern
resolve_type fn
# Guess type from struct name:
# Example: %Foo{} -> :foo
%str{}, _ ->
str
|> Some.Helper.Module.struct_to_object_type
value, _ ->
Logger.warn "Could not extract type from value: #{inspect value}"
nil
end
@bruce
bruce / subscriptions.md
Last active June 16, 2017 23:30
Absinthe Subscriptions Sketch

In a vanilla ES6 project, using no framework:

// Configuration

import { Client } from 'absinthe-phoenix';

const client = new Client({
  uri: "http://localhost:3010/graphql",
  wsUri: "ws://localhost:3010/socket"