Skip to content

Instantly share code, notes, and snippets.

View neslinesli93's full-sized avatar
🏠
Working from home

Tom neslinesli93

🏠
Working from home
View GitHub Profile
@neslinesli93
neslinesli93 / router.ex
Last active January 2, 2020 20:17
Add plug to the router
pipeline :browser do
# ...other plugs
plug :fetch_flash
plug Phoenix.LiveView.Flash
end
@neslinesli93
neslinesli93 / endpoint.ex
Last active January 2, 2020 20:18
Add new websocket endpoint
defmodule BreakoutexWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :breakoutex
socket "/live", Phoenix.LiveView.Socket, websocket: [timeout: 45_000]
# ...rest of the module
end
@neslinesli93
neslinesli93 / config.exs
Last active January 2, 2020 20:18
Endpoint config
config :breakoutex, BreakoutexWeb.Endpoint,
# ...other settings
live_view: [signing_salt: "SIGNING_SALT"]
@neslinesli93
neslinesli93 / package.json
Created September 29, 2019 12:32
Phoenix LiveView frontend deps
{
"dependencies": {
"phoenix": "file:../deps/phoenix",
"phoenix_html": "file:../deps/phoenix_html",
"phoenix_live_view": "file:../deps/phoenix_live_view"
}
}
@neslinesli93
neslinesli93 / app.js
Created September 29, 2019 12:35
Complete app.js for Phoenix LiveView
import "../css/app.css";
import { Socket } from "phoenix";
import LiveSocket from "phoenix_live_view";
let liveSocket = new LiveSocket("/live", Socket);
liveSocket.connect();
WITH values as (
SELECT
0 as value,
'' as label,
to_date('00000101','YYYYMMDD') as time
UNION ALL
SELECT
(close - open) / close as value,
to_char(time, 'Mon') || ' ' || to_char(time, 'YYYY') as label,
time
@neslinesli93
neslinesli93 / level_example.ex
Created January 2, 2020 20:21
An example for representing a level in Elixir
level = [
~w(X X X X X X X X X X X X X X X X X X X X X X X X X X),
~w(X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X),
~w(X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X),
~w(X r 0 0 r 0 0 r 0 0 r 0 0 r 0 0 r 0 0 r 0 0 r 0 0 X),
~w(X b 0 0 b 0 0 b 0 0 b 0 0 b 0 0 b 0 0 b 0 0 b 0 0 X),
~w(X g 0 0 g 0 0 g 0 0 g 0 0 g 0 0 g 0 0 g 0 0 g 0 0 X),
~w(X o 0 0 o 0 0 o 0 0 o 0 0 o 0 0 o 0 0 o 0 0 o 0 0 X),
~w(X p 0 0 p 0 0 p 0 0 p 0 0 p 0 0 p 0 0 p 0 0 p 0 0 X),
~w(X y 0 0 y 0 0 y 0 0 y 0 0 y 0 0 y 0 0 y 0 0 y 0 0 X),
@neslinesli93
neslinesli93 / mix.exs
Created January 2, 2020 20:25
Add UUID library to mix.exs
defp deps do
[
# ...other deps
{:elixir_uuid, "~> 1.2"}
]
end
@neslinesli93
neslinesli93 / blocks.ex
Created January 2, 2020 20:26
An initial definition of the blocks module
defmodule BreakoutexWeb.Live.Blocks do
@moduledoc """
Module that contains the definitions of all the block types,
as well as functions to init the board
"""
# Expressed in multiple of basic units
@brick_length 3
@spec build_board(list(list(String.t())), number(), number()) :: [map()]
@neslinesli93
neslinesli93 / index.html.eex
Last active January 2, 2020 21:29
Main template
<div class="game-container">
<%= for block <- @blocks, block.type in [:wall, :floor] do %>
<div class="block <%= block.type %>"
style="transform: translate3d(<%= block.left %>px, <%= block.top %>px, 0px);
width: <%= block.width %>px;
height: <%= block.height %>px; "></div>
<% end %>
<%= for brick <- @blocks, brick.type == :brick and brick.visible == true do %>
<div class="block brick"