Skip to content

Instantly share code, notes, and snippets.

View HosMercury's full-sized avatar

Hos.Mercury HosMercury

View GitHub Profile
@jeremychone
jeremychone / rust-xp-02-postgresql-sqlx.rs
Created May 11, 2021 05:48
Rust to PostgreSQL with SQLX | Rust By Example
#![allow(unused)] // silence unused warnings while exploring (to comment out)
use sqlx::postgres::{PgPoolOptions, PgRow};
use sqlx::{FromRow, Row};
// Youtube episode: https://youtu.be/VuVOyUbFSI0
// region: Section
// Start postgresql server docker image:
@LukeMathWalker
LukeMathWalker / audit.yml
Last active April 19, 2024 06:56
GitHub Actions - Rust setup
name: Security audit
on:
schedule:
- cron: '0 0 * * *'
push:
paths:
- '**/Cargo.toml'
- '**/Cargo.lock'
jobs:
security_audit:
#![warn(rust_2018_idioms)]
#[derive(Debug)]
pub struct StrSplit<'haystack, D> {
remainder: Option<&'haystack str>,
delimiter: D,
}
impl<'haystack, D> StrSplit<'haystack, D> {
pub fn new(haystack: &'haystack str, delimiter: D) -> Self {
@abou7mied
abou7mied / index.hbs
Created December 26, 2019 06:16
connect-flash + hbs example
<html>
<body>
{{#each messages}}
Message: {{this}}
{{/each}}
</body>
</html>
@bpas247
bpas247 / state-updates-are-async.md
Last active March 17, 2023 17:12
State Updates Are Asynchronous

State Updates Are Asynchronous

The gist of it

You do this.

const handleEvent = e => {
  setState(e.target.value);
  console.log(state);
}
@samsch
samsch / stop-using-jwts.md
Last active April 14, 2024 16:00
Stop using JWTs

Stop using JWTs!

TLDR: JWTs should not be used for keeping your user logged in. They are not designed for this purpose, they are not secure, and there is a much better tool which is designed for it: regular cookie sessions.

If you've got a bit of time to watch a presentation on it, I highly recommend this talk: https://www.youtube.com/watch?v=pYeekwv3vC4 (Note that other topics are largely skimmed over, such as CSRF protection. You should learn about other topics from other sources. Also note that "valid" usecases for JWTs at the end of the video can also be easily handled by other, better, and more secure tools. Specifically, PASETO.)

A related topic: Don't use localStorage (or sessionStorage) for authentication credentials, including JWT tokens: https://www.rdegges.com/2018/please-stop-using-local-storage/

The reason to avoid JWTs comes down to a couple different points:

  • The JWT specification is specifically designed only for very short-live tokens (~5 minute or less). Sessions
@rylev
rylev / learn.md
Created March 5, 2019 10:50
How to Learn Rust

Learning Rust

The following is a list of resources for learning Rust as well as tips and tricks for learning the language faster.

Warning

Rust is not C or C++ so the way your accustomed to do things in those languages might not work in Rust. The best way to learn Rust is to embrace its best practices and see where that takes you.

The generally recommended path is to start by reading the books, and doing small coding exercises until the rules around borrow checking become intuitive. Once this happens, then you can expand to more real world projects. If you find yourself struggling hard with the borrow checker, seek help. It very well could be that you're trying to solve your problem in a way that goes against how Rust wants you to work.

@igorjs
igorjs / rest-api-response-format.md
Last active April 19, 2024 09:38
REST API response format based on some of the best practices
@greyscaled
greyscaled / README.md
Last active September 19, 2022 08:59
Sequelize + Express + Migrations + Seed Starter