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
| def safe_cast(value, astype, default = None): | |
| """Convert one type to another without raising errors""" | |
| try: | |
| return astype(value) | |
| except (TypeError, ValueError): | |
| pass | |
| return default |
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
| def coalesce(*values): | |
| """Return the first non-None value or None if all values are None""" | |
| return next((v for v in values if v is not None), None) |
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
| #lang racket | |
| (require minikanren) | |
| (require minikanren/numbers) | |
| (define zo (build-num 0)) | |
| (define 1o (build-num 1)) | |
| (define (factorialo n f) |
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
| Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted | |
| if (-not (Get-InstalledModule -Name posh-git)) | |
| { | |
| Install-Module posh-git -Scope CurrentUser | |
| } | |
| if (-not (Get-InstalledModule -Name oh-my-posh)) | |
| { | |
| Install-Module oh-my-posh -Scope CurrentUser | |
| } |
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
| class bst_node: | |
| def __init__(self, val, left=None, right=None): | |
| self.val = val | |
| self.left = left | |
| self.right = right | |
| # assumes arr is sorted | |
| def bst_from_array(arr): | |
| if len(arr) == 0: | |
| return None |
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 TrieNode(char, terminal = false) { | |
| this.char = char; | |
| this.terminal = terminal; | |
| this.nextChars = {}; | |
| } | |
| function Trie() { | |
| this.root = new TrieNode(null); | |
| } |
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
| ## === Backup Environment | |
| # 1. Backup your settings.json file | |
| # | |
| # For total control over extension versions, | |
| # - extensions.autoUpdate | |
| # - extensions.autoCheckUpdates | |
| # | |
| # Default settings.json locations: | |
| # - Windows: %APPDATA%\Code\User\settings.json |
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
| def reverse_linked_list_recursive(head): | |
| if head is None: # handles empty linked list | |
| return head | |
| if head.next_node is None: # handles linked list with one node | |
| return head | |
| # A. label the end node as the new head node | |
| new_head = reverse_linked_list_recursive(head.next_node) | |
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
| def reverse_linked_list_recursive(head): | |
| if head is None: # handles empty linked list | |
| return head | |
| if head.next_node is None: # handles linked list with one node | |
| return head | |
| # A. label the end node as the new head node | |
| new_head = head.next_node | |
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
| def reverse_linked_list_recursive(head): | |
| if head is None or head.next_node is None: | |
| return head |