Skip to content

Instantly share code, notes, and snippets.

@squarism
squarism / main.rs
Last active June 3, 2023 17:55
Railroad Error Handling in Rust
// User password resets could benefit from railroad error handling
// because there are so many things to go wrong along the way
//
// 1. I forgot my password, send me a link
// 2. I got the link, let me enter a new password
// 3. Password and confirmation must match
// 4. Password must be at least 8, etc
// 5. Password was saved successfully
//
// There are many things that can go wrong and having a transaction
@squarism
squarism / .gitlab-ci.yml
Created May 30, 2023 21:37
Gitlab and Vitest Code Coverage with c8
# stages:
# - whatever
# - test
vitest:
stage: test
script:
# assuming scripts: has "test": "vitest" ...
# run your tests with coverage output
- npm test -- run --coverage
@squarism
squarism / main.rs
Created May 28, 2023 20:30
Mocking in Rust with a working mockall example
#[cfg(test)]
use mockall::{automock, predicate::*};
pub struct Visa {}
#[cfg_attr(test, automock)]
pub trait Chargable {
fn charge_credit_card(&self) -> u32;
}
@squarism
squarism / eat_my_shorts.txt
Created January 5, 2023 01:55
Eat My Shorts - Block Youtube Shorts with uBlock Origin
! youtube shorts
www.youtube.com###guide-content #endpoint[title="Shorts"]:upward(ytd-guide-entry-renderer)
www.youtube.com###items #endpoint[title="Shorts"]:upward(ytd-mini-guide-entry-renderer)
www.youtube.com##ytd-browse ytd-grid-video-renderer:has(span.ytd-thumbnail-overlay-time-status-renderer:has-text(/\s(0:\d\d|1:0\d)\s/))
www.youtube.com##ytd-browse ytd-rich-item-renderer:has(span.ytd-thumbnail-overlay-time-status-renderer:has-text(/\s(0:\d\d|1:0\d)\s/))
www.youtube.com##ytd-search ytd-video-renderer:has(span.ytd-thumbnail-overlay-time-status-renderer:has-text(/\s(0:\d\d|1:0\d)\s/))
www.youtube.com##ytd-watch-next-secondary-results-renderer ytd-compact-video-renderer:has(span.ytd-thumbnail-overlay-time-status-renderer:has-text(/\s(0:\d\d|1:0\d)\s/))
www.youtube.com##ytd-browse ytd-grid-video-renderer:has(span.ytd-thumbnail-overlay-time-status-renderer[aria-label="Shorts"])
www.youtube.com##ytd-browse ytd-rich-item-renderer:has(span.ytd-thumbnail-overlay-time-status-renderer[aria-label="Shorts"])
www.y
@squarism
squarism / typescript_enums_are_cursed.ts
Created January 3, 2023 19:36
Typescript Enums are Cursed
// Theo's Enum Avoidance, Implemented
// https://www.youtube.com/watch?v=Anu8vHXsavo
// don't do this ---------------------------------------------------
enum UserRole {
User,
Admin,
Staff
}
HTTP Verb   Route            Model->method()   Description
-----------------------------------------------------------------------------------------
GET         /posts           posts->index()    display a list of all posts
GET         /posts/new       posts->new()      return an HTML form for creating a new post
POST        /posts           posts->create()   create a new post
GET         /posts/:id       posts->show()     display a specific post
GET         /posts/:id/edit  posts->edit()     return an HTML form for editing a post
PATCH/PUT   /posts/:id       posts->update()   update a specific post
DELETE /posts/:id posts->destroy() delete a specific post
@squarism
squarism / typescriptreact.json
Last active November 20, 2022 19:10
React Snippets
{
// for next, remix and solid index routes that uses the directory name for the component name
"export default function": {
"prefix": "edf",
"body": [
"export default function ${TM_DIRECTORY/^.+\\/(.*)$/${1:/pascalcase}/}() {",
"\treturn(",
"\t\t${0}",
"\t)",
"}"
@squarism
squarism / remix_notices.ts
Created November 11, 2022 21:45
How to do flash messages or notices or toasts in remix
// app/services/notice.server.ts
const { getSession, commitSession, destroySession } =
createCookieSessionStorage({
cookie: {
name: "notice",
sameSite: "lax",
path: "/",
httpOnly: true,
secrets: [process.env.COOKIE_SECRET || "CHANGEME"],
secure: process.env.NODE_ENV === "production",
@squarism
squarism / remix_on_bun.md
Last active November 6, 2022 19:20
Remix on Bun

Not a whole lot of info out there about this. I understand that bun is in beta at the moment. I just wanted to see where it's at. Remix doesn't really care too much about the runtime since it's tied to standard APIs. However, it's still SSR so ... how to run in prod etc?

Install Bun

bun.sh has the instructions but basically run the curl/bash one-liner command even if you are on zsh or fish.

bun --version
0.2.2
@squarism
squarism / remix_thoughts.md
Last active November 14, 2022 22:31
Thoughts on Remix So Far

Caveats and Disclaimers

  • I'm biased and unperfect
  • Remix 1.7.2 is the current release, things may change
  • Making a framework is harder than I know. Making it fully featured is even harder.

The Good

It embraces web standards