Skip to content

Instantly share code, notes, and snippets.

@AlemTuzlak
AlemTuzlak / index.ts
Last active August 9, 2024 09:56
Hono auto-infer app context
// Your app load context function that generates the remix context object
const generateAppLoadContext = async (c: Context, build: ServerBuild) => {
// example with i18n
const locale = i18next.getLocale(c);
const t = await i18next.getFixedT(c);
return {
appVersion: "v1.0",
lang: locale,
t,
@renatorib
renatorib / vscode.settings.json
Created November 14, 2023 16:23
Tailwind classRegex vscode
"tailwindCSS.experimental.classRegex": [
// const foo = cn("...")
// const foo = cx("...")
// const foo = classnames("...")
["cn|cx|classnames\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"],
// <Component classNames={{ foo: "..." }} />
["classNames=\\{([^}]*)\\}", "[\"'`]([^\"'`]*).*?[\"'`]"],
// const foo = /* tw */ "..."
["/\\* tw \\*/ ?(.*)", "[\"'`]([^\"'`]*).*?[\"'`]"],
// const foo = /* tw */ { bar: "...", baz: "..." }
@seldo
seldo / can-spam.md
Last active May 2, 2023 19:52
CAN-SPAM

Hi! I notice your email doesn't contain instructions on how to unsubscribe, which is illegal:

https://www.ftc.gov/tips-advice/business-center/guidance/can-spam-act-compliance-guide-business

Despite its name, the CAN-SPAM Act doesn’t apply just to bulk email. It covers all commercial messages, which the law defines as “any electronic mail message the primary purpose of which is the commercial advertisement or promotion of a commercial product or service,” including email that promotes content on commercial websites. The law makes no exception for business-to-business email. That means all email – for example, a message to former customers announcing a new product line – must comply with the law.

Each separate email in violation of the CAN-SPAM Act is subject to penalties of up to $46,517, so non-compliance can be costly. But following the law isn’t complicated. Here’s a rundown of CAN-SPAM’s main requirements:

  1. Don’t use false or misleading header information.
  2. Don’t use deceptive subject lines.
@bvaughn
bvaughn / LICENSE.md
Last active January 8, 2025 14:26
Advanced example for manually managing subscriptions in an async-safe way using hooks

The MIT License (MIT)

Copyright © <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

@gragland
gragland / use-fake-auth-hook.js
Created February 28, 2019 20:12
useFakeAuth React Hook
// Current auth status
let currentAuth = false;
// Holds setAuth for every instance of hook
const authSetters = new Set();
function useFakeAuth() {
// Auth state and setter
const [auth, setAuth] = useState(currentAuth);
@tannerlinsley
tannerlinsley / hooks.js
Created January 25, 2019 17:00
useCancellable, useRefresh combo
const useCancellable = fn => {
const requestRef = useRef(0)
return async (...args) => {
// Keep track of latest promise ID
const id = Date.now()
requestRef.current = id
// Wait for resolution
const res = await fn(...args)
@JoniJnm
JoniJnm / date-fns-date-adapter.ts
Created January 4, 2019 11:44
date-fns angular material adapter
import {Injectable} from '@angular/core';
import {DateAdapter} from '@angular/material';
import {addDays, addMonths, addYears, format, getDate, getDaysInMonth, getMonth, getYear, parse, setDay, setMonth, toDate} from 'date-fns';
// CONFIG. Use environment or something for a dynamic locale and settings
import {es as locale} from 'date-fns/locale';
const WEEK_STARTS_ON = 1; // 0 sunday, 1 monday...
export const MAT_DATE_FNS_DATE_FORMATS = {
@vktr
vktr / rule.js
Created February 10, 2018 18:54
Add Stripe Customer Id to Auth0 via custom rule
function (user, context, callback) {
user.app_metadata = user.app_metadata || {};
if ('stripe_customer_id' in user.app_metadata) {
context.idToken['https://example.com/stripe_customer_id'] = user.app_metadata.stripe_customer_id;
return callback(null, user, context);
}
var stripe = require('stripe')('sk_....');
var customer = {

Folder Structure

Please note

While this gist has been shared and followed for years, I regret not giving more background. It was originally a gist for the engineering org I was in, not a "general suggestion" for any React app.

Typically I avoid folders altogether. Heck, I even avoid new files. If I can build an app with one 2000 line file I will. New files and folders are a pain.

@natelandau
natelandau / .bash_profile
Last active April 25, 2025 02:45
Mac OSX Bash Profile
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management