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 background=dark | |
| nnoremap <silent> <C-l> :nohlsearch<CR> | |
| set autoindent | |
| filetype plugin indent on | |
| set expandtab | |
| set tabstop=4 | |
| set shiftwidth=4 | |
| set softtabstop=4 |
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
| # $Profile has the profile location | |
| # Detect VS Code environment and change the history path | |
| if ( $env:TERM_PROGRAM -eq "vscode" ) { | |
| Set-PSReadLineOption -HistorySavePath ((Get-PSReadLineOption).HistorySavePath + "_vscode") | |
| } | |
| # Or, to preserve the file extension: | |
| if ( $env:TERM_PROGRAM -eq "vscode" ) { | |
| $h = (Get-PSReadLineOption).HistorySavePath |
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 logging, logging.config | |
| logging.config.dictConfig({ | |
| "version": 1, | |
| "formatters": { | |
| "common": { | |
| "format": (f"%(asctime)s%(msecs)03d %(process)7d " | |
| f"[{JOB_ID or 0:4d}] %(levelname)-7s %(message)s"), | |
| "datefmt": "%Y-%m-%dT%H:%M:%S" }}, | |
| "handlers": { | |
| "stdout": { |
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 string | |
| from typing import Callable | |
| class FormatterWithFallback(string.Formatter): | |
| def __init__(self, fallback: str|Callable): | |
| self.fallback=fallback | |
| def get_value(self, key, args, kwds): | |
| try: | |
| return super().get_value(key, args, kwds) |
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 is_subarray(a, b): | |
| return any( | |
| all( e_a==e_b for e_a, e_b in zip(a,b[i:]) ) | |
| for i in range(len(b)-len(a)+1) ) | |
| assert is_subarray('ab', 'abcd') | |
| assert is_subarray('bc', 'abcd') | |
| assert is_subarray('cd', 'abcd') | |
| assert not is_subarray('de', 'abcd') | |
| assert not is_subarray('abcd', 'ab') |
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 Group-NoSort() { | |
| [CmdletBinding()] | |
| Param( | |
| [Parameter(ValueFromPipeline=$true)] $InputObject, | |
| [Parameter(Mandatory, Position=0, | |
| HelpMessage="Name of the property to use as a grouping key")][String] $Property, | |
| [Parameter( | |
| HelpMessage="If true, keys will be compared for full equality (e.g. 2.0 and 2 are not equal)")] | |
| [switch] $StrictEq | |
| ) |
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
| [System.Text.Encoding]::UTF8.GetBytes("é") | % ToString X2 | Join-String -Separator " " | |
| # C3 A9 | |
| [System.Text.Encoding]::Latin1.GetBytes("é") | % ToString X2 | Join-String -Separator " " | |
| # E9 | |
| [System.Text.Encoding]::Latin1.GetString( [System.Text.Encoding]::UTF8.GetBytes("é") ) | |
| # é |
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 Timer(): | |
| def __init__(self): | |
| self.timer = time.perf_counter | |
| def __enter__(self): | |
| self.start = self.timer() | |
| return self | |
| def __exit__(self, *args): | |
| self.elapsed = self.timer() - self.start | |
| if __name__ == "__main__": |
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 MyArgParser(argparse.ArgumentParser): | |
| def error(self, message): | |
| print(f'Error: {message}\n', file=sys.stderr) | |
| self.print_help() | |
| sys.exit(2) |
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 java.io.BufferedReader; | |
| import java.io.InputStreamReader; | |
| import java.io.StringWriter; | |
| public class PbReadStdout { | |
| public static void main(String[] argv) { | |
| try { | |
| String[] cmd = { | |
| // "/bin/sh", "-c", | |
| // String.format( |
NewerOlder