Skip to content

Instantly share code, notes, and snippets.

View Yankzy's full-sized avatar

Yankuba Kuyateh Yankzy

View GitHub Profile
@Yankzy
Yankzy / email_script.py
Last active December 25, 2021 23:04
Python script to monitor changes in files on your computer and send email to you using crontab.
import hashlib
import glob
import json
import smtplib
from email.message import EmailMessage
hasher = hashlib.md5()
size = 65536 #to read large files in chunks
list_of_files = glob.glob('./*.csv') #absolute path for crontab
@Yankzy
Yankzy / LoadSpinner.js
Created April 22, 2021 16:17
React Loading Spinner
import React, { useState } from "react";
import { makeStyles, Modal, CircularProgress } from "@material-ui/core";
const useStyles = makeStyles((theme) => ({
paper: {
position: "absolute",
padding: theme.spacing(2, 4, 3),
},
}));
@Yankzy
Yankzy / user.py
Last active June 11, 2021 11:56
Django Global User Object
"""
SINGLETON PATTERN
I recently refactored my Django website into a GraphQL API and use react as frontend.
This was fun, but I lost some Django privileges most importantly "request.user".
This is my solution to restoring the privilege.
"""
class user:
__instance = None
#! /bin/bash
# ECHO COMMAND
# echo Hello World!
# VARIABLES
# Uppercase by convention
# Letters, numbers, underscores
NAME="Bob"
# echo "My name is $NAME"
@Yankzy
Yankzy / dict_merge.py
Created March 10, 2022 22:37 — forked from angstwad/dict_merge.py
Recursive dictionary merge in Python
# Recursive dictionary merge
# Copyright (C) 2016 Paul Durivage <pauldurivage+github@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@Yankzy
Yankzy / utils.py
Last active March 17, 2022 13:44
python utility functions
from dataclasses import dataclass, field
from typing import Any, Awaitable, Callable
@dataclass(unsafe_hash=True)
class ExtraValidators:
func: Callable
# all sub dicts are flattened to key: value level for validate function to work on
flattened: dict = field(default_factory=dict, compare=False)
@Yankzy
Yankzy / grapheneJourney.py
Last active June 28, 2022 05:39
GraphQL & Graphene
# custom scalar explained
from graphene.types import Scalar
from graphql.language import ast
import graphene
class Money(Scalar):
@staticmethod
def serialize(value):
return int(value * Decimal(100))
from graphql.language.ast import StringValue
from graphene.types import Scalar
import graphene
class Stringy(Scalar):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@Yankzy
Yankzy / usage.py
Last active July 3, 2022 04:13
usage
from graphql.language.ast import StringValue
from graphene.types import Scalar
import graphene
from myapp.types import UsageType
class Stringy(Scalar):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
from graphql.language.ast import StringValue
from graphene.types import Scalar
import graphene
from myapp.types import UsageType
pattern_list = []