Skip to content

Commit 6747e4c

Browse files
committed
gitignore output, post weekly listening
1 parent aa0a81a commit 6747e4c

35 files changed

Lines changed: 116 additions & 59327 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ personal-*.tar
2424

2525
# Temporary files, for example, from tests.
2626
/tmp/
27+
28+
.expert
29+
30+
output/

drafts/dont-wrap-that-ets-table.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
%{
2+
title: "Don't Wrap That ETS Table",
3+
description: "Don't make this common mistake",
4+
author: "Andy LeClair",
5+
tags: ["elixir"],
6+
related_listening: "https://www.youtube.com/watch?v=fXjTxC-HbKY",
7+
}
8+
---
9+
10+
I've seen this pattern enough that I wanted to make a post about it. Don't wrap that ETS table!
11+
12+
Consider the following Elixir code:
13+
14+
```elixir
15+
def MyServer do
16+
use GenServer
17+
@table __MODULE__
18+
19+
def start_link(opts) do
20+
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
21+
end
22+
23+
def init(_) do
24+
_tid = :ets.new(@table, [:set, :protected, :named_table])
25+
{:ok, []}
26+
end
27+
28+
def put_item(key, value) do
29+
GenServer.call(__MODULE__, {:put_item, key, value})
30+
end
31+
32+
def get_item(key) do
33+
GenServer.call(__MODULE__, {:get_item, key})
34+
end
35+
36+
def handle_call({:get_item, key}, _from, _state) do
37+
:ets.lookup(@table, key)
38+
end
39+
40+
def handle_call({:put_item, key, value}, _from, _state) do
41+
:ets.insert(@table, key, value)
42+
end
43+
end
44+
```
45+

lib/mix/tasks/publish_post.ex

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
defmodule Mix.Tasks.PublishPost do
2+
use Mix.Task
3+
4+
@impl Mix.Task
5+
def run(_args) do
6+
{:ok, drafts} = File.ls("./drafts")
7+
8+
indexed_drafts = Enum.with_index(drafts, 1) |> Enum.map(fn {path, i} -> "#{i}. #{path}" end)
9+
10+
IO.puts """
11+
Listing Draft posts:
12+
#{Enum.join(indexed_drafts, "\n")}
13+
"""
14+
15+
index = get_draft()
16+
draft = Enum.at(drafts, index - 1)
17+
18+
IO.puts "Publishing #{draft}"
19+
20+
today = Date.utc_today()
21+
22+
File.cp!("./drafts/#{draft}", "./posts/#{today.year}/#{today.month}-#{today.day}-#{draft}")
23+
File.rm!("./drafts/#{draft}")
24+
end
25+
26+
def get_draft do
27+
IO.gets("Which draft post would you like to publish?: ") |> String.trim() |> String.to_integer()
28+
end
29+
30+
end

output/assets/app.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

output/assets/app.js

Lines changed: 0 additions & 1 deletion
This file was deleted.
-32.3 KB
Binary file not shown.
-21.7 KB
Binary file not shown.
-20.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)