This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To use this check: | |
# 1. Add it to your project at `/lib/credo/disallow_unless.ex` | |
# 2. Add it to the list of `requires` in `.credo.exs`: | |
# | |
# requires: ["lib/credo/disallow_unless.ex"], # <-- add file here | |
# | |
# Add the module to the list of `checks` within `.credo.exs`: | |
# | |
# checks: [ | |
# {Credo.DisallowUnless}, # <-- add check here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule AppServerWeb.Telemetry do | |
require Logger | |
@doc """ | |
Attaches an event handler to the "handled in" event on your Phoenix Channels. | |
Call from within your application.ex initialization. | |
""" | |
def attach_telemetry_handlers() do | |
channel_handled_in = [:phoenix, :channel_handled_in] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Test Elixir Server | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you're here, I assume it's because you tried to run | |
# :observer for the first time on your Mac and discovered | |
# it won't work because of some obscure issue with wxwidgets | |
# (formerly known to Homebrew as wxmac). | |
# | |
# This script will fix it for you. | |
# 1. Remove the old and busted copy | |
brew uninstall wxwidgets --ignore-dependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Greeter do | |
use GenServer | |
def start_link(opts) do | |
name = Access.get(opts, :name, __MODULE__) | |
GenServer.start_link(__MODULE__, name, name: name) | |
end | |
def greet(server \\ __MODULE__, name) do | |
GenServer.call(server, {:greet, name}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_user = User.start_link("Tyler", "abcd-efgh-1234-5678") | |
# Prints "Hi, I'm Tyler" | |
User.say_hello(my_user) | |
# Prints a process ID | |
IO.inspect(my_user) | |
# Prints the state data: | |
# %{name: "Tyler", id: "abcd-efgh-1234-5678"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Dictionary { | |
func mapKeys<NewKey>(_ transform: (Key) -> NewKey) -> [NewKey: Value] { | |
reduce(into: [NewKey: Value]()) { result, item in | |
result[transform(item.key)] = item.value | |
} | |
} | |
} | |
/// 🥤 | |
extension Dictionary where Key: RawRepresentable { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if git checkout "$1" ; then | |
echo "No untracked files had to be deleted" | |
else | |
git checkout "$1" 2>&1 > /dev/null | grep $'\t' | xargs rm | |
git checkout "$1" | |
echo "Deleted conflicting untracked files" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MmoServer.WorldCache do | |
@moduledoc "A cache of all aircraft in the world, intermittently updated for 'flight tracker' API usage" | |
use GenServer | |
require Logger | |
import Appsignal, only: [set_gauge: 2] | |
def start_link(_), do: GenServer.start_link(__MODULE__, %{}, name: __MODULE__) | |
# Log a new connected user | |
def put(%{session_id: sid, lon: lon, lat: lat} = acf) when is_integer(sid) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule ExplicitlyIgnoreReturnValues do | |
@moduledoc """ | |
This is a horrifying hack. | |
It is a complete copy & paste of Credo's stock unused_operation and unused_function_return_helper, | |
but modified slightly to reverse the logic; instead of specifying modules and types to warn about when unused, | |
we specify an "allow list" of the *only* modules & functions to allow ignoring. | |
See original copypasta source here: | |
https://github.com/rrrene/credo/blob/master/lib/credo/check/warning/unused_operation.ex |
NewerOlder