• Stars
    star
    3,017
  • Rank 14,327 (Top 0.3 %)
  • Language
    Elixir
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A walk through the Elixir language in 30 exercises.

30 Days of Elixir

A walk through the Elixir language, one exercise per day for 30 days.

Frequently Asked Question:

How am I supposed to use this?

I'm not sure! I originally wrote these exercises as I was learning the language myself. I don't know if merely reading them will be of much use though. I recommend you open each file in your favorite editor, change it, break it, rewrite the code in your own style, etc. Experiment, and if you find a mistake, then bonus points for you!

You have to start somewhere.

01-hello-world.exs - We start at the very beginning: our first message to the world!

02-unit-testing.exs - We'll need unit testing for the rest of the exercises, so let's do this! The built-in unit testing library ExUnit is capable and easy-to-use.

03-input-output.exs - Here we learn that file input and user input are easy. JosΓ© has even done us a solid and duplicated some familiar Path and File methods from Ruby.

04-list.exs - What's a functional language without a List? Here we learn some simple list manipulation, and for awhile we can pretend lists are like our familiar Ruby arrays. :-)

05-map.exs - Maps are the go-to key-value structure in Elixir, and the syntax is fairly simple coming from other dynamic languages.

06-record.exs - Where are our beloved objects? In functional programming, data is just data, and Elixir gives you the Record structure to organize it a bit. Records are a little like Struct from other imperative languages, except of course they are immutable!

07-fibonacci.exs - You learn recursion by using recursion! We learn about multiple methods of the same name, pattern matching, and guard clauses, cool! Finally we do it all over again, backwards! (Hey, why not?)

Learning is a Process.

08-process-ring.exs - Sometimes a contrived example is the best way to focus on the technology. For now, let's just send messages around in a ring and see how this Process thing works.

09-ping.exs - Now let's build something useful! Wow, it's easy to launch as many processes as you have increments of work. When the work is finished, send a message back to the parent and he'll assemble the results. Cool!

So, do you Sudoku?

10-sudoku-board.exs - No objects? Pshaaw! Who needs 'em - let's use simple lists to represent our Sudoku board. Easy!

11-sudoku-solver.exs - Epic fail. Our code is pretty, but the algorithm is naive and too slow to use on a full-size board.

12-sudoku-solver-norvig.exs - Time to bring out the big guns! Here we port Peter Norvig's Holy Grail of a Solver over to Elixir. We learn how to change imperative operations on mutable state to functional ones on immutable data. This solver is freakin' fast!

Spades, cuz they look like little shovels!

13-card-deck.exs - Let's see how we might represent a deck of cards. Easy, a list of tuples! We'll also build a higher-order function to deal out the cards to players.

14-spades.exs - They're aliiiiive! Processes connect to one another and send messages, across terminal windows, machines, even teh intarwebs! Let's put this to good use and build a multi-player game of Spades. Ace of Spades FTW!

Tease your brain, but don't be a bully.

15-quine.exs - A quine is a program that prints its own source code. Let's build the smallest one we can using Elixir... sigils help a lot!

16-euler-tree.exs - Project Euler problem 67 is a fun puzzle; let's solve it with a functional language! We'll make extensive use of list comprehensions in this one.

17-dining-philosophers.exs - Pass the fork! The actor model makes certain problems a lot easier to reason about, and feeding some philosophers is one of them.

OTP, hey you know me!

18-gen_server.exs - Here we move up a level and build a Prime Factors server using OTP GenServer behaviour.

19-supervisor.exs - This one is simple: when our Prime Factors server craps out, restart it. Easy!

Let's build a web...

20-inets.exs - Erlang's built-in inets library is nothing to be amazed by, but it gets the job done. We'll simply announce ourselves to the world again, this time via HTTP.

21-wiki.exs - Now let's build something useful, combining our knowledge of inets and some simple File IO to build a wiki web server.

22-socket-server.exs - "I don't always build web apps, but when I do, I use low-level sockets and parse the HTTP headers myself," said no one, ever. Turns out gen_tcp is pretty easy to use if you want to handle socket communication.

What's this doing here?

23-digest.exs - Erlang/OTP has so many things to offer, yet simple hexdigest using sha1 isn't one of 'em. At least we get to learn one way to import external Erlang code and run it in Elixir, so not all is lost.

24-stream.exs - Let's build a better Fibonacci method using lazy streams. You can tell our understanding of the language has improved, as the amount of code to implement this is 1/10th of the size of our first foray into Fibonacci!

25-set.exs - We'll learn about the built-in HashSet library, just for fun.

The Rat Pack didn't have Macros.

