This guide is a quick set of guidelines for reading or writing elixir code. It's designed to get you through stuff that is different from Elixir relative to other programming languages you might be used to, and which you might miss while learning elixir.
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 RockE.DynamicImprover do | |
alias OpenAI | |
require EEx | |
EEx.function_from_string(:defp, :prompt, """ | |
<% assigns = Map.from_struct(round) %> | |
Hi ChatGPT! I'm trying to prompt ChatGPT 3.5 to perform a function call. | |
However, the function call often makes mistakes in the passed argument: | |
The current accuracy is <%= @accuracy %> I'd love to see the accuracy go up to 90%. |
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 NxExt do | |
import Nx.Defn | |
@bitshift Nx.tensor([[1], [16]], type: {:u, 8}) | |
@doc """ | |
Takes an N-vector of floats (arbitrarily typed) and converts it into 4-bit gptq, which has | |
a range of -8..-7. Should be compacted into two "floats" per byte, with the lower indexed | |
value in the less significant nybble | |
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 Aaa do | |
# terminal condition. If we've gotten through the whole pattern we're done. | |
def matches(<<>>, <<>>), do: true | |
# If the first character matches and has a question mark we must make an | |
# epsilon transition. We have to try both "universes". In one "universe" | |
# we proceed as if we consumed the optional match, and the other we proceed | |
# as if we didn't. The success of either means the match succeeds. This | |
# means for this branch we don't get TCO =( but this should be relatively rare. | |
def matches(<<char, ??, rest1 :: binary>>, string = <<char, rest2 :: binary>>) 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
:net_kernel.start([:"main@127.0.0.1"]) | |
:erlang.set_cookie(:cook) | |
{:ok, peer, peername} = | |
:peer.start(%{connection: 0, name: :peer, host: ~C'127.0.0.1'}) | |
:peer.call(peer, :erlang, :set_cookie, [:cook]) | |
Node.connect(peername) | |
# add code paths | |
:rpc.call(peername, :code, :add_paths, [:code.get_path()]) |
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
{ | |
"Elixir debug": { | |
"prefix": "dd", | |
"body": "|> dbg", | |
"description": "injects an elixir dbg statement" | |
}, | |
} |
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
const beam = @import("beam.zig"); | |
const e = @import("erl_nif.zig"); | |
const std = @import("std"); | |
pub fn make(env: beam.env, value: anytype) beam.term { | |
const T = @TypeOf(value); | |
if (T == beam.env) return value; | |
switch (@typeInfo(T)) { | |
.Array => return make_array(env, value), | |
.Pointer => return make_pointer(env, value), |
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
const E = enum(u12) { | |
Int = 0xFFF, | |
String = 0xFFE, | |
Pointer = 0xFFD, | |
} | |
const P = packed union(?e){ | |
const this = @This(); | |
Int: packed struct { |
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
{ | |
"Inspect": { | |
"prefix": "ins", | |
"body": "|> IO.inspect(label: \"$RELATIVE_FILEPATH:#{__ENV__.line}\")", | |
"description": "Adds a pipeline with a labelled `IO.inspect`", | |
} | |
} |
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 T do | |
@foo [%{foo: "bar"}] | |
def t(@foo) do | |
:ok | |
end | |
end | |
# DISASSEMBLED RESULT: |
NewerOlder