Skip to content

Instantly share code, notes, and snippets.

View carvalhochris's full-sized avatar

Christopher Carvalho carvalhochris

View GitHub Profile
@carvalhochris
carvalhochris / serializers.py
Created February 7, 2023 16:16
The Card links to a thumbnail
class CardSerializer(serializers.ModelSerializer):
title = serializers.CharField()
song = SongSerializer(read_only=True)
thumbnail = HyperlinkedSorlImageField(
'300x300',
options={"crop": "center"},
source='image',
read_only=True
)
@carvalhochris
carvalhochris / views.py
Last active February 27, 2023 14:34
Django Rest Viewset sort by pinned, then by year
class WorkViewSet(viewsets.ModelViewSet):
queryset = Work.objects.all()
serializer_class = WorkSerializer
def get_queryset(self):
queryset = Work.objects.order_by('-pinned', '-year')
return queryset
git rm -r --cached . && git add . && git commit -am 'git cache cleared' && git push origin master
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
import React, { useState } from 'react';
import MyComponent from './MyComponent';
function MyButton() {
const [showComponent, setShowComponent] = useState(false);
const handleClick = () => {
setShowComponent(true);
};
const [profileObject, setProfileObject] = useState({
name: "",
slug: "",
profile_image: "",
});
<iframe height="500px" src="https://sc-embed.vercel.app/af5dc561-2fcb-499b-b168-6aa8e12f6dd2" title="Songcard"></iframe>
styles = {
margin: "auto",
maxWidth: "600px",
padding: "20px",
};
<iframe height="500px" src="https://sc-embed.vercel.app/3223555a-904b-46c4-abfa-a529589b4b56" title="Songcard"></iframe>
@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"