26-frank.exs - Here we'll make a brief incursion into the land of macros. In this exercise, we'll build a web DSL with custom syntax. This first try we'll just use a macro to write a method. quote/unquote confounds a bit.

27-frank-2.exs - This version of Frank is only a little better, but lets our path matches contain any character and utilizes pattern matching to grab the right handler method. But here we're still struggling with quote/unquote et al. What does it all mean?

28-frank-3.exs - Macros are starting to make a little more sense now. The final version of Frank can handle patterns in the URL, e.g. /foo/:id and our macro code got simpler!

You'll never learn if you don't Trie.

29-vector.exs - For our last couple of exercises, let's do something completely different! Elixir has a list data structure, but no Vector, so let's create one... our first attempt has us learning about Hash Array Mapped Trie (HAMT), and as it turns out, using this structure for a vector wasn't the best idea.

30-vector.exs - Take 2... Thanks to Jean Niklas L'orange's excellent articles about Clojure's Vectors, we learn how to build a Bit Partitioned Vector Trie. And now, we have a Vector with constant-time access. Cool stuff!

Copyright & License

Copyright (c) Tim Morgan

Licensed under MIT, see LICENSE file.

More Repositories

1

onebody

private member portal for churches, built with Ruby on Rails
Ruby
1,400
star
2

do-install-button

NO LONGER MAINTAINED
HTML
611
star
3

natalie

a unique Ruby implementation, compiled to C++ (WIP)
Ruby
530
star
4

bible_api

Ruby web app that serves JSON API for open and public domain bibles
Ruby
499
star
5

open-bibles

Repository of public domain and freely (libre) licensed bible translations in some standard XML formats.
Python
251
star
6

justforfunnoreally.dev

A little website to explain that sometimes we just like to have fun!
HTML
85
star
7

bible_parser

parse different bible formats with Ruby
Ruby
49
star
8

malcc

Mal (Make A Lisp) Compiler in C
C
45
star
9

sooner.io

NO LONGER MAINTAINED - a distributed job scheduling engine and web-based management app
CoffeeScript
39
star
10

old-churchio-website

The website of Church.IO
HTML
23
star
11

hackernews

Ruby library for scripting the Hacker News website (http://news.ycombinator.com).
Ruby
22
star
12

rpi-clock

very simple clock and weather page for raspberry pi - NO LONGER MAINTAINED
CSS
21
star
13

wuparty

Lightweight Ruby wrapper for Wufoo REST API v3 over HTTP using HTTParty
Ruby
19
star
14

load_and_authorize_resource

Auto-loads and authorizes resources in your Rails controllers
Ruby
18
star
15

mini

Tim's [VERY OLD] Mini JavaScript Library
JavaScript
18
star
16

checkin-printer

This is a tiny bit of software that allows the Church.IO Checkin System to print remotely to a DYMO LabelWriter controlled by a Raspberry Pi.
JavaScript
18
star
17

dymo-printer-agent

print label XML to a Dymo printer on Linux (or any platform)
Ruby
17
star
18

bible_ref

Parser for bible passage/ranges
Ruby
14
star
19

sidekiq-clutch

An ergonomic wrapper API for Sidekiq Pro Batches
Ruby
14
star
20

mal-rust

My own Rust implementation of Mal (Make a Lisp)
Rust
14
star
21

sinatra-appengine-example

Example of a Sinatra app for Google AppEngine (JRuby) from http://blog.bigcurl.de/2009/04/running-sinatra-apps-on-google.html
Ruby
12
star
22

rpi-check-in-printer

Set up a Raspberry Pi as a Planning Center Check-ins Printer Station for Dymo label printers
Shell
11
star
23

mya

WIP statically-typed subset of Ruby (maybe)
Ruby
10
star
24

simple_restful_openid

Rails plugin that generates an uber simple, restful openid login controller.
Ruby
10
star
25

scheme-vm

a work-in-progress R7RS scheme implementation
Ruby
9
star
26

cascading_rubies

Ruby DSL for generating CSS. THIS IS NO LONGER MAINTAINED
Ruby
8
star
27

type_inference_experiment

A little toy compiler so I can play with type inference
Ruby
7
star
28

flickr_party

Wrapper for the Flickr API, with real application authentication, using HTTParty
Ruby
6
star
29

image_hash_ruby

a simple perceptual image hashing library
Ruby
6
star
30

froman

Run Sidekiq/Resque workers for multiple apps only when there is work to be done.
Rust
6
star
31

lydia

an interpreted functional language for learning
C
6
star
32

trac_wiki_to_github

A rough start of a Ruby script to help convert Trac wiki syntax to GitHub friendly syntax. DOES NOT SUPPORT NEW GIT-BACKED WIKIS.
Ruby
6
star
33

has_one_photo

Super simple photo support for AR models using MiniMagick - THIS IS NO LONGER MAINTAINED
Ruby
5
star
34

flickr-upload-set

Browse your computer hard drive for photos that are not yet on your Flickr account.
Ruby
5
star
35

onebody-sync

scripts to export data from other Church Management System databases to OneBody
Ruby
4
star
36

.emacs.d

My Emacs configs, and a live blog of my experience switching from Vim to Emacs
Emacs Lisp
4
star
37

quine

Some Ruby Quines
Ruby
4
star
38

facebook_party

Lightweight wrapper for Facebook API using HTTParty.
Ruby
4
star
39

prawn_template_handler

Uber simple template handler for Prawn PDF views in Rails. THIS IS NO LONGER MAINTAINED; please check out https://github.com/Volundr/prawn-rails
Ruby
4
star
40

openwar

turn-based strategy game written in SVG and JavaScript
CoffeeScript
3
star
41

onebody-mobile

A mobile app for OneBody
CSS
3
star
42

jqtal

jQuery Template Attribute Language
JavaScript
3
star
43

honcho

Sidekiq- and Resque-aware process manager for your dev environment (alternative to Foreman)
Ruby
3
star
44

crk

Corkboard App built with Node.js, Backbone.js, and Socket.io
JavaScript
3
star
45

simple_sinatra_openid

example Sinatra app with OpenID authentication
Ruby
3
star
46

whiteboard_icons

Icons with a certain fat, hand-drawn marker look. Actually drawn on my whiteboard.
Ruby
3
star
47

onebody-mobile-old

WebView wrapper for OneBody
Objective-C
2
star
48

tulsarb.org

Old website of the Tulsa Ruby User Group
Ruby
2
star
49

path-download

Download your entire feed from Path before they disappear on Oct 18, 2018
JavaScript
2
star
50

tm

Some basic data structures for C++ projects
C++
2
star
51

snake-term

A simple ASCII "snake" game in the terminal, written in < 100 lines of Ruby
Ruby
2
star
52

my_snippets

I was fed up with dzone snippets, and decided to write my own. ABANDONED -- just use GitHub Gists. :-)
Ruby
2
star
53

