Skip to content

Instantly share code, notes, and snippets.

View AlfiyaZi's full-sized avatar
🎯
Focusing

Ziganshina Alfiya AlfiyaZi

🎯
Focusing
  • Bremen
  • 04:28 (UTC -12:00)
View GitHub Profile
@codeinthehole
codeinthehole / python-testing.md
Last active April 9, 2024 00:37
Python testing reference

Python testing reference

This document is a reference for common testing patterns in a Django/Python project using Pytest.

Contents:

"""A set of helpers for reversing urls, similar to Django ``reverse``.
Usage:
.. code:: python
@router.get("/class/{class_id}")
async def get_class(request: Request, class_id: int = Path(...)):
student_route = get_route(request.app, "list_students")
class_students_url = URLFactory(student_route).get_path(class_id=class_id)
1 cd ~
2 clear
3 sudo hostnamectl set-hostname k8s-master
4 hostname
5 sudo reboot
6 cd ~
7 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
8 ls
9 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
10 $(lsb_release -cs) \
@dwyn
dwyn / settings.js
Last active May 6, 2021 10:00
VSCode Settings Details
{
// Editor
// When enabled, the diff editor ignores changes in leading or trailing whitespace.
"diffEditor.ignoreTrimWhitespace": true,
// Timeout in milliseconds after which diff computation is cancelled. Use 0 for no timeout.
"diffEditor.maxComputationTime": 5000,
// Controls whether the diff editor shows +/- indicators for added/removed changes.

Init Containers in Kubernetes

This is the era of containerization and orchestration where majority of the application are following the trend of running on a container which are further deployed in a Kubernetes cluster. It’s sometimes necessary to prepare the main container which will be running our application or the main logic.

There can also be situations where we need to execute a particular utilities or setup scripts that are not present in our main image ( as it would make it heavy and we only need it once in the beginning ).

What are Init Containers ?

Kubernetes provides special type of containers that runs to completion before the main app's container and Kubernetes will repeatedly restarts the Pod until the init container succeeds. Some of its properties are :

@sainipray
sainipray / filter.py
Created February 27, 2020 09:53
Custom Django rest framework Ordering Filter
from rest_framework.filters import OrderingFilter
class CustomOrderFilter(OrderingFilter):
allowed_custom_filters = ['user_city', 'user_country']
fields_related = {
'user_city': 'user__city__name', # ForeignKey Field lookup for ordering
'user_country': 'user__country__name'
}
def get_ordering(self, request, queryset, view):
@System-Glitch
System-Glitch / go-worker.go
Last active May 10, 2024 15:57
A resilient Go worker
package main
// This is an example of a resilient worker program written in Go.
//
// This program will run a worker, wait 5 seconds, and run it again.
// It exits when SIGINT or SIGTERM is received, while ensuring any ongoing work
// is finished before exiting.
//
// Unexpected panics are also handled: program won't crash if the worker panics.
// However, panics in goroutines started by the worker won't be handled and have
@schicks
schicks / README.md
Last active November 25, 2021 23:41
Pydantic Generation Strategy

Pydantic Generation Strategy

We frequently use pydantic at Pluralsight to validate data at the edge of a well typed domain. I've been trying to sell my coworkers on using hypothesis for testing, and thought it might go easier if they could generate test data from existing pydantic schemas. I found that it was almost trivial for data classes, but BaseModel subclasses (which are unfortunately much more common in our code) don't play as nicely, and deeply nested schemas can get you into trouble. If anyone has any advice on how to get around the errors that come from the last test, I'd be super greatful.

Requirements for usage

  • pydantic
  • hypothesis
  • pytest
@dmontagu
dmontagu / fastapi_cbv.py
Last active July 17, 2024 04:08
FastAPI CBV
import inspect
from typing import Any, Callable, List, Type, TypeVar, Union, get_type_hints
from fastapi import APIRouter, Depends
from pydantic.typing import is_classvar
from starlette.routing import Route, WebSocketRoute
T = TypeVar("T")
CBV_CLASS_KEY = "__cbv_class__"
@asoorm
asoorm / docker-compose-mongo-replicaset.yml
Created September 14, 2018 19:00
Mongo Replica Set docker compose
version: "3"
services:
mongo1:
hostname: mongo1
container_name: localmongo1
image: mongo:4.0-xenial
expose:
- 27017
ports:
- 27011:27017