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 abc | |
| from io import BytesIO, StringIO | |
| from typing import Any, TypeVar | |
| WriteContentType = TypeVar('WriteContentType', StringIO, BytesIO, str) | |
| class FileSystemManager(abc.ABC): | |
| _instance: Any = 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
| def get_all_files(src_dir: str, | |
| depth: int = 0, | |
| exclude_files: List[str] = [], | |
| exclude_dirs: List[str] = []) -> List[str]: | |
| """ | |
| Args: | |
| depth: walk depth of directories, | |
| 0 will walk through same directory | |
| -1 will walk through all directories | |
| Returns: |
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 gdload () { | |
| CONFIRM=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate "https://docs.google.com/uc?export=download&id=$1" -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p') | |
| wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$CONFIRM&id=$1" -O $2 | |
| rm -rf /tmp/cookies.txt | |
| } |
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 math | |
| from typing import Any, Dict | |
| from sqlalchemy.orm import Query | |
| class Paginator: | |
| @staticmethod | |
| def paginate(query: Query, page: int, per_page: int) -> Dict[str, 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
| function range(start: number, end: number, step=1) { | |
| return { | |
| [Symbol.iterator]() { | |
| return this; | |
| }, | |
| next() { | |
| if (start < end) { | |
| start = start + step; | |
| return {value: start, done: false} | |
| } |
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
| <?php | |
| namespace App\Logger; | |
| use Arr; | |
| use Illuminate\Support\Facades\Http; | |
| use Monolog\Handler\AbstractProcessingHandler; | |
| use Monolog\Logger; | |
| class GoogleChatHandler extends AbstractProcessingHandler |
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 flatten($array, $prefix = '') { | |
| $return = []; | |
| foreach ($array as $key => $value) { | |
| if (is_array($value)) { | |
| $return = array_merge($return, flatten($value, $prefix . $key . '_')); | |
| } else { | |
| $return[$prefix . $key] = $value; | |
| } | |
| } | |
| return $return; |
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
| let response = getSheetApi; // with responseType arraybuffer or blob | |
| const url = window.URL.createObjectURL(new Blob([response.data])); | |
| const link = document.createElement('a'); | |
| link.href = url; | |
| link.setAttribute('download', 'filename.ext'); | |
| document.body.appendChild(link); | |
| link.click(); | |
| link.remove(); |
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
| <?php | |
| $query = Model::conditions(); | |
| $query->whereRaw('id IN (SELECT max(id) from table group by other_id)'); | |
| $query->get(); |
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 doGet() { | |
| const tab = e.parameter.tab; | |
| const spreadSheet = SpreadsheetApp.openById('your-sheet-id'); | |
| const tabs = { | |
| tab1: { idx: 0, titleRange: 'A1:H1', dataRange: 'A2:H' }, | |
| tab2: { idx: 1, titleRange: 'A1:E1', dataRange: 'A2:E' }, | |
| tab3: { idx: 2, titleRange: 'A1:G1', dataRange: 'A2:C' }, | |
| tab4: { idx: 3, titleRange: 'A1:C1', dataRange: 'A2:C' }, | |
| tab5: { idx: 4, titleRange: 'A1:D1', dataRange: 'A2:D' }, | |
| }; |