Fifthtry

Shell

So we have a bunch of software installed, and we are going to enter our zsh, its time to configure it a bit, here is .zshrc for fifthtry:

source auto.sh
test -f ~/.zshrc && source ~/.zshrc
export HISTFILE=~/.zsh_history
export PS1="]$PS1"

Here I am doing a bit of cheating and using personal zshrc, this is a debt, will be moving stuff in project directory.

The main thing we do is source auto.sh.

auto.sh

This is shell script that “source into the current shell”, which auto.sh to setup environment variables etc. Lets take a look at fifthtry’s auto.sh:

export PROJDIR=${PROJDIR:-$(git rev-parse --show-toplevel)}
export IN_NIX_SHELL=${IN_NIX_SHELL:-nopes}
export PYTHONPATH=${PROJDIR}/dj

export PATH=${PROJDIR}/venv/bin:${PROJDIR}/.cargo/bin:$PATH

export DATABASE_URL=postgres://[email protected]/amitu_heroku
export CARGO_HOME="${PROJDIR}/.cargo";

export REALM_WATCHER_DIR="./fifthtry/frontend/"
export REALM_WATCHER_DOIT_CMD="doit fifthtry:iframe"
export REALM_WATCHER_IFRAME="static/fifthtry/iframe.js"

setup() {
    pushd2 /

    test -f venv/bin/python || python3 -m venv venv
    test -f venv/bin/doit || pip install -r requirements.txt
    test -f .git/hooks/pre-commit || pre-commit install

    mkdir -p .cargo
    test -f .cargo/bin/diesel || cargo install diesel_cli --no-default-features --features postgres

    doit
    popd2
}

pushd2() {
    PUSHED=$(pwd)
    cd "${PROJDIR}""$1" >> /dev/null || return
}

popd2() {
    cd "${PUSHED:-$PROJDIR}" >> /dev/null || return
    unset PUSHED
}

o() {
    cd "${PROJDIR}" || return
}

manage() {
    pushd2 /dj
    python manage.py "$@"
    r=$?
    popd2
    return ${r}
}

migrate() {
    pushd2 /dj
    python manage.py migrate "$@"
    r=$?
    popd2
    return ${r}
}

dodo() {
    pushd2 /
    doit "$@"
    r=$?
    popd2
    return ${r}
}

recreatedb() {
    pushd2 /
    psql -U postgres -c "CREATE USER root;"
    psql -U postgres -c "ALTER USER root WITH SUPERUSER;"
    psql -c "DROP DATABASE IF EXISTS amitu_heroku;" template1
    psql -c "CREATE DATABASE amitu_heroku" template1
    psql -c "CREATE EXTENSION IF NOT EXISTS citext;" amitu_heroku

    echo "    -> running django migration"
    # shellcheck disable=SC2119
    migrate

    psql -c "ALTER SCHEMA public RENAME TO the_public_schema;" amitu_heroku

    pg_dump amitu_heroku --schema='the_public_schema' --schema-only -f schema.sql
    psql -c "ALTER SCHEMA the_public_schema RENAME TO public;" amitu_heroku

    sed -i -e 's/the_public_schema/test/g' schema.sql
    sed -i -e 's/test.citext/public.citext/g' schema.sql
    psql -d amitu_heroku -f schema.sql  # create initial test schema

    echo "    -> copying amitu_heroku db into fifthtry_local"

    echo "    -> updating schema.rs"
    rust_schema fifthtry

    echo "    -> all done"
    popd2
}

check() {
    pushd2 /
    sh scripts/clippy.sh
    sh scripts/django-check.sh
    flake8 --ignore=E501,W503 --max-line-length=88
    black --check dj
    popd2
}

djshell() {
    manage shell_plus --ipython
}

dbshell() {
    manage dbshell
}

rust_schema() {
    pushd2 /"$1"_db
    python ../scripts/create_diesel_toml.py "$@"
    diesel print-schema > src/schema_pg.rs
    sed -i -e 's/Citext/realm::base::sql_types::Citext/g' src/schema_pg.rs
    popd2
}

alias open=/usr/bin/open
alias gst="git status"
alias gd="git diff"
alias gp="git push"

setup

We will go through details when they become relevant in tutorial, for now we will focus on the setup function.

setup() {
    pushd2 /

    test -f venv/bin/python || python3 -m venv venv
    test -f venv/bin/doit || pip install -r requirements.txt
    test -f .git/hooks/pre-commit || pre-commit install

    mkdir -p .cargo;
    test -f .cargo/bin/diesel || cargo install diesel_cli --no-default-features --features postgres

    doit
    popd2
}

We first create virtual environment if it does not exists.

Then we install python dependencies, if doit is not found. We do this directly only the first time the project setup, subsequently we will always do this via doit, which I will discuss later.

Then we install diesel cli, which we will again get to later.

We then run doit to do its stuff. Lets read about doit in next section.

So our shell and shell functions are setup, let’s take a look at doit, our “software builder”.

Table Of Content

What is Realm?

A Bit On Motivation

Routing is Hard

What does Realm do?

Backend Data And Type Safety

Tutorial

Quick Start Realm Tutorial

In Depth Tutorial (not ready)

Nix
Shell
Doit
Hello Rust
Hello Elm
Hello Static Files
Hello Server Side Rendering
Pre-Commit Hooks

Routing, Request And Response

Frontend, Data, Navigation, And APIs

How To Guides

File Upload

Backend: S3 File Upload
Authenticated File Serving
Frontend: Uploading Files From Elm

How to use storybook?

How to implement “loading..”?

Docs

Realm.In

Realm.Storybook.Story

realm::In

realm::Context

realm::Result

realm.magicSlice

realm::RequestConfig

Environment Variables

Internals - Only for Realm Developers, not Users

“Realm DATA”
iFrame Controller
Shutdown Routine
Testing Internals

Change Log

Get Realm Starter Working

Transparent Offline Feature

How to make http requests in Realm?

Development

Tutorial: ToDo App

Realm Testing

Enhance Realm Starter

Double Load Issue

Deploy To Heroku Button

End failure

Realm-Starter Github Template

Proposal: Tracker And Visit

Proposal: Activity Store

Proposal: Bundling

Proposal: Retry On Network Error

Storybook: Editable JSON

Storybook: Notes

Storybook: Reference

Backlog

Readings

Change Log

How to Publish

Testing

Code Snippets

Skip rustfmt For Some Section

Close Modal Dialog When Clicked Outside

Ignoring Lints In Python

Ignoring Lints (clippy and rustc warnings) In Rust

Handle DateTime in Rust & Elm

Handle CiText value read in Rust

Transport Enum Type to and fro Rust/Elm through JSON