Skip to content

Instantly share code, notes, and snippets.

View bettio's full-sized avatar

Davide Bettio bettio

View GitHub Profile
@bettio
bettio / insertlicense.sh
Created January 28, 2022 23:03
Add Apache 2.0 license to all files without license
#!/bin/bash
IFILE=$1
./printlicense.sh $IFILE > "$IFILE.new"
echo "" >> "$IFILE.new"
cat $IFILE >> "$IFILE.new"
mv "$IFILE.new" $IFILE
@bettio
bettio / morse_encoder.ex.patch
Created March 7, 2020 22:54
Elixir morse encoder example - step 7
<html>
+ <head>
+ <link rel="stylesheet" href="/milligram.min.css">
+ </head>
<body>
+ def handle_req('GET', ['milligram.min.css'], conn) do
+ :http_server.reply(200, :atomvm.read_priv(:morse_encoder, 'milligram.min.css'), conn)
+ end
+
@bettio
bettio / morse_encoder.ex
Created March 7, 2020 22:51
Elixir morse encoder example - step 6
defp blink_led(nil, _l) do
:ok
end
defp blink_led(gpio_num, l) do
gpio = get_gpio()
GPIO.set_direction(gpio, gpio_num, :output)
Enum.each(l, fn e ->
case e do
@bettio
bettio / encoder_test.exs
Created March 7, 2020 22:48
Elixir morse encoder example - step 5
defmodule EncoderTest do
use ExUnit.Case
alias MorseEncoder.Encoder
test "encode hello world" do
assert Encoder.morse_encode('HELLO') == '.... . .-.. .-.. --- '
end
end
@bettio
bettio / encoder.ex
Created March 7, 2020 22:43
Elixir morse encoder example - step 4
defmodule MorseEncoder.Encoder do
def morse_encode(s) do
:string.to_upper(s)
|> Enum.map(&to_morse/1)
|> List.flatten()
end
defp to_morse(c) do
case c do
?\s -> ' '
@bettio
bettio / morse_encoder.ex
Created March 7, 2020 22:39
Elixir morse encode example - step 3
def handle_req('GET', [], conn) do
body = """
<html>
<body>
<h1>Morse Encoder</h1>
<form method=\"post\">
<p>Text: <input type=\"text\" name=\"text\"></p>
<p>GPIO: <input type=\"text\" name=\"gpio\"></p>
<input type=\"submit\" value=\"Submit\">
</form>
@bettio
bettio / morse_encoder.ex
Created March 7, 2020 22:30
Elixir morse encode example - step 2
def start() do
connect()
end
def connect() do
this_process = self()
config = [
{:sta,
[
@bettio
bettio / mix.exs.patch
Created March 7, 2020 22:23
Elixir morse encode example - step 1
# Run "mix help deps" to learn about dependencies.
defp deps do
[
+ {:exatomvm, github: "bettio/exatomvm", runtime: false}
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
- deps: deps()
+ deps: deps(),
@bettio
bettio / UDPHelloWorld.ex
Created November 30, 2018 00:59
UDP hello world on https://github.com/bettio/atomvm (works on d6c6d54d607e5d8ca5af7447fa53f3d4e1647db4)
defmodule UDPHelloWorld do
@remote_ip {192, 168, 0, 2}
@port 8981
# @ssid 'YourSSID'
# @psk 'YourPassword'
def start() do
# You should connect to a network and sleep some seconds
@bettio
bettio / Blink.ex
Created November 22, 2018 19:44
Blinking a Led in Elixir on ESP32 with AtomVM