Skip to content

Instantly share code, notes, and snippets.

View alexwaweru's full-sized avatar
💭
I may be slow to respond.

Alex Waweru alexwaweru

💭
I may be slow to respond.
View GitHub Profile
@alexwaweru
alexwaweru / paginate.py
Last active November 19, 2023 12:22
This is a gist of a GraphQL API controller built on Django. This gist shows how controller code has been decoupled into simple, readable and reusable functions. Initially the pagination and querying code was repeated across multiple files.
import base64
import math
from typing import Dict
import jwt
from cursor_pagination import CursorPaginator
from django.conf import settings
from django.utils import timezone
def paginate(queryset, pagination_input: Dict = None):
from __future__ import annotations
from datetime import datetime
from copy import deepcopy
from typing import Any
class Prototype:
"""
The example class that has cloning ability. We'll see how the values of
field with different types will be cloned.
addi $t0, $s6, 4
add $t1, $s6, $s0
sw $t1, 0($t0)
lw $t0, 0($t0)
add $s0, $t1, $t0
from __future__ import annotations
from abc import ABC, abstractmethod
class AbstractPizzaStore(ABC):
@abstractmethod
def create_pizza(self) -> AbstractPizza:
"""
This is factory method
from __future__ import annotations
from abc import ABC, abstractmethod, abstractproperty
from typing import Any
class AbstractHouseBuilder(ABC):
"""
This Builder interface specifies methods for creating the different parts of
the house.
"""
from __future__ import annotations
from abc import ABC, abstractmethod
class AbstractChairFactory(ABC):
@abstractmethod
def create_chair(self) -> AbstractChair:
pass
\\ Further exaMPles af pointers
Main ()
{
char c = 'Q';
char *char_pointer = &c;
printf("%c %c\n", c, *char_pointer);
c ='/';
printf("%c %c\n", c, *char_pointer);
//Program to illustrate pointers
Main ()
{
int count = 10;
int *int_pointer; // Pointer-to-integer
int_pointer = &count; // Assign address of count to int_pointer
int x = *int_pointer; // Variable int_pointer contains a pointer to count. This pointer is used to access the data item in count.
printf("count = %d, x = %d\n", count, x);
}
int x = *int_pointer;
int_pointer = &count;