Skip to content

Commit

Permalink
Merge pull request #26 from EmmaRamirez/feature/elixir-post
Browse files Browse the repository at this point in the history
Feature/elixir post
  • Loading branch information
EmmaRamirez authored Nov 16, 2020
2 parents 4e4c611 + c7f8f56 commit 2b384b9
Show file tree
Hide file tree
Showing 74 changed files with 26,619 additions and 200 deletions.
22 changes: 20 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# [0.22.0](https://github.com/EmmaRamirez/emmaramirez.me/compare/0.21.4...0.22.0) (2020-11-16)


### Features

* add post on Elixir with new prism syntax highlights ([d459f41](https://github.com/EmmaRamirez/emmaramirez.me/commit/d459f41eb18c7bc9b9a52f002c27f2835e99d4a4))
* **design:** update design to not constrain width on posts ([97e73f0](https://github.com/EmmaRamirez/emmaramirez.me/commit/97e73f0d5eb9c83ad51096166988f20367c15676))



## [0.21.4](https://github.com/EmmaRamirez/emmaramirez.me/compare/0.21.3...0.21.4) (2020-11-11)


Expand Down Expand Up @@ -103,13 +113,12 @@



## [0.16.2](https://github.com/EmmaRamirez/emmaramirez.me/compare/0.14.0...0.16.2) (2020-05-28)
## [0.16.2](https://github.com/EmmaRamirez/emmaramirez.me/compare/v0.15.0...0.16.2) (2020-05-28)


### Bug Fixes

* fix links markdown'd wrong ([3911a7b](https://github.com/EmmaRamirez/emmaramirez.me/commit/3911a7bfb30699aaf1750b36ebb2bfc313b20fcb))
* **writing:** reorganize section abou Elm ([bce34fe](https://github.com/EmmaRamirez/emmaramirez.me/commit/bce34fe60978cad7deabd746747f11f4ddd84625))


### Features
Expand All @@ -118,6 +127,15 @@



# [0.15.0](https://github.com/EmmaRamirez/emmaramirez.me/compare/0.14.0...v0.15.0) (2018-08-24)


### Bug Fixes

* **writing:** reorganize section abou Elm ([bce34fe](https://github.com/EmmaRamirez/emmaramirez.me/commit/bce34fe60978cad7deabd746747f11f4ddd84625))



# [0.14.0](https://github.com/EmmaRamirez/emmaramirez.me/compare/0.13.4...0.14.0) (2018-07-01)


Expand Down
4 changes: 2 additions & 2 deletions docs/bundle.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions docs/posts/a-couple-random-tech-thoughts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Slab&display=swap" rel="stylesheet">
<link href='../../prism.css' rel='stylesheet' />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="../../code-theme.css" rel="stylesheet">
<meta name="keywords" content="no tags">
<meta name="description" content="<p>I haven't had much time or energy to write articles, so I wanted to dump a couple things that I've been thinking lately....</p>
">
Expand Down Expand Up @@ -48,7 +48,8 @@ <h2>Frustrated users are the most important ones.</h2>
<div id='app'></div>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<script src='../../bundle.js'></script>
<script src="../../rainbow-custom.min.js"></script><!-- Global site tag (gtag.js) - Google Analytics -->
<script src='../../prism.js'></script>
</script><!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-79007755-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
Expand Down
5 changes: 3 additions & 2 deletions docs/posts/building-the-nuzlocke-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Slab&display=swap" rel="stylesheet">
<link href='../../prism.css' rel='stylesheet' />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="../../code-theme.css" rel="stylesheet">
<meta name="keywords" content="no tags">
<meta name="description" content="<blockquote>
<p>Note: This project is still in beta. Check it out <a href='generator'>here</a>...</p>
Expand Down Expand Up @@ -44,7 +44,8 @@ <h2>The Future</h2>
<div id='app'></div>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<script src='../../bundle.js'></script>
<script src="../../rainbow-custom.min.js"></script><!-- Global site tag (gtag.js) - Google Analytics -->
<script src='../../prism.js'></script>
</script><!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-79007755-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
Expand Down
5 changes: 3 additions & 2 deletions docs/posts/ill-be-giving-a-talk-at-forwardjs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Slab&display=swap" rel="stylesheet">
<link href='../../prism.css' rel='stylesheet' />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="../../code-theme.css" rel="stylesheet">
<meta name="keywords" content="no tags">
<meta name="description" content="<p>💖...</p>
">
Expand All @@ -21,7 +21,8 @@
<div id='app'></div>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<script src='../../bundle.js'></script>
<script src="../../rainbow-custom.min.js"></script><!-- Global site tag (gtag.js) - Google Analytics -->
<script src='../../prism.js'></script>
</script><!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-79007755-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
Expand Down
5 changes: 3 additions & 2 deletions docs/posts/learning-rust/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Slab&display=swap" rel="stylesheet">
<link href='../../prism.css' rel='stylesheet' />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="../../code-theme.css" rel="stylesheet">
<meta name="keywords" content="no tags">
<meta name="description" content="<p>I've been writing Rust code for over a year now, and I am still squarely in the novice category. Which isn't a bad thing! But I'm certainly less of a novice and less mystified by Rust than I was a year ago. I come from a non-systems programming background, so most of this is going to relate back to that. I'll be going over some of the things that I've learned about Rust that make it as confusing as it is special....</p>
">
Expand Down Expand Up @@ -39,7 +39,8 @@ <h2>Borrowing and References</h2>
<div id='app'></div>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<script src='../../bundle.js'></script>
<script src="../../rainbow-custom.min.js"></script><!-- Global site tag (gtag.js) - Google Analytics -->
<script src='../../prism.js'></script>
</script><!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-79007755-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
Expand Down
116 changes: 116 additions & 0 deletions docs/posts/making-a-cli-game-with-elixir-part-1/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@

<html lang=en>
<head>
<title>emmaramirez.me</title>
<meta charset='utf-8'>
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Slab&display=swap" rel="stylesheet">
<link href='../../prism.css' rel='stylesheet' />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="no tags">
<meta name="description" content="<p>Out of curiosity, I've currently been experimenting with the <a href='https://elixir-lang.org/'>Elixir programming language</a>, and one of my goals to get a good feel for the language is building a tiny game in the command line. Why? Because it's fun!...</p>
">

</head>
<body class=markdown-body>
<div id='markdown' style='display: none'><h1>Making a CLI Game with Elixir Part I</h1>
<p>Out of curiosity, I've currently been experimenting with the <a href="https://elixir-lang.org/">Elixir programming language</a>, and one of my goals to get a good feel for the language is building a tiny game in the command line. Why? Because it's fun!</p>
<blockquote>
<p>Note: This is being written about two weeks into learning Elixir, so I'm certain that some of the patterns &amp; ideas here are not prime Elixir. I'll do my best to update this blog post over time as I learn more.</p>
</blockquote>
<h2>Beginning the Brew</h2>
<p>The first thing, <a href="https://elixir-lang.org/getting-started/introduction.html">after installing Elixir itself</a> is creating an Elxir file*.</p>
<pre><code class="language-bash">touch game.ex
elixirc game.ex
</code></pre>
<p><code>.ex</code> is the file extension for Elixir, and the <code>elixirc</code> command is how we run Elixir files (it stands for Elixir compile).</p>
<p>We begin our file by creating a module for our Game:</p>
<pre><code class="language-elixir">defmodule Game do
def start_game do
IO.puts &quot;Hello! Welcome to Elixirtopia. What would you like to do?&quot;
end
end

Game.start_game
</code></pre>
<p><code>defmodule</code> declares our module and <code>start_game</code> is a method that prints to the console. When you run <code>elixirc game.ex</code>, you should see &quot;Hello! Welcome to Elixirtopia. What would you like to do?&quot; printed to the screen.</p>
<h2>Managing State</h2>
<p>Functional programming relies on the pure functions in order to achieve predictability and elegance. But like most programming languages, Elixir offers a way of handling side-effects, that is code that dispatches actions rather than just returning values, through procceses, in this case <code>Agent</code>s.</p>
<p>Let's refactor our code a bit to look more like this</p>
<pre><code class="language-elixir">defmodule Game do
use Agent

def start_game do
IO.puts &quot;Hello! Welcome to Elixirtopia. What would you like to do?&quot;
end

def create_player do
Agent.start_link(fn -&gt; %{
:attack =&gt; 10,
:current_hp =&gt; 10,
:max_hp =&gt; 10,
:name =&gt; &quot;&quot;,
} end, name: :player)
end
end
</code></pre>
<p>Okay, so that's quite a bit going on there. First, we declare <code>use Agent</code>, in the same way you would any import. Then, our <code>create_player</code> function starts the process that creates our player -- we also name it <code>:player</code> for convenience later on. For this game, we declare a couple of attributes in a Map (<code>%{}</code>) (equivalent to a Python dict or a Javascript object), chiefly attack, current_hp, max_hp, and name.</p>
<p>Let's add these two additional functions. For brevity's sake, presume that any additional functions are int he body of our <code>Game</code> module.</p>
<pre><code class="language-elixir">def get_player do
Agent.get(:player, &amp; &amp;1)
do

def update_player(key, value) do
Agent.get_and_update(:player, fn (x) -&gt; {x | %{x | key =&gt; value }} end)
end
</code></pre>
<p>Don't worry too much about any confusing syntax here, just know that <code>get_player</code> retrieves our <code>:player</code> from state and <code>update_player</code> updates the Map with the appropriate map and key.</p>
<h2>Sequencing the Game</h2>
<p>Now, let's modify our <code>start_game</code> function</p>
<pre><code class="language-elixir">def start_game do
Game.create_player
answer = IO.gets &quot;&quot;&quot;
Hello! Welcome to Elixirtopia. What would you like to do?
[1] Explore
[2 / any other key] Quit
&quot;&quot;&quot;
answer_parsed = Integer.parse answer
number = elem(answer_parsed, 0)

cond do
number == 1 -&gt; explore
number == 2 -&gt; quit
number == :error -&gt; quit
true -&gt; quit
end
end
</code></pre>
<p>Let's run through all of what this means</p>
<p><code>Game.create_player</code> calls our Agent to manage our player state</p>
<p><code>IO.gets</code> prints out a prompt with a multiline <code>&quot;&quot;&quot;</code> string</p>
<p><code>elem(answer_parsed, 0)</code> after our answer has been parsed, much like in Rust, we need to unwrap the resulting value. Elixir will either return our value or an <code>:error</code></p>
<p><code>cond do</code> declares a condition and we match based on that; the <code>true</code> declaration at the end will match any condition we give it. You may intuit that because we only have 2 options—explore or quit—we only need <code>number == 1 -&gt; explore</code> and <code>true -&gt; quit</code> and you'd be absolutely right!</p>
<p><code>explore</code> and <code>quit</code> are functions we haven't written yet!</p>
<p>We'll walk through the exploration and more in the next segment.</p>
<h2>Further Reading &amp; Footnotes</h2>
<p>* <code>Mix</code> is generally what you would use to initiate a real-world project, but this is more in the alley of &quot;contrived example.&quot;</p>
<p>Additional Reading</p>
<ul>
<li><a href="https://dockyard.com/blog/2016/08/05/understand-capture-operator-in-elixir">Explanation of &amp; Operator</a></li>
</ul>
</div>
<div id='app'></div>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<script src='../../bundle.js'></script>
<script src='../../prism.js'></script>
</script><!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-79007755-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-79007755-1');
</script>
</body>
</html>
50 changes: 50 additions & 0 deletions docs/posts/making-a-cli-game-with-elixir/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

<html lang=en>
<head>
<title>emmaramirez.me</title>
<meta charset='utf-8'>
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Slab&display=swap" rel="stylesheet">
<link href='../../prism.css' rel='stylesheet' />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="no tags">
<meta name="description" content="<p>Out of curiosity, I've currently been experimenting with the <a href='https://elixir-lang.org/'>Elixir programming language</a>, and one of my goals to get a good feel for the language is building a tiny game in the command line. Why? Because it's fun!...</p>
">

</head>
<body class=markdown-body>
<div id='markdown' style='display: none'><h1>Making a CLI Game with Elixir</h1>
<p>Out of curiosity, I've currently been experimenting with the <a href="https://elixir-lang.org/">Elixir programming language</a>, and one of my goals to get a good feel for the language is building a tiny game in the command line. Why? Because it's fun!</p>
<blockquote>
<p>Note: This is being written about two weeks into learning Elixir, so I'm certain that some of the patterns &amp; ideas here are not prime Elixir. I'll do my best to update this blog post over time as I learn more.</p>
</blockquote>
<h2>Beginning the Brew</h2>
<p>The first thing, <a href="https://elixir-lang.org/getting-started/introduction.html">after installing Elixir itself</a> is creating the file in question.</p>
<pre><code class="language-bash">touch game.ex
elixirc game.ex
</code></pre>
<p><code>.ex</code> is the file extension for Elixir, and the <code>elixirc</code> command is how we run Elixir files (it stands for Elixir compile).</p>
<p>We begin our file by creating a module for our Game:</p>
<pre><code class="language-elixir">defmodule Game do
def start_game do
IO.puts &quot;Hello! Welcome to Elixirtopia. What would you like to do?&quot;
end
end
</code></pre>
<p><code>defmodule</code> declares our module and <code>start_game</code> is a method that prints to the console. When you run <code>elixirc game.ex</code>, you should see &quot;Hello! Welcome to Elixirtopia. What would you like to do?&quot; printed to the screen.</p>
</div>
<div id='app'></div>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<script src='../../bundle.js'></script>
<script src='../../prism.js'></script>
</script><!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-79007755-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-79007755-1');
</script>
</body>
</html>
5 changes: 3 additions & 2 deletions docs/posts/making-time-to-code/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Slab&display=swap" rel="stylesheet">
<link href='../../prism.css' rel='stylesheet' />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="../../code-theme.css" rel="stylesheet">
<meta name="keywords" content="no tags">
<meta name="description" content="<p>The more I worked, the less I coded. Okay, so perhaps that's not entirely true—I still <em>write</em> code, but the code we write for work and the code we write as a result of passion are often very different, kind of like an abstract expressionist being asked to draw figurative paintings by the government versus splattering paint in their free time. It's an ironic trap, since our love and pursuit of this hobby is what leads us to coding for work in the first place. And we work for food, so it isn't stopping any time soon....</p>
">
Expand All @@ -30,7 +30,8 @@ <h2>4. Calendarize</h2>
<div id='app'></div>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<script src='../../bundle.js'></script>
<script src="../../rainbow-custom.min.js"></script><!-- Global site tag (gtag.js) - Google Analytics -->
<script src='../../prism.js'></script>
</script><!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-79007755-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
Expand Down
Loading

0 comments on commit 2b384b9

Please sign in to comment.