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 / ExtendedEvent_LongRunningQuery.sql
Created February 6, 2025 10:27 — forked from paschott/ExtendedEvent_LongRunningQuery.sql
Create an Extended Event Trace for Long-Running Queries
CREATE EVENT SESSION [Long-Running Queries] ON SERVER
ADD EVENT sqlserver.rpc_completed (
ACTION ( sqlserver.client_app_name, sqlserver.client_hostname,
sqlserver.database_id, sqlserver.database_name, sqlserver.nt_username,
sqlserver.query_hash, sqlserver.server_principal_name,
sqlserver.session_id, sqlserver.sql_text )
WHERE ( ( ( package0.greater_than_uint64(sqlserver.database_id, ( 4 )) )
AND ( package0.equal_boolean(sqlserver.is_system, ( 0 )) ) )
AND ( duration >= ( 500000 ) )
) ),
@kodekracker
kodekracker / bash_util.sh
Last active December 16, 2024 14:28
Bash scripting utilities
set +e
set -o noglob
#
# Set Colors
#
bold=$(tput bold)
underline=$(tput sgr 0 1)
reset=$(tput sgr0)
@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 January 25, 2025 16:25
VS Code settings
{
"[csharp]": {
"editor.defaultFormatter": "csharpier.csharpier-vscode"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
@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);