Skip to content

Instantly share code, notes, and snippets.

@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 / python_generators.py
Created October 5, 2018 22:41
Python Generator Cheatsheet
# A personal cheatsheet for the confusing (to me) python feature: generators
# Done in ipython
[n*2 for n in [1,2,3]]
# Out[8]: [2, 4, 6]
{n*2 for n in [1,2,3] if n > 1}
# Out[9]: {4, 6}
for n in (x for x in [1,2,3] if x > 1):
@squarism
squarism / java_upgrades_homebrew_jenv.md
Last active February 21, 2023 14:53
Automating Java Upgrades with Homebrew and Jenv

Goals:

  • never upgrade Java with the GUI pkg installer again.
  • never try to remember that /Library/Java is where JDKs go.
  • Just keep JDK8 and JDK9 up-to-date. Java is so stable, maybe these two major versions is all we need?

Note the assumptions in these goals. Making this a bit more generic would be nice.

I'm on a mac and I use the fish shell which I know is squarely in the edge case camp but I hope this is inspiring or useful to someone else because there's not much shell specific stuff here. I found jenv which is going to help.

First, upgrading java with homebrew is pretty easy. The assumption is that java8 is stable and java (9) is still emerging. This assumption would likely change so it'd be nice to have this scripted out of this assumption. For now, I'm just trying to avoid graphical Oracle installers.

@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
}
@squarism
squarism / english_is_terrible.md
Last active January 2, 2023 18:59
English is Terrible

I'm sad that the world has adopted English as the language of science and business. It's insane. It's like adopting a psychotic murdering robot to clean your house. English is a mutt language that has never been redone, reworked or even designed. It's a combination of ice cream, meatballs and wine. All fine things by themselves but terrible when combined.

There are more English learners than there are native English speakers in the world. I'm really sorry world. I'm just so so sorry that you have to learn Germanic-French-Latin nonsense. It's terrible. It's a terrible language.

Update: I wrote this before I read Mother Tongue by Bill Bryson. It's fantastic and a better write-up of what I'm trying to say here.


Prepositional phrases

@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 / 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_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

@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