Skip to content

Instantly share code, notes, and snippets.

View johncmunson's full-sized avatar

John Munson johncmunson

View GitHub Profile
@samsch
samsch / stop-using-jwts.md
Last active April 23, 2024 05:47
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
@dsandif
dsandif / angular6-aws-s3.md
Last active December 19, 2019 17:15
A how-to guide for hosting a static website on Amazon S3 and Cloudfront.

Tutorial

This is a tutorial on hosting a static website on Amazon S3 and Cloudfront. I made this based on an Angular 6 frontend but this write up can also be used as a guide for other frameworks like React or Vue.js. This tutorial also assumes that you already have an Amazon AWS account and domain name through Google Domains or Amazon Route 53. I use Google Domains as a registrar but I will also cover using Amazon Route 53.

Hosting a static SPA on AWS is a pretty straightforward process. This guide will cover:

  • Creating and configuring an S3 bucket for a Single-Page Application (SPA)
  • Uploading an application to an Amazon S3 bucket
  • Creating and configuring a Cloudfront Distribution
  • Configuring Google Domains OR Amazon Route 53
@kentcdodds
kentcdodds / create-required-context.js
Created May 15, 2018 22:31
create react context that has a validated consumer.
// create a React context Provider/Consumer pair that
// validates the consumer is rendered within a provider
function createRequiredContext(name) {
const Context = React.createContext()
function Consumer(props) {
return (
<Context.Consumer {...props}>
{val => {
if (!val) {
@gaearon
gaearon / prepack-gentle-intro-1.md
Last active February 13, 2024 14:30
A Gentle Introduction to Prepack, Part 1

Note:

When this guide is more complete, the plan is to move it into Prepack documentation.
For now I put it out as a gist to gather initial feedback.

A Gentle Introduction to Prepack (Part 1)

If you're building JavaScript apps, you might already be familiar with some tools that compile JavaScript code to equivalent JavaScript code:

  • Babel lets you use newer JavaScript language features, and outputs equivalent code that targets older JavaScript engines.
@sindresorhus
sindresorhus / writing-eslint-rule.md
Last active February 26, 2023 03:01
Gettings started writing a ESLint rule

Gettings started writing a ESLint rule

First, take a look at the ESLint rule documentation. Just skim it for now. It's very long and boring. You can come back to it later.

ESLint rules works on the AST (Abstract Syntax Tree) representation of the code. In short, this is a tree structure that describes the code in a very verbose form. ESLint walks this tree and rules can subscribe to be notified when it hits a specific node type, like a Literal type, which could be the "hello" part of const welcome = "hello";.

Go ahead and play around with some code in AST Explorer (Make sure the parser is espree). It's a great tool!

Here are some good articles on the subject (ignore the scaffolding parts):

@andymatuschak
andymatuschak / States-v3.md
Last active April 12, 2024 16:06
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@nepsilon
nepsilon / how-to-git-patch-diff.md
Last active April 19, 2024 13:33
How to generate and apply patches with git? — First published in fullweb.io issue #33

How to generate and apply patches with git?

It sometimes happen you need change code on a machine from which you cannot push to the repo. You’re ready to copy/paste what diff outputs to your local working copy.

You think there must be a better way to proceed and you’re right. It’s a simple 2 steps process:

1. Generate the patch:

git diff &gt; some-changes.patch
@alexserver
alexserver / rest-basics.md
Created October 28, 2015 18:56
REST basics, Theory, Principles, and examples.

RESTful API know-how

Motivation

I place my learning process in this document with 2 motives:

  1. To have a quick guide whenever I lost the track of knowledge.
  2. To share the knowledge with anyone wants to learn RESTful APIs

1. Before, some theory

@KyleAMathews
KyleAMathews / lambda.md
Last active May 13, 2022 00:49
Using Kafka and a Samza-like node.js architecture

Disclaimer

I'm still very new to Kafka, eventsourcing, stream processing, etc. I'm in the middle of building my first production system with this stuff and am writing this at the request of a few folks on Twitter. So if you do have experience, please do me and anyone else reading this a favor by pointing out things I get wrong :)

Inspirations

@joseluisq
joseluisq / terminal-git-branch-name.md
Last active April 20, 2024 02:26
Add Git Branch Name to Terminal Prompt (Linux/Mac)

Add Git Branch Name to Terminal Prompt (Linux/Mac)

image

Open ~/.bash_profile in your favorite editor and add the following content to the bottom.

# Git branch in prompt.

parse_git_branch() {