Skip to content

Instantly share code, notes, and snippets.

@toraritte
toraritte / form.html.eex
Created June 28, 2018 05:51
The generated form via `mix phx.gen.html`
<%= form_for @changeset, @action, fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<!-- "She says ... a bunch of stuff. Look, have you tried drugs?" -->
<% end %>
defmodule PuffinWeb.UserController do
use PuffinWeb, :controller
alias Puffin.Accounts
alias Puffin.Accounts.User
def new(conn, _params) do
changeset = Accounts.change_user(%User{})
render(conn, "new.html", changeset: changeset)
end
defmodule Puffin.Accounts do
@moduledoc """
The Accounts context.
"""
import Ecto.Query, warn: false
alias Puffin.Repo
alias Puffin.Accounts.User
defmodule Puffin.Accounts.User do
use Ecto.Schema
import Ecto.Changeset
schema "users" do
field :name, :string
field :username, :string
timestamps()
#!/bin/sh
PROJECT_NAME=$1
mix phx.new $PROJECT_NAME
cd $PROJECT_NAME
mix phx.gen.html Accounts User users name:string username:string:unique
sed -i '/ get/i \ resources "/users", UserController' lib/${PROJECT_NAME}_web/router.ex
mix ecto.create
mix ecto.migrate
@toraritte
toraritte / firebase-realtime-db-generic-write-rules.md
Created July 11, 2018 19:52
Firebase Realtime Database generic write rules
permissions                   .write rules
----------------------        ------------
create, update, delete  CUD   true  (not using `data` and `newData`)
none                    xxx   false (not using `data` and `newData`)
create only             Cxx   "!data.exists() && newData.exists()"
update only             xUx   "data.exists() && newData.exists()"
delete only             xxD   "data.exists() && !newData.exists()"
create, delete          CxD   "!data.exists() || !newData.exists()"
update, delete xUD "data.exists()"
@toraritte
toraritte / firebase-db-snippets-for-access-news.js
Last active July 13, 2018 00:57
Firebase realtime database snippets for Access News
function catObjects(array) {
if (array.length === 0) {
return {}
}
const obj = array.pop();
return Object.assign(obj, catObjects(array));
}
/* `refString` is basically a db path along the lines of
"users/(uid)/(auto-id)". This function is needed to make
@toraritte
toraritte / add_user_and_reset_password_with_Firebase_admin_on_node.md
Last active May 10, 2024 13:10
Sending password reset email after user has been created with Firebase Admin SDK (Node.js)

Sending password reset email after user has been created with Firebase Admin SDK (Node.js)

1. Install Firebase's Node modules

Install the Firebase Node modules:

$ npm install firebase firebase-admin --save
@toraritte
toraritte / rrs-trs.md
Last active August 1, 2018 16:53
history of telephone reader services

1. How many TR-based programs exist in the US today?

10.5 (Goodwill's New Vision in Virginia mentions a service very similar to TR, but it omits any information on how to access it or how to sign up for that matter.)

There are also 7 active services that have non-TR-based phone access to their content to access the broadcast currently on the air.

2. How many TRP programs have gone out of existence in the past 5 years or so?

4 TR programs and 17 radio reader services went down. Included the radio reader services as well, because most of these programs started out as one and both types face the same challenges.

@toraritte
toraritte / promise-reminder.md
Created August 10, 2018 22:22
JavaScript Promise reminder

Write a promise

const c = 
    function(p) {

        return new Promise( 
            function(resolve, reject) {
                if (p < 7) {