Skip to content

Instantly share code, notes, and snippets.

View carvalhochris's full-sized avatar

Christopher Carvalho carvalhochris

View GitHub Profile
@carvalhochris
carvalhochris / token_in_email_out.py
Created August 24, 2025 21:10
Python Decode Auth0 JWT with JWK Endpoint
from django.conf import settings
from django.http import HttpRequest
import requests
from joserfc.jwk import KeySet
from joserfc import jwt
from joserfc.jwt import Token
from requests import Response
from project.types import EmailOrNot, OptionalEmail, OptionalToken
@carvalhochris
carvalhochris / django_ninja_from_orm.md
Last active January 2, 2025 07:43
How to use Django Ninja schemas to serialize a queryset before returning a response

Take this example of a view that returns two querysets each nested into its own object

# schemas.py

class CardModelOut(ModelSchema):
    class Meta:
        model = Card
        fields = [
 "id",
@carvalhochris
carvalhochris / [id].tsx
Created March 30, 2024 18:24
add cache control headers to dynamic page (Next.js pages router)
export const getServerSideProps = (async (context) => {
const id = context.query.id;
const res = await fetch(`https://api.../posts/${id}/`, {
...
});
context.res.setHeader(
"Cache-Control",
"public, s-maxage=604800, stale-while-revalidate=59"
<iframe height="500px" src="https://sc-embed.vercel.app/3223555a-904b-46c4-abfa-a529589b4b56" title="Songcard"></iframe>
styles = {
margin: "auto",
maxWidth: "600px",
padding: "20px",
};
<iframe height="500px" src="https://sc-embed.vercel.app/af5dc561-2fcb-499b-b168-6aa8e12f6dd2" title="Songcard"></iframe>
const [profileObject, setProfileObject] = useState({
name: "",
slug: "",
profile_image: "",
});
import React, { useState } from 'react';
import MyComponent from './MyComponent';
function MyButton() {
const [showComponent, setShowComponent] = useState(false);
const handleClick = () => {
setShowComponent(true);
};
504b 0304 1400 0800 0800 eb83 5456 0000
0000 0000 0000 0000 0000 3200 1000 646a
7072 6f6a 205b 4531 3735 3638 3233 2d38
3934 382d 3438 4136 2d42 3738 392d 3235
4230 3641 4236 3842 4244 5d2e 6a73 6f6e
5558 0c00 5aa0 f363 5aa0 f363 f601 1400
abe6 5250 504a cc49 2b4a 4d29 cecb 2c28
482d 5152 b052 a806 8a02 c591 4494 52b2
12f3 d2f3 7513 5372 33f3 148a 4b12 8b4a
0a8a f2b3 5293 4b14 60b4 9e92 0e44 5b69
git rm -r --cached . && git add . && git commit -am 'git cache cleared' && git push origin master