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"; |
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
| sudo pip3 install jupyter | |
| export PASSWD=$(ipython -c "from IPython.lib import passwd; print(passwd('sudo123'))") # Change with your password here between quotes. | |
| jupyter notebook --generate-config | |
| cd ~ | |
| mkdir certs | |
| cd certs | |
| sudo openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem |
NewerOlder