Skip to content

Instantly share code, notes, and snippets.

@georgepar
Created May 31, 2019 07:54
Show Gist options
  • Save georgepar/80d90214ff30684a9ac7bccbb6cc2f75 to your computer and use it in GitHub Desktop.
Save georgepar/80d90214ff30684a9ac7bccbb6cc2f75 to your computer and use it in GitHub Desktop.
VS Code snippets
{
"Create Class": {
"prefix": "cls",
"body": [
"class ${1:MyClass}(${2:object}):",
" def __init__(self, ${3:*args}, ${4:**kwargs}):",
" super(${1:MyClass}, self).__init__(${5:*args}, ${6:**kwargs})"
],
"description": "Create Class"
},
"Initialize Property": {
"prefix": "prp",
"body": [
"self.${1:member} = ${1:value}"
],
"description": "initialize property"
},
"Define funtion": {
"prefix": "fn",
"body": [
"def ${1:my_function}(${2:*args}, ${3:kwargs}):",
" ${4:pass}"
],
"description": "Define Function"
},
"Load Pickle": {
"prefix": "loadpkl",
"body": [
"with open(${1:filename}, 'rb') as fd:",
" ${2:data} = pickle.load(fd)"
],
"description": "Load Pickle"
},
"Dump Pickle": {
"prefix": "dumppkl",
"body": [
"with open(${1:filename}, 'wd') as fd:",
" pickle.dump(${2:data}, fd)"
],
"description": "Dump Pickle"
},
"List Comprehension": {
"prefix": "lc",
"body": [
"${1:ys} = [${2:x} for ${2:x} in ${3:xs}]"
],
"description": "List Comprehension"
},
"List Comprehension Filter": {
"prefix": "lcf",
"body": [
"${1:ys} = [${2:x} for ${2:x} in ${3:xs} if ${4:condition}]"
],
"description": "List Comprehension Filter"
},
"forenum": {
"prefix": "For Loop Enumerate",
"body": [
"for ${1:i}, ${2:x} in enumerate(${3:xs}):",
" ${4:pass}"
],
"description": "forenum"
},
"Dictionary iteration": {
"prefix": "fordict",
"body": [
"for ${1:k}, ${2:v} in ${3:d}.items():",
" ${4:pass}"
],
"description": "Dictionary iteration"
},
"Argument Parser": {
"prefix": "parseargs",
"body": [
"parser = argparse.ArgumentParser(description='${1:The Description}')",
"${2}",
"args = parser.parse_args()",
""
],
"description": "Argument Parser"
},
"Add generic argparse argument": {
"prefix": "parseargs:arg",
"body": [
"parser.add_argument(",
" '-${1:s}','--${2:long-arg}', type=${3:int}, default=${4:None},",
" help='${5:Be kind. Include help msg} (default: ${4})')"
],
"description": "Add generic argparse argument"
},
"Add bool argparse argument": {
"prefix": "parseargs:bool",
"body": [
"parser.add_argument(",
" '-${1:f}', '--${2:flag}', action='store_true', default=${3:False},",
" help='${4:Happy little help message} (default ${3})')"
],
"description": "Add bool argparse argument"
},
"Add list argparse argument": {
"prefix": "parseargs:list",
"body": [
"parser.add_argument(",
" '-${1:s}', '--${2:long}, nargs='+', type=${3:int}, default=${4:None},",
" help='${5:Helpful help message}, (default: ${4})', )",
""
],
"description": "Add list argparse argument"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment