Skip to content

Instantly share code, notes, and snippets.

@nathanl
nathanl / jeg_stateful_web_applications.md
Last active October 31, 2019 16:48
James Edward Gray II describing the ability to build *stateful* web application in Elixir

James Edward Gray II

Quote from Elixir Mix 63 - "063: Designing Elixir Systems With OTP with Bruce Tate and James Gray", starting at 01:03:13

"I've worked at a bunch of companies building web apps for a long time, and I keep seeing this same pattern, and it haunts me. In the web world, all we want is these long interactions with people, and we live in this stateless world. So what we do is, the first part of every request, we do thirty queries to re-establish the state of the world that we just forgot a few seconds ago after the last request. And then we go forward and make one tiny step forward, and then we forget everything again, so that when the next request comes in we can do thirty queries to put it all back and make one more tiny step. And I kept thinking, "there has to be a better way than this, right?"

And if you look at web advancements over the years, most of the things we're doing are

@teamon
teamon / box.ex
Created August 25, 2017 23:09
Define elixir structs with typespec with single line of code
defmodule Box do
defmacro __using__(_env) do
quote do
import Box
end
end
@doc """
Define module with struct and typespec, in single line
@yaycode
yaycode / 0 - instachat.md
Last active April 29, 2023 02:57
Elixir + Phoenix : Creating a simple chatroom

Instachat

The Phoenix Framework was built with realtime communication as a first class priority. Using its built in socket handling and channels we can implement a basic, realtime chat application with little effort.

For this video we’re going to assume that you already have Elixir and Phoenix Setup. You will not need a database as the messages will not be persisted. This tutorial is taken pretty much directly from the Phoenix Documentation.

Setting up the app

To start let’s generate a standard phoenix application:

$> mix phoenix.new instachat
@gigamonkey
gigamonkey / criteria.txt
Last active January 5, 2020 06:21
Hiring criteria: looking for the ability to …
Write a program that does what it’s supposed to do
Write idiomatic code
Debug a program that you wrote
Debug a program someone else wrote
Debug the interaction between a system you wrote and one you didn’t
File a good bug report
Modify a program you didn’t write
Test a program you wrote
Test a program you didn’t write
Learn a new programming language
@rbishop
rbishop / README.md
Last active April 26, 2022 15:38
A super simple Elixir server for sending Server Sent Events to the browser.

Generate a new Elixir project using mix and add cowboy and plug as dependencies in mix.exs:

  defp deps do
    [
      {:cowboy, "~> 1.0.0"},
      {:plug, "~> 0.8.1"}
    ]
  end
def index(conn, %{"event" => "true"}) do
conn = conn
|> put_resp_content_type("text/event-stream")
|> send_chunked(200)
{:ok, conn} = chunk(conn, ["data: ", JSON.encode!(Thermostat.Data.get()), "\n\n"])
Phoenix.Topic.subscribe self, "data"
data_updated(conn)
end
defp data_updated(conn) do
@mlynch
mlynch / auth.markdown
Last active September 4, 2020 18:11
AngularJS Authentication and CORS

Single Page Apps are ruling the world and AngularJS is leading the charge. But many of the lessons we learned in the Web 2.0 era no longer apply, and few are as drastically different as authentication.

CORS

CORS is an oft-misunderstood feature of new browsers that is configured by a remote server. CORS stands for Cross-Origin-Resource-Sharing, and was designed to make it possible to access services outside of the current origin (or domain) of the current page.

Like many browser features, CORS works because we all agree that it works. So all major browsers like Chrome, Firefox, and IE support and enforce it. By using these browsers, you benefit from the security of CORS.

That means certain browsers do not enforce it, so it is not relevant there. One large example is a native Web View for things like Cordova and Phonegap. However, these tools often have configuration options for whitelisting domains so you can add some security that way.

@rob-brown
rob-brown / ElixirConf2014.md
Last active December 4, 2020 05:38
Notes from ElixirConf 2014

ElixirConf 2014

Dave Thomas—Opening Keynote

Twitter | Slides

Think different(ly)

Get out of your rut and learn new ways to think.

/*!
* jQuery JavaScript Library v2.1.1pre
* http://jquery.com/
*
* Includes Sizzle.js
* http://sizzlejs.com/
*
* Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors
* Released under the MIT license
* http://jquery.org/license