From f30795f0147802857638ebee06d91a2313e3cf36 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 7 Aug 2024 02:04:57 +0100 Subject: [PATCH] chore: fmt --- .github/workflows/clippy-fmt.yml | 2 +- .prettierrc.yml | 7 ++- ...26c337a88f4e29ae3bb170c4b687208aba20d.json | 6 +-- README.md | 8 ++- auth/casbin/README.md | 1 + auth/simple-auth-server/static/main.js | 14 ++--- basics/static-files/static/root/js/example.js | 12 ++--- cors/backend/README.md | 2 +- cors/frontend/src/main.js | 6 +-- cors/frontend/vite.config.js | 16 +++--- databases/postgres/README.md | 7 +-- graphql/juniper/README.md | 4 +- justfile | 13 +++++ server-sent-events/benchmark.js | 52 +++++++++---------- server-sent-events/drain.js | 25 ++++----- websockets/chat/README.md | 14 ++--- 16 files changed, 100 insertions(+), 89 deletions(-) create mode 100644 justfile diff --git a/.github/workflows/clippy-fmt.yml b/.github/workflows/clippy-fmt.yml index b531a09..ae35050 100644 --- a/.github/workflows/clippy-fmt.yml +++ b/.github/workflows/clippy-fmt.yml @@ -51,6 +51,6 @@ jobs: timeout-minutes: 30 uses: giraffate/clippy-action@v1 with: - reporter: 'github-pr-check' + reporter: "github-pr-check" github_token: ${{ secrets.GITHUB_TOKEN }} clippy_flags: --workspace --all-features --tests diff --git a/.prettierrc.yml b/.prettierrc.yml index 7c7f379..fcd2c8d 100644 --- a/.prettierrc.yml +++ b/.prettierrc.yml @@ -1,8 +1,7 @@ -singleQuote: true -arrowParens: avoid +arrowParens: "avoid" semi: false overrides: - - files: '*.md' + - files: "*.md" options: printWidth: 9999 - proseWrap: never + proseWrap: "never" diff --git a/.sqlx/query-3a5b2a81088aa91ade3106165f926c337a88f4e29ae3bb170c4b687208aba20d.json b/.sqlx/query-3a5b2a81088aa91ade3106165f926c337a88f4e29ae3bb170c4b687208aba20d.json index 2782007..8eee0fd 100644 --- a/.sqlx/query-3a5b2a81088aa91ade3106165f926c337a88f4e29ae3bb170c4b687208aba20d.json +++ b/.sqlx/query-3a5b2a81088aa91ade3106165f926c337a88f4e29ae3bb170c4b687208aba20d.json @@ -22,11 +22,7 @@ "parameters": { "Right": 0 }, - "nullable": [ - false, - false, - false - ] + "nullable": [false, false, false] }, "hash": "3a5b2a81088aa91ade3106165f926c337a88f4e29ae3bb170c4b687208aba20d" } diff --git a/README.md b/README.md index 395a40b..cc1020b 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,13 @@ > Curated examples using the Actix ecosystem. + + [![build status](https://github.com/actix/examples/workflows/CI%20%28Linux%29/badge.svg?branch=master&event=push)](https://github.com/actix/examples/actions) [![Chat on Discord](https://img.shields.io/discord/771444961383153695?label=chat&logo=discord)](https://discord.gg/NWpN5mmg3x) + + ## Community Showcase - [Merino](https://github.com/mozilla-services/merino): Web service for Firefox Suggest. @@ -52,9 +56,9 @@ - [Fullstack-Rust](https://github.com/vascokk/fullstack-rust): A Full Stack Rust application (Connect5 game) with Actix Web, Yew, Bulma CSS and Diesel. - [Mozilla Services Skeleton App](https://github.com/mozilla-services/skeleton) - [rayspace.dev](https://github.com/ryspc/rayspace.dev): Minimalist dev portfolio and blog implemented as a Rust-powered SPA, featuring GitHub OAuth, session management, static file serving, API endpoints, and SQLx integration. -- [Blog with markdown rendering](https://github.com/gemini-15/blog-engine): Blog example built with Actix Web, diesel (with Postgres) and r2d2 rendering articles in markdown with metadata and a front-end with React. +- [Blog with markdown rendering](https://github.com/gemini-15/blog-engine): Blog example built with Actix Web, diesel (with Postgres) and r2d2 rendering articles in markdown with metadata and a front-end with React. - [Rust, Angular, PostgreSQL and JWT Security](https://github.com/stav121/actix-angular-project-template): Boilerplate project that implements an Angular + Actix Web application with login and registration pages, that is pre-dockerized. -- [planters_cycle](https://github.com/grimm-integrations/planters_cycle): Another boilerplate fullstack application with identity system, prisma and NextJs. +- [planters_cycle](https://github.com/grimm-integrations/planters_cycle): Another boilerplate fullstack application with identity system, prisma and NextJs. ## Paid Resources diff --git a/auth/casbin/README.md b/auth/casbin/README.md index 68d7131..44757e4 100644 --- a/auth/casbin/README.md +++ b/auth/casbin/README.md @@ -20,6 +20,7 @@ cargo run (or ``cargo watch -x run``) ``` In this example, you can get the: + - successful result at [http://localhost:8080/success](http://localhost:8080/success) (accessible) - failed result at [http://localhost:8080/fail](http://localhost:8080/fail) (inaccessible, `ERR_EMPTY_RESPONSE`). diff --git a/auth/simple-auth-server/static/main.js b/auth/simple-auth-server/static/main.js index b245cb3..b530b27 100644 --- a/auth/simple-auth-server/static/main.js +++ b/auth/simple-auth-server/static/main.js @@ -1,16 +1,16 @@ function post(url = ``, data = {}) { // Default options are marked with * return fetch(url, { - method: 'POST', // *GET, POST, PUT, DELETE, etc. - mode: 'cors', // no-cors, cors, *same-origin - cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached + method: "POST", // *GET, POST, PUT, DELETE, etc. + mode: "cors", // no-cors, cors, *same-origin + cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached headers: { - 'Content-Type': 'application/json; charset=utf-8', + "Content-Type": "application/json; charset=utf-8", }, - redirect: 'follow', // manual, *follow, error - referrer: 'no-referrer', // no-referrer, *client + redirect: "follow", // manual, *follow, error + referrer: "no-referrer", // no-referrer, *client body: JSON.stringify(data), // body data type must match "Content-Type" header - }).then(response => response.json()); // parses response to JSON + }).then(response => response.json()) // parses response to JSON } // window.addEventListener('load', function() { diff --git a/basics/static-files/static/root/js/example.js b/basics/static-files/static/root/js/example.js index 86d57cb..434c19d 100644 --- a/basics/static-files/static/root/js/example.js +++ b/basics/static-files/static/root/js/example.js @@ -1,7 +1,7 @@ jQuery(document).ready(function () { - let rotation = 0; - jQuery("img").click(function () { - rotation += 360; - jQuery("img").css({'transform': 'rotate(' + rotation + 'deg)'}); - }); -}); + let rotation = 0 + jQuery("img").click(function () { + rotation += 360 + jQuery("img").css({ transform: "rotate(" + rotation + "deg)" }) + }) +}) diff --git a/cors/backend/README.md b/cors/backend/README.md index 865d867..5e0fe04 100644 --- a/cors/backend/README.md +++ b/cors/backend/README.md @@ -11,7 +11,7 @@ cargo run ### web client - [http://localhost:8080/user/info](http://localhost:8080/user/info) - ```json5 + ```json // payload structure { "username": "username", diff --git a/cors/frontend/src/main.js b/cors/frontend/src/main.js index d598101..a2d4544 100644 --- a/cors/frontend/src/main.js +++ b/cors/frontend/src/main.js @@ -1,6 +1,6 @@ // import './assets/main.css' -import { createApp } from 'vue' -import App from './App.vue' +import { createApp } from "vue" +import App from "./App.vue" -createApp(App).mount('#app') +createApp(App).mount("#app") diff --git a/cors/frontend/vite.config.js b/cors/frontend/vite.config.js index 5c45e1d..8bace67 100644 --- a/cors/frontend/vite.config.js +++ b/cors/frontend/vite.config.js @@ -1,16 +1,14 @@ -import { fileURLToPath, URL } from 'node:url' +import { fileURLToPath, URL } from "node:url" -import { defineConfig } from 'vite' -import vue from '@vitejs/plugin-vue' +import { defineConfig } from "vite" +import vue from "@vitejs/plugin-vue" // https://vitejs.dev/config/ export default defineConfig({ - plugins: [ - vue(), - ], + plugins: [vue()], resolve: { alias: { - '@': fileURLToPath(new URL('./src', import.meta.url)) - } - } + "@": fileURLToPath(new URL("./src", import.meta.url)), + }, + }, }) diff --git a/databases/postgres/README.md b/databases/postgres/README.md index a42da2c..5082370 100644 --- a/databases/postgres/README.md +++ b/databases/postgres/README.md @@ -11,8 +11,7 @@ ### NOTE: -You may need to ensure that you are running the commands with the correct SQL user. -On many Linux distributions you may prefix the shell commands with `sudo -u postgres` +You may need to ensure that you are running the commands with the correct SQL user. On many Linux distributions you may prefix the shell commands with `sudo -u postgres` 1. Create database user @@ -25,6 +24,7 @@ On many Linux distributions you may prefix the shell commands with `sudo -u post This step is **optional** and you can also use an existing database user for that. Just make sure to replace `test_user` by the database user of your choice in the following steps and change the `.env` file containing the configuration accordingly. An alternative using SQL: + ```sql CREATE USER test_user WITH PASSWORD 'testing'; ``` @@ -36,6 +36,7 @@ On many Linux distributions you may prefix the shell commands with `sudo -u post ``` An alternative using SQL: + ```sql CREATE DATABASE testing_db OWNER test_user; ``` @@ -54,7 +55,7 @@ On many Linux distributions you may prefix the shell commands with `sudo -u post GRANT ALL PRIVILEGES ON SCHEMA testing TO test_user; GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA testing TO test_user; GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA testing TO test_user; - ``` + ``` 5. Create `.env` file: diff --git a/graphql/juniper/README.md b/graphql/juniper/README.md index 5856c5e..c52f5e2 100644 --- a/graphql/juniper/README.md +++ b/graphql/juniper/README.md @@ -47,9 +47,7 @@ _Mutation example:_ ```graphql mutation { - createHuman( - newHuman: { name: "Fresh Kid Ice", appearsIn: EMPIRE, homePlanet: "earth" } - ) { + createHuman(newHuman: { name: "Fresh Kid Ice", appearsIn: EMPIRE, homePlanet: "earth" }) { id name appearsIn diff --git a/justfile b/justfile new file mode 100644 index 0000000..9d60f68 --- /dev/null +++ b/justfile @@ -0,0 +1,13 @@ +_list: + @just --list + +# Format project. +[group("lint")] +fmt: + cargo +nightly fmt + fd --type=file --hidden --extension=yml --extension=md --extension=js --exec-batch npx -y prettier --write + +# Run Clippy over workspace. +[group("lint")] +clippy: + cargo clippy --workspace --all-targets --all-features diff --git a/server-sent-events/benchmark.js b/server-sent-events/benchmark.js index 85f0854..91860f3 100644 --- a/server-sent-events/benchmark.js +++ b/server-sent-events/benchmark.js @@ -1,73 +1,73 @@ -const http = require('http') +const http = require("http") const n = 120 let connected = 0 let messages = 0 let start = Date.now() -let phase = 'connecting' +let phase = "connecting" let connection_time let broadcast_time -let message = process.argv[2] || 'msg' -let expected_data = 'data: ' + message +let message = process.argv[2] || "msg" +let expected_data = "data: " + message for (let i = 0; i < n; i++) { http .get( { - host: '127.0.0.1', + host: "127.0.0.1", port: 8080, - path: '/events', + path: "/events", }, - (response) => { - response.on('data', (data) => { + response => { + response.on("data", data => { if (data.includes(expected_data)) { messages += 1 - } else if (data.includes('data: connected\n')) { + } else if (data.includes("data: connected\n")) { connected += 1 } }) - } + }, ) - .on('error', (_) => {}) + .on("error", _ => {}) } setInterval(() => { - if (phase === 'connecting' && connected === n) { + if (phase === "connecting" && connected === n) { // done connecting - phase = 'messaging' + phase = "messaging" connection_time = Date.now() - start } - if (phase === 'messaging') { - phase = 'waiting' + if (phase === "messaging") { + phase = "waiting" start = Date.now() http .request( { - method: 'POST', - host: '127.0.0.1', + method: "POST", + host: "127.0.0.1", port: 8080, - path: '/broadcast/' + message, + path: "/broadcast/" + message, + }, + response => { + response.on("data", _ => {}) }, - (response) => { - response.on('data', (_) => {}) - } ) .end() } - if (phase === 'waiting' && messages >= n) { + if (phase === "waiting" && messages >= n) { // all messages received broadcast_time = Date.now() - start - phase = 'paused' + phase = "paused" messages = 0 - phase = 'messaging' + phase = "messaging" } - process.stdout.write('\r\x1b[K') + process.stdout.write("\r\x1b[K") process.stdout.write( - `Connected: ${connected}, connection time: ${connection_time} ms, total broadcast time: ${broadcast_time} ms` + `Connected: ${connected}, connection time: ${connection_time} ms, total broadcast time: ${broadcast_time} ms`, ) }, 20) diff --git a/server-sent-events/drain.js b/server-sent-events/drain.js index 9031e50..1f8849c 100644 --- a/server-sent-events/drain.js +++ b/server-sent-events/drain.js @@ -1,41 +1,42 @@ -const http = require('http') +const http = require("http") let drop_goal = 5_000 let dropped = 0 let query = { - method: 'POST', - host: '127.0.0.1', + method: "POST", + host: "127.0.0.1", port: 8080, - path: '/events', + path: "/events", } setInterval(() => { if (dropped < drop_goal) { let request = http - .request(query, (response) => { - response.on('data', (data) => { - if (data.includes('data: connected\n')) { + .request(query, response => { + response.on("data", data => { + if (data.includes("data: connected\n")) { // drop connection after welcome message dropped += 1 request.abort() } }) }) - .on('error', () => {}) + .on("error", () => {}) .end() } }, 0) setInterval(() => { - http.request({ ...query, path: '/' }, () => print_status(true)) + http + .request({ ...query, path: "/" }, () => print_status(true)) .setTimeout(100, () => print_status(false)) - .on('error', () => {}) + .on("error", () => {}) }, 20) function print_status(accepting_connections) { - process.stdout.write('\r\x1b[K') + process.stdout.write("\r\x1b[K") process.stdout.write( - `Connections dropped: ${dropped}, accepting connections: ${accepting_connections}` + `Connections dropped: ${dropped}, accepting connections: ${accepting_connections}`, ) } diff --git a/websockets/chat/README.md b/websockets/chat/README.md index ce743a5..db1b23a 100644 --- a/websockets/chat/README.md +++ b/websockets/chat/README.md @@ -31,13 +31,13 @@ cargo run --bin websocket-chat-server ## WebSocket Browser Client -Open url: [http://localhost:8080/](http://localhost:8080/) -Use two tabs to set up a proper conversation. +- Open in browser: . +- Use two tabs to set up a proper conversation. ## Python Client using aiohttp -Client connects to server. Reads input from stdin and sends to server. -Create a venv environment `python3 -m venv venv` -Launch venv environment `source ./venv/bin/activate` -Fetch the needed python libraries `pip3 install -r requirements.txt` -Then start client as `./client.py` +- Client connects to server. Reads input from stdin and sends to server. +- Create a venv environment `python3 -m venv venv`. +- Launch venv environment `source ./venv/bin/activate`. +- Fetch the needed python libraries `pip3 install -r requirements.txt`. +- Then start client as `./client.py`.