Last active
February 19, 2023 14:06
-
-
Save Kunkgg/d35fac4145682dfac7846bac30198fe0 to your computer and use it in GitHub Desktop.
VScode snippets
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
{ | |
// * Place your global snippets here. | |
// * docs: https://code.visualstudio.com/docs/editor/userdefinedsnippets#_snippet-scope | |
// region pre-define variables | |
// * The following variables can be used: | |
// TM_SELECTED_TEXT The currently selected text or the empty string | |
// TM_CURRENT_LINE The contents of the current line | |
// TM_CURRENT_WORD The contents of the word under cursor or the empty string | |
// TM_LINE_INDEX The zero-index based line number | |
// TM_LINE_NUMBER The one-index based line number | |
// TM_FILENAME The filename of the current document | |
// TM_FILENAME_BASE The filename of the current document without its extensions | |
// TM_DIRECTORY The directory of the current document | |
// TM_FILEPATH The full file path of the current document | |
// RELATIVE_FILEPATH The relative (to the opened workspace or folder) file path of the current document | |
// CLIPBOARD The contents of your clipboard | |
// WORKSPACE_NAME The name of the opened workspace or folder | |
// WORKSPACE_FOLDER The path of the opened workspace or folder | |
// * For inserting the current date and time: | |
// CURRENT_YEAR The current year | |
// CURRENT_YEAR_SHORT The current year's last two digits | |
// CURRENT_MONTH The month as two digits (example '02') | |
// CURRENT_MONTH_NAME The full name of the month (example 'July') | |
// CURRENT_MONTH_NAME_SHORT The short name of the month (example 'Jul') | |
// CURRENT_DATE The day of the month as two digits (example '08') | |
// CURRENT_DAY_NAME The name of day (example 'Monday') | |
// CURRENT_DAY_NAME_SHORT The short name of the day (example 'Mon') | |
// CURRENT_HOUR The current hour in 24-hour clock format | |
// CURRENT_MINUTE The current minute as two digits | |
// CURRENT_SECOND The current second as two digits | |
// CURRENT_SECONDS_UNIX The number of seconds since the Unix epoch | |
// * For inserting random values: | |
// RANDOM 6 random Base-10 digits | |
// RANDOM_HEX 6 random Base-16 digits | |
// UUID A Version 4 UUID | |
// For inserting line or block comments, honoring the current language: | |
// BLOCK_COMMENT_START Example output: in PHP /* or in HTML <!-- | |
// BLOCK_COMMENT_END Example output: in PHP */ or in HTML --> | |
// LINE_COMMENT Example output: in PHP // | |
// endregion | |
"Code Section": { | |
"prefix": "co-sec", | |
"body": [ | |
"$LINE_COMMENT ---------------------------------------------------------------------------", | |
"$LINE_COMMENT ${1:section_name}", | |
"$LINE_COMMENT ---------------------------------------------------------------------------", | |
"$0", | |
], | |
"description": "Code section spliter" | |
}, | |
"Code region fold": { | |
"prefix": "co-region", | |
"body": [ | |
"${LINE_COMMENT}region ${1:region_name}", | |
"${LINE_COMMENT}endregion", | |
"$0", | |
], | |
"description": "Code region fold marker" | |
}, | |
"Code region fold with selection": { | |
"prefix": "co-region-selection", | |
"body": [ | |
"${LINE_COMMENT}region ${1:region_name}", | |
"$TM_SELECTED_TEXT", | |
"${LINE_COMMENT}endregion", | |
"$0", | |
], | |
"description": "Code region fold marker with selection" | |
}, | |
} |
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
{ | |
// Place your snippets for python here. Each snippet is defined under a snippet name and has a prefix, body and | |
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: | |
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the | |
// same ids are connected. | |
// Example: | |
// "Print to console": { | |
// "prefix": "log", | |
// "body": [ | |
// "console.log('$1');", | |
// "$2" | |
// ], | |
// "description": "Log output to console" | |
// } | |
// --------------------------------------------------------------------------- | |
// Basic | |
// --------------------------------------------------------------------------- | |
"if __name__ == \"__main__\"": { | |
"prefix": "ifmain", | |
"body": "if __name__ == \"__main__\":\n\t${1:main()}$0", | |
"description": "Create implicitly all the code at the top level using the __name__ special variable." | |
}, | |
"lambda": { | |
"prefix": "lam", | |
"body": "lambda ${1:args}: ${2:expr}", | |
"description": "Create template for lambda function" | |
}, | |
"New enum": { | |
"prefix": "enum", | |
"body": [ | |
"from enum import Enum\n\n", | |
"class ${1:MyEnum}(Enum):", | |
"\t\"\"\"${2:Docstring for $1.}\"\"\"", | |
"\t${3:FIRST_ENUM} = \"some_value\"", | |
"\t${4:SECOND_ENUM} = \"some_other_value\"", | |
"\t$0" | |
], | |
"description": "Code snippet for enum definition." | |
}, | |
"for": { | |
"prefix": "for", | |
"body": "for ${1:value} in ${2:iterable}:\n\t${3:pass}$0", | |
"description" : "Code snippet to create a for loop structure." | |
}, | |
// --------------------------------------------------------------------------- | |
// list comprehension | |
// --------------------------------------------------------------------------- | |
"List comprehension": { | |
"prefix": "lc", | |
"body": "[${1:value} for ${2:value} in ${3:iterable}]$0", | |
"description" : "List comprehension for creating a list based on existing lists." | |
}, | |
"List comprehension if filter": { | |
"prefix": "lci", | |
"body": "[${1:value} for ${2:value} in ${3:iterable} if ${4:condition}$0]", | |
"description" : "List comprehension for creating a list based on existing lists, with conditional if statement." | |
}, | |
"Dictionary comprehension": { | |
"prefix": "dc", | |
"body": "{${1:key}: ${2:value} for ${3:key}, ${4:value} in ${5:iterable}}$0", | |
"description" : "Handy and faster way to create dictories based on existing dictionaries." | |
}, | |
"Dictionary comprehension if filter": { | |
"prefix": "dci", | |
"body": "{${1:key}: ${2:value} for ${3:key}, ${4:value} in ${5:iterable} if ${6:condition}}$0", | |
"description" : "Handy and faster way to create dictories based on existing dictionaries, with conditional if statement." | |
}, | |
"Set comprehension": { | |
"prefix": "sc", | |
"body": "{${1:value} for ${2:value} in ${3:iterable}}$0", | |
"description" : "Create a set based on existing iterables." | |
}, | |
"Set Comprehension if filter": { | |
"prefix": "sci", | |
"body": "{${1:value} for ${2:value} in ${3:iterable} if ${4:condition}}$0", | |
"description" : "Create a set based on existing iterables, with condition if statement." | |
}, | |
// --------------------------------------------------------------------------- | |
// Python Native frequency | |
// --------------------------------------------------------------------------- | |
"New ipdb breakpoint": { | |
"prefix": "ipdb", | |
"body": "import ipdb; ipdb.set_trace()", | |
"description" : "Create New ipdb breakpoint" | |
}, | |
// --------------------------------------------------------------------------- | |
// logging | |
// --------------------------------------------------------------------------- | |
// --------------------------------------------------------------------------- | |
// pathlib | |
// --------------------------------------------------------------------------- | |
// --------------------------------------------------------------------------- | |
// Exception | |
// --------------------------------------------------------------------------- | |
"try-except-else-finally": { | |
"prefix": "try-except-else-finally", | |
"body": [ | |
"try:", | |
" result = x / y", | |
"except ZeroDivisionError as e:", | |
" print(\"division by zero!\")", | |
"else:", | |
" print(\"result is\", result)", | |
"finally:", | |
" print(\"executing finally clause\")" | |
], | |
"description": "try-except-else-finally" | |
} | |
// --------------------------------------------------------------------------- | |
// unittest | |
// --------------------------------------------------------------------------- | |
"New unittest case": { | |
"prefix": "utcase", | |
"body": [ | |
"import unittest", | |
"", | |
"", | |
"class TestSome(unittest.TestCase):", | |
" def test_some_do_some(self):", | |
" pass", | |
], | |
"description" : "Create New unittest case" | |
}, | |
// --------------------------------------------------------------------------- | |
// decorator | |
// --------------------------------------------------------------------------- | |
// --------------------------------------------------------------------------- | |
// context manager | |
// --------------------------------------------------------------------------- | |
// --------------------------------------------------------------------------- | |
// pandas | |
// --------------------------------------------------------------------------- | |
// --------------------------------------------------------------------------- | |
// sql-alchemy | |
// --------------------------------------------------------------------------- | |
// --------------------------------------------------------------------------- | |
// fastapi | |
// --------------------------------------------------------------------------- | |
// --------------------------------------------------------------------------- | |
// django | |
// --------------------------------------------------------------------------- | |
// --------------------------------------------------------------------------- | |
// sphinx | |
// --------------------------------------------------------------------------- | |
"simplest sphinx config": { | |
"prefix": "sphinx-config", | |
"body": [ | |
"import os", | |
"import sys", | |
"", | |
"sys.path.insert(0, os.path.abspath('..'))", | |
"", | |
"extensions = [", | |
" 'sphinx.ext.autodoc',", | |
" 'sphinx.ext.todo',", | |
" 'sphinx.ext.viewcode',", | |
"]", | |
"", | |
"language = 'zh_CN'", | |
"", | |
"html_theme = 'sphinx_rtd_theme'" | |
], | |
"description": "simplest sphinx config" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment