Skip to content

Instantly share code, notes, and snippets.

View Joel-hanson's full-sized avatar
:octocat:
Looking for opportunities

Joel Hanson Joel-hanson

:octocat:
Looking for opportunities
View GitHub Profile
@Joel-hanson
Joel-hanson / Git-alias.md
Created June 22, 2024 02:59
Git aliases are a powerful workflow tool that create shortcuts to frequently used Git commands.

title: "Git Aliases to Supercharge Your Workflow" date: 2024-03-21 draft: false ShowToc: true TocOpen: false math: true summary: "Git aliases are a powerful workflow tool that create shortcuts to frequently used Git commands." tags: [ "git", "version-control", "workflow", "development", "productivity", "command-line", "aliases", "git-commands", "git-aliases", "coding",

1. Get details about this Connect worker and the id of the Kafka cluster it is connected to

curl -X GET "http://localhost:8083/" -H "accept: application/json"

2. List the current loggers and their log levels

curl -X GET "http://localhost:8083/admin/loggers" -H "accept: application/json"
@Joel-hanson
Joel-hanson / videospliting.py
Created July 11, 2021 06:41
Video spliting problem
"""
- based no splits 1000 splits
- based on time eg 10s
- based on time interval 2:10 -> 2:50
- 10 people upload 1 gb 2 file daily
- we have design a system to split it into 1000 partitions
Solution:
@Joel-hanson
Joel-hanson / fib.py
Last active April 10, 2021 17:36
Find nth Fibonacci number using recursion.
def fibonacci(n):
if n <= 2:
return 1
return fibonacci(n - 1) + fibonacci(n - 2)
@Joel-hanson
Joel-hanson / urls.py
Created July 31, 2020 10:40
The urls for django rest framework
from django.urls import path, include
from rest_framework import routers
from .views import UploadViewSet
router = routers.DefaultRouter()
router.register(r'upload', UploadViewSet, basename="upload")
# Wire up our API using automatic URL routing.
urlpatterns = [
path('', include(router.urls)),
@Joel-hanson
Joel-hanson / serializers.py
Created July 31, 2020 10:33
serializer for file upload in django rest framework
from rest_framework.serializers import Serializer, FileField
# Serializers define the API representation.
class UploadSerializer(Serializer):
file_uploaded = FileField()
class Meta:
fields = ['file_uploaded']
@Joel-hanson
Joel-hanson / views.py
Last active July 31, 2020 10:33
views for file upload for django rest framework
from rest_framework.viewsets import ViewSet
from rest_framework.response import Response
from .serializers import UploadSerializer
# ViewSets define the view behavior.
class UploadViewSet(ViewSet):
serializer_class = UploadSerializer
def list(self, request):
return Response("GET API")
@Joel-hanson
Joel-hanson / serializers.py
Created June 3, 2019 04:20
The Nested serializers fields can also be a dynamically modifying fields by using the SerializerMethodField . TheSerializerMethodField can be used to pass the context which contains the requestof the parent serializer, so that we can pass the fields required by us to the nested serializer.
class BookModelSerializer(ModelSerializer):
authors = SerializerMethodField("get_author_serializer")
publisher = SerializerMethodField("get_publisher_serializer")
class Meta:
model = Book
fields = '__all__'
def get_author_serializer(self, obj):
request = self.context.get('request')
@Joel-hanson
Joel-hanson / urls.py
Created June 3, 2019 04:17
In this example, we are using a DefaultRouter which adds support for automatic URL routing to Django, and provides you with a simple, quick and consistent way of wiring your view logic to a set of URLs.
from rest_framework.routers import DefaultRouter
from .views import BookModelViewSet
router = DefaultRouter(trailing_slash=False)
router.register(r'book', BookModelViewSet, base_name='book')
urlpatterns = router.urls
@Joel-hanson
Joel-hanson / views.py
Created June 3, 2019 04:16
We will be using the ModelViewSet and ModelSerializer to make the API for our Book model.
from rest_framework.viewsets import ModelViewSet
from rest_framework.authentication import SessionAuthentication
from .serializers import BookModelSerializer
from .models import Book
# Create your views here.
class BookModelViewSet(ModelViewSet):
"""
A simple ViewSet for viewing and editing books.