This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Copyright 2025 Sunrit Jana <warriordefenderz@gmail.com> | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is | |
| furnished to do so, subject to the following conditions: | |
| The above copyright notice and this permission notice shall be included in all |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| def check_sudo(): | |
| return os.geteuid() == 0 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| # colors | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| BLUE='\033[0;34m' | |
| NC='\033[0m' # No Color |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import defaultdict | |
| from typing import Callable, Optional | |
| HandlerFunction = Callable[..., None] | |
| class EventHandler: | |
| def __init__(self): | |
| self.handlers = defaultdict(list) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # We don't check if `rocm` is available as it uses the same CUDA semantics for AMD GPUs | |
| def get_device(): | |
| if torch.cuda.is_available(): | |
| return 'cuda' | |
| elif torch.backends.mps.is_available(): | |
| return 'mps' | |
| else: | |
| return 'cpu' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isNodeRuntime() { | |
| // The reason we check for both `v8` instead of `node` is because when running `process.versions` under | |
| // Bun, it returns `node` and `bun` version, but it doesn't use v8 engine, hence not a Node.js runtime. | |
| return ( | |
| typeof process !== 'undefined' && | |
| process.versions && | |
| process.versions.v8 | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class EventEmitter { | |
| public events: Map<string, Set<Function>>; | |
| constructor() { | |
| this.events = new Map(); | |
| } | |
| public on(event: string, listener: Function) { | |
| if (!this.events.has(event)) this.events.set(event, new Set()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import typing as t | |
| class FromDictMeta(type): | |
| """Metaclass to ensure inherited classes have `from_dict` class method.""" | |
| def __new__( | |
| cls, | |
| name: str, | |
| bases: t.Tuple[type, ...], | |
| attrs: t.Dict[str, t.Any], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Imports | |
| import tensorflow as tf | |
| from keras import backend as K | |
| # Define function for centralizing the gradients | |
| def centralize_gradients(optimizer, loss, params): | |
| grads = [] # List to store the gradients | |
| for grad in K.gradients(loss, params): # Iterate over gradients using the Keras Backend |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Fix CSRF error in django using this. | |
| axios.defaults.xsrfCookieName = "csrftoken"; | |
| axios.defaults.xsrfHeaderName = "X-CSRFToken"; |
NewerOlder