Skip to content

Instantly share code, notes, and snippets.

View ahey's full-sized avatar

Alan Heywood ahey

  • Softweb Development Pty Ltd
  • Brisbane, Australia
  • 01:30 (UTC +10:00)
View GitHub Profile
@ahey
ahey / confirm_with_token.ex
Created October 11, 2023 05:07
Using ash and ash_authentication, configure a user resource for auth via GraphQL
defmodule YourApp.User.Actions.ConfirmWithToken do
use Ash.Resource.ManualCreate
def create(changeset, _opts, _context) do
strategy = AshAuthentication.Info.strategy!(YourApp.User, :confirm)
AshAuthentication.Strategy.action(
strategy,
:confirm,
%{"confirm" => changeset.arguments[:token]}
@ahey
ahey / ash_intellisense.bash
Created April 4, 2023 01:38
Enable elixir-ls / elixir_sense intellisense for ASH DSLs
# Get intellisense working with the Ash Framework DSL in VSCode
# on MacOS using the asdf version manager
git clone https://github.com/elixir-lsp/vscode-elixir-ls.git
cd vscode-elixir-ls
# Update elixir_sense to the latest version and get dependencies
git submodule init
git submodule update --remote
cd elixir-ls
@ahey
ahey / auth.ex
Created February 24, 2023 06:22
Ash Framework module for finding out whether an actor is allowed to perform an action on a particular resource instance
defmodule Auth do
require Ash.Query
def can_on_instance?(resource, id, action_name, actor, api) do
action = Ash.Resource.Info.action(resource, action_name)
case action.type do
:create ->
false
@ahey
ahey / built_in_elixir_errors.ex
Last active January 7, 2022 01:57
List of core elixir errors
# The following core errors are built in to elixir
# See https://github.com/elixir-lang/elixir/blob/main/lib/elixir/lib/exception.ex
ArgumentError
ArithmeticError
BadArityError
BadBooleanError
BadFunctionError
BadMapError
BadStructError
@ahey
ahey / gist:8dab2f6614f5490996934150564359e8
Created January 18, 2020 00:00
Detecting when a heroku application is down for maintenance
curl -v 'https://stormy-lake-09991.herokuapp.com/' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Connection: keep-alive' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache'
* Trying 34.197.140.84...
* TCP_NODELAY set
* Connected to stormy-lake-09991.herokuapp.com (34.197.140.84) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/cert.pem
CApath: none
@ahey
ahey / ConnectToQuickBooksDirective.js
Created August 27, 2014 01:44
angularjs directive to show the quickbooks connect button
'use strict';
angular.module('thirdParty')
.directive('connectToQuickbooks', function($window){
return {
restrict: 'E',
template: "<ipp:connectToIntuit></ipp:connectToIntuit>",
link: function(scope) {
var intuitScriptLoaded = function(){