Skip to content

Instantly share code, notes, and snippets.

View kodekracker's full-sized avatar
🎯
Focusing

Akshay Pratap Singh kodekracker

🎯
Focusing
View GitHub Profile
@kodekracker
kodekracker / multidict.py
Created January 6, 2024 17:19
Multi dict data stucture utilities
"""
Source: https://github.com/mitmproxy/mitmproxy/blob/main/mitmproxy/coretypes/multidict.py
"""
from abc import ABCMeta
from abc import abstractmethod
from collections.abc import Iterator
from collections.abc import MutableMapping
from collections.abc import Sequence
from typing import TypeVar
@kodekracker
kodekracker / settings.json
Last active October 12, 2023 07:46
VS Code settings
{
"workbench.productIconTheme": "material-product-icons",
"workbench.iconTheme": "material-icon-theme",
"workbench.colorTheme": "Material Theme Ocean",
"telemetry.telemetryLevel": "off",
"files.associations": {
"*.env.staging": "env",
"*.env.development": "env",
"*.env.production": "env",
"*.env.example": "env",
@kodekracker
kodekracker / after_fetch_queryset_mixin.py
Created October 17, 2022 16:02 — forked from spookylukey/after_fetch_queryset_mixin.py
AfterFetchQuerySetMixin for Django
class AfterFetchQuerySetMixin:
"""
QuerySet mixin to enable functions to run immediately
after records have been fetched from the DB.
"""
# This is most useful for registering 'prefetch_related' like operations
# or complex aggregations that need to be run after fetching, but while
# still allowing chaining of other QuerySet methods.
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@kodekracker
kodekracker / debug_requests.py
Created July 19, 2022 17:40
Enable debugging in python requests package
# source: https://stackoverflow.com/a/57325050/10504918
import requests
import logging
from http.client import HTTPConnection # py3
log = logging.getLogger('urllib3')
log.setLevel(logging.DEBUG)
# logging from urllib3 to console
@kodekracker
kodekracker / amazon-cloudwatch-agent-config-schema.json
Created June 2, 2022 08:37
Amazon Cloudwatch Agent Config JSON Schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"description": "Amazon CloudWatch Agent JSON Schema",
"properties": {
"agent": {
"$ref": "#/definitions/agentDefinition"
},
"metrics": {
"$ref": "#/definitions/metricsDefinition"
@kodekracker
kodekracker / install_python_source_build_system_dependencies.sh
Created May 14, 2022 19:04
Python source build system dependencies
sudo apt install libffi-dev libgdbm-dev libsqlite3-dev libssl-dev zlib1g-dev libncurses-dev libz-dev tk-dev libreadline-dev liblzma-dev
@kodekracker
kodekracker / pseudo_encrypt.sql
Last active April 27, 2022 19:00
A pseudo_encrypt function implementation for int and bigint
CREATE OR REPLACE FUNCTION pseudo_encrypt(value int) returns int AS $$
DECLARE
l1 int;
l2 int;
r1 int;
r2 int;
i int:=0;
BEGIN
l1:= (value >> 16) & 65535;
r1:= value & 65535;
@kodekracker
kodekracker / bounded_prng.sql
Last active April 27, 2022 18:02
A bounded pseudo-random generator of unique values in postgres database inspired from pseudo_encrypt
CREATE FUNCTION pseudo_encrypt_24(VALUE int) returns int AS $$
DECLARE
l1 int;
l2 int;
r1 int;
r2 int;
i int:=0;
BEGIN
l1:= (VALUE >> 12) & (4096-1);
r1:= VALUE & (4096-1);
@kodekracker
kodekracker / multiple-deploy-keys-multiple-private-repos-github-ssh-config.md How to configure multiple deploy keys for different private github repositories on the same computer without using ssh-agent

How to configure multiple deploy keys for different private github repositories on the same computer without using ssh-agent

Let's say alice is a github.com user, with 2 or more private repositories repoN. For this example we'll work with just two repositories named repo1 and repo2

https://github.com/alice/repo1

https://github.com/alice/repo2

You need to be to pull from these repositories without entering a passwords probably on a server, or on multiple servers.

@kodekracker
kodekracker / network-tuning.conf
Created December 1, 2021 06:22 — forked from pensierinmusica/network-tuning.conf
Linux sysctl configuration file for NginX
## Place this file in "/etc/sysctl.d/network-tuning.conf" and
## run "sysctl -p" to have the kernel pick the new settings up
# Avoid a smurf attack
net.ipv4.icmp_echo_ignore_broadcasts = 1
# Turn on protection for bad icmp error messages
net.ipv4.icmp_ignore_bogus_error_responses = 1
# Turn on syncookies for SYN flood attack protection