attr_accessible_if

Pass an :if Proc to the attr_accessible class method to change what attributes are accessible depending on, for example, who is logged in.
Ruby
2
star
54

usfx

Ruby SAX stream parser for Unified Scripture Format XML (USFX)
Ruby
2
star
55

natalie-lang.org

Just a simple website for Natalie
JavaScript
2
star
56

lisp200

200 LOC Lisp implementation in Ruby
Ruby
2
star
57

ragchew.app

A website for amateur radio operators to find and participate in on-the-air gatherings
Ruby
2
star
58

hook.io-fswatcher

filesystem watcher for Hook.io (supports inotify on Linux)
CoffeeScript
2
star
59

exceptioncollection

My first AppEngine app. It collects exceptions in Rails apps, ala Hoptoad and Exceptional, but has about 10% of the features.
2
star
60

adventofcode

Advent of Code exercises
Ruby
1
star
61

html5-todo-app

demo app for presentation at September 2011 meeting of TulsaWebDevs
JavaScript
1
star
62

snake-gosu

Snake game written in Ruby and Gosu
Ruby
1
star
63

dlopen_test

Just testing dlopen, dlsym, et al
C
1
star
64

onebody-help

Help Guides - NO LONGER MAINTAINED
1
star
65

natalie-spec-stats-api

a tiny sinatra app for tracking our ruby/spec stats
Ruby
1
star
66

plusone-test

Just testing the plusone bot
1
star
67

bulk_bundler

Install dependencies for multiple Gemfile.lock files in one go. Or maybe don't.
Ruby
1
star
68

boardslam-c

Classical Conversations Board Slam math game calculator
C
1
star
69

microbit-services-live

Control Planning Center Services LIVE with a micro:bit
JavaScript
1
star
70

pco_giving_labels

Set labels on donations in Planning Center Giving based on campus in Planning Center People.
Ruby
1
star
71

rust-ruby-wrap-data

set a pointer to a Rust heap-allocated value on your Ruby object and get it back out again
Rust
1
star
72

nvim

my neovim config
Lua
1
star
73

robots-chatting-with-other-robots

Simple Node.js chat server based on Socket.io, with Robot avatars thanks to robohash.org
JavaScript
1
star