Skip to content

Instantly share code, notes, and snippets.

@idac73
Last active September 28, 2020 23:49
Show Gist options
  • Save idac73/10cbfea1a2d505ef22edb4f548bbf17c to your computer and use it in GitHub Desktop.
Save idac73/10cbfea1a2d505ef22edb4f548bbf17c to your computer and use it in GitHub Desktop.
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-09-28T23:49:53.031Z","extensionVersion":"v3.4.3"}
[
{
"metadata": {
"id": "e337c67b-55c2-4fef-8949-eb260e7fb7fd",
"publisherId": "Shan.code-settings-sync",
"publisherDisplayName": "Shan"
},
"name": "code-settings-sync",
"publisher": "Shan",
"version": "3.4.3"
},
{
"metadata": {
"id": "2bba45f2-4a48-41a6-bb86-d6ba5ab29a9f",
"publisherId": "felipecaputo.git-project-manager",
"publisherDisplayName": "felipecaputo"
},
"name": "git-project-manager",
"publisher": "felipecaputo",
"version": "1.7.1"
},
{
"metadata": {
"id": "5960f38e-0bbe-4644-8f9c-9c8824e82511",
"publisherId": "donjayamanne.githistory",
"publisherDisplayName": "donjayamanne"
},
"name": "githistory",
"publisher": "donjayamanne",
"version": "0.6.10"
},
{
"metadata": {
"id": "4de763bd-505d-4978-9575-2b7696ecf94e",
"publisherId": "eamodio.gitlens",
"publisherDisplayName": "eamodio"
},
"name": "gitlens",
"publisher": "eamodio",
"version": "10.2.2"
},
{
"metadata": {
"id": "0fcefdd8-e09c-4b96-9998-f5dc891893dd",
"publisherId": "nhoizey.gremlins",
"publisherDisplayName": "nhoizey"
},
"name": "gremlins",
"publisher": "nhoizey",
"version": "0.23.1"
},
{
"metadata": {
"id": "7b71fc1b-190d-4f7d-95d1-93e422649b0a",
"publisherId": "Zignd.html-css-class-completion",
"publisherDisplayName": "Zignd"
},
"name": "html-css-class-completion",
"publisher": "Zignd",
"version": "1.19.0"
},
{
"metadata": {
"id": "82dfe17d-bb64-404e-bcc5-f9803f7ab5d5",
"publisherId": "dbaeumer.jshint",
"publisherDisplayName": "dbaeumer"
},
"name": "jshint",
"publisher": "dbaeumer",
"version": "0.10.21"
},
{
"metadata": {
"id": "ef2a5b38-02c4-4193-8561-1f072c209474",
"publisherId": "silvenon.mdx",
"publisherDisplayName": "silvenon"
},
"name": "mdx",
"publisher": "silvenon",
"version": "0.1.0"
},
{
"metadata": {
"id": "08792992-bb56-41fb-b5dd-8551bbee0cb6",
"publisherId": "bpruitt-goddard.mermaid-markdown-syntax-highlighting",
"publisherDisplayName": "bpruitt-goddard"
},
"name": "mermaid-markdown-syntax-highlighting",
"publisher": "bpruitt-goddard",
"version": "1.0.3"
},
{
"metadata": {
"id": "dff6b801-247e-40e9-82e8-8c9b1d19d1b8",
"publisherId": "christian-kohler.npm-intellisense",
"publisherDisplayName": "christian-kohler"
},
"name": "npm-intellisense",
"publisher": "christian-kohler",
"version": "1.3.1"
},
{
"metadata": {
"id": "a41c1549-4053-44d4-bf30-60fc809b4a86",
"publisherId": "christian-kohler.path-intellisense",
"publisherDisplayName": "christian-kohler"
},
"name": "path-intellisense",
"publisher": "christian-kohler",
"version": "2.3.0"
},
{
"metadata": {
"id": "96fa4707-6983-4489-b7c5-d5ffdfdcce90",
"publisherId": "esbenp.prettier-vscode",
"publisherDisplayName": "esbenp"
},
"name": "prettier-vscode",
"publisher": "esbenp",
"version": "5.7.1"
},
{
"metadata": {
"id": "f1f59ae4-9318-4f3c-a9b5-81b2eaa5f8a5",
"publisherId": "ms-python.python",
"publisherDisplayName": "ms-python"
},
"name": "python",
"publisher": "ms-python",
"version": "2020.9.111407"
},
{
"metadata": {
"id": "aae0701b-111f-49c1-9000-abd37a442f28",
"publisherId": "WallabyJs.quokka-vscode",
"publisherDisplayName": "WallabyJs"
},
"name": "quokka-vscode",
"publisher": "WallabyJs",
"version": "1.0.320"
},
{
"metadata": {
"id": "797a79de-a0fd-4349-9034-bec47be9a941",
"publisherId": "2gua.rainbow-brackets",
"publisherDisplayName": "2gua"
},
"name": "rainbow-brackets",
"publisher": "2gua",
"version": "0.0.6"
},
{
"metadata": {
"id": "99789571-5d0c-4f5b-9fde-fa015906548c",
"publisherId": "mohsen1.react-javascript-to-typescript-transform-vscode",
"publisherDisplayName": "mohsen1"
},
"name": "react-javascript-to-typescript-transform-vscode",
"publisher": "mohsen1",
"version": "1.10.0"
},
{
"metadata": {
"id": "ae062c8a-c68e-4b92-9ecf-8f1d4288b05d",
"publisherId": "rebornix.ruby",
"publisherDisplayName": "rebornix"
},
"name": "ruby",
"publisher": "rebornix",
"version": "0.27.0"
},
{
"metadata": {
"id": "96509933-ee2a-42b8-ab76-e55b2a7b5107",
"publisherId": "ryanolsonx.snippet-creator",
"publisherDisplayName": "ryanolsonx"
},
"name": "snippet-creator",
"publisher": "ryanolsonx",
"version": "0.1.3"
},
{
"metadata": {
"id": "4ae6dc82-7981-4f10-bd81-2d72aec37f39",
"publisherId": "jock.svg",
"publisherDisplayName": "jock"
},
"name": "svg",
"publisher": "jock",
"version": "1.3.10"
},
{
"metadata": {
"id": "cb9cc98b-7140-4f13-b993-1e26c4a7bd42",
"publisherId": "Arjun.swagger-viewer",
"publisherDisplayName": "Arjun"
},
"name": "swagger-viewer",
"publisher": "Arjun",
"version": "3.0.1"
},
{
"metadata": {
"id": "0b2bcf1a-3630-47ec-9718-e153b0695f17",
"publisherId": "Tyriar.terminal-tabs",
"publisherDisplayName": "Tyriar"
},
"name": "terminal-tabs",
"publisher": "Tyriar",
"version": "0.2.0"
},
{
"metadata": {
"id": "f5d7ffda-c1d6-4070-ba80-803c705a1ee6",
"publisherId": "monokai.theme-monokai-pro-vscode",
"publisherDisplayName": "monokai"
},
"name": "theme-monokai-pro-vscode",
"publisher": "monokai",
"version": "1.1.17"
},
{
"metadata": {
"id": "0479fc1c-3d67-49f9-b087-fb9069afe48f",
"publisherId": "ms-azuretools.vscode-docker",
"publisherDisplayName": "ms-azuretools"
},
"name": "vscode-docker",
"publisher": "ms-azuretools",
"version": "1.6.0"
},
{
"metadata": {
"id": "583b2b34-2c1e-4634-8c0b-0b82e283ea3a",
"publisherId": "dbaeumer.vscode-eslint",
"publisherDisplayName": "dbaeumer"
},
"name": "vscode-eslint",
"publisher": "dbaeumer",
"version": "2.1.8"
},
{
"metadata": {
"id": "9ccc1dd7-7ec4-4a46-bd4f-7d7b8b9d322a",
"publisherId": "vscode-icons-team.vscode-icons",
"publisherDisplayName": "vscode-icons-team"
},
"name": "vscode-icons",
"publisher": "vscode-icons-team",
"version": "11.0.0"
},
{
"metadata": {
"id": "4837e4f3-1b01-4732-b1a6-daa57ef64cab",
"publisherId": "ms-kubernetes-tools.vscode-kubernetes-tools",
"publisherDisplayName": "ms-kubernetes-tools"
},
"name": "vscode-kubernetes-tools",
"publisher": "ms-kubernetes-tools",
"version": "1.2.1"
},
{
"metadata": {
"id": "daf8b44d-8aae-4da2-80c5-1f770219f643",
"publisherId": "DavidAnson.vscode-markdownlint",
"publisherDisplayName": "DavidAnson"
},
"name": "vscode-markdownlint",
"publisher": "DavidAnson",
"version": "0.36.3"
},
{
"metadata": {
"id": "2d6939dc-9776-4c55-bdbe-6af17c602141",
"publisherId": "xyc.vscode-mdx-preview",
"publisherDisplayName": "xyc"
},
"name": "vscode-mdx-preview",
"publisher": "xyc",
"version": "0.3.0"
},
{
"metadata": {
"id": "c7188ad2-f5c4-46c3-be65-5e264d565bdf",
"publisherId": "tomoyukim.vscode-mermaid-editor",
"publisherDisplayName": "tomoyukim"
},
"name": "vscode-mermaid-editor",
"publisher": "tomoyukim",
"version": "0.8.1"
},
{
"metadata": {
"id": "ae9e3eb0-3357-4cc0-90ee-598d2d384757",
"publisherId": "eg2.vscode-npm-script",
"publisherDisplayName": "eg2"
},
"name": "vscode-npm-script",
"publisher": "eg2",
"version": "0.3.13"
},
{
"metadata": {
"id": "5a7017bf-c571-4d77-b902-6e56b16f539a",
"publisherId": "johnpapa.vscode-peacock",
"publisherDisplayName": "johnpapa"
},
"name": "vscode-peacock",
"publisher": "johnpapa",
"version": "3.8.0"
},
{
"metadata": {
"id": "708cfcd8-e0c6-49ca-9af6-b27a342d247b",
"publisherId": "wingrunr21.vscode-ruby",
"publisherDisplayName": "wingrunr21"
},
"name": "vscode-ruby",
"publisher": "wingrunr21",
"version": "0.27.0"
},
{
"metadata": {
"id": "90a37ca1-92a2-488a-b196-7a8c0b0127ea",
"publisherId": "ms-vscode.vscode-typescript-tslint-plugin",
"publisherDisplayName": "ms-vscode"
},
"name": "vscode-typescript-tslint-plugin",
"publisher": "ms-vscode",
"version": "1.2.3"
},
{
"metadata": {
"id": "2061917f-f76a-458a-8da9-f162de22b97e",
"publisherId": "redhat.vscode-yaml",
"publisherDisplayName": "redhat"
},
"name": "vscode-yaml",
"publisher": "redhat",
"version": "0.11.0"
},
{
"metadata": {
"id": "0b94edb3-44e3-49a3-aed9-04b5d8510385",
"publisherId": "ms-vsonline.vsonline",
"publisherDisplayName": "ms-vsonline"
},
"name": "vsonline",
"publisher": "ms-vsonline",
"version": "1.0.2823"
},
{
"metadata": {
"id": "6f99be10-9aad-4b1c-8691-bcae8ae7b104",
"publisherId": "dariofuzinato.vue-peek",
"publisherDisplayName": "dariofuzinato"
},
"name": "vue-peek",
"publisher": "dariofuzinato",
"version": "1.0.2"
},
{
"metadata": {
"id": "0cb81da2-1880-4755-9995-0ae9cc728e20",
"publisherId": "DotJoshJohnson.xml",
"publisherDisplayName": "DotJoshJohnson"
},
"name": "xml",
"publisher": "DotJoshJohnson",
"version": "2.5.1"
}
]
// Place your settings in this file to overwrite the default settings
{
"editor.fontFamily": "'Source Code Pro', Menlo, Monaco, 'Courier New', monospace",
"editor.fontSize": 14,
"editor.tabSize": 2,
"workbench.colorTheme": "Monokai Pro (Filter Spectrum)",
// Format a file on save. A formatter must be available, the file must not be auto-saved, and editor must not be shutting down.
// "editor.formatOnSave": true,
// Support using flow through your node_modules folder, WARNING: Checking this box is a security risk. When you open a project we will immediately run code contained within it.
"flow.useNPMPackagedFlow": true,
// Enable/disable default JavaScript formatter (For Prettier)
"javascript.format.enable": true,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"jshint.options": {
"esversion": 9
},
"sync.gist": "10cbfea1a2d505ef22edb4f548bbf17c",
"sync.lastUpload": "2017-11-17T04:25:20.829Z",
"sync.autoDownload": false,
"sync.autoUpload": false,
"sync.lastDownload": "",
"sync.forceDownload": false,
"sync.anonymousGist": false,
"sync.host": "",
"sync.pathPrefix": "",
"sync.quietSync": false,
"sync.askGistName": false,
"workbench.panel.location": "bottom",
"workbench.startupEditor": "newUntitledFile",
"git.confirmSync": false,
"git.autofetch": true,
"gitlens.advanced.messages": {
"suppressCommitHasNoPreviousCommitWarning": false,
"suppressCommitNotFoundWarning": false,
"suppressFileNotUnderSourceControlWarning": false,
"suppressGitVersionWarning": false,
"suppressLineUncommittedWarning": false,
"suppressNoRepositoryWarning": false,
"suppressResultsExplorerNotice": false,
"suppressShowKeyBindingsNotice": true,
"suppressUpdateNotice": true,
"suppressWelcomeNotice": false
},
"gitlens.keymap": "chorded",
"gitlens.historyExplorer.enabled": true,
"gitlens.gitExplorer.files.layout": "auto",
"explorer.confirmDragAndDrop": false,
"javascript.updateImportsOnFileMove.enabled": "always",
"vs-kubernetes": {
"vs-kubernetes.helm-path": "/Users/thrashpunk/.vs-kubernetes/tools/helm/darwin-amd64/helm",
"vs-kubernetes.draft-path": "/Users/thrashpunk/.vs-kubernetes/tools/draft/darwin-amd64/draft",
"vs-kubernetes.minikube-path": "/Users/thrashpunk/.vs-kubernetes/tools/minikube/darwin-amd64/minikube",
"vs-kubernetes.kubectl-path": "/Users/thrashpunk/.vs-kubernetes/tools/kubectl/kubectl",
"vs-kubernetes.minikube-path.mac": "/Users/thrashpunk/.vs-kubernetes/tools/minikube/darwin-amd64/minikube"
},
"sync.removeExtensions": true,
"sync.syncExtensions": true,
"typescript.updateImportsOnFileMove.enabled": "always",
"window.zoomLevel": 0,
"window.newWindowDimensions": "maximized",
"breadcrumbs.enabled": true,
"gitlens.views.repositories.files.layout": "auto",
"gitlens.views.fileHistory.enabled": true,
"gitlens.views.lineHistory.enabled": true,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"workbench.iconTheme": "Monokai Pro (Filter Spectrum) Icons",
"editor.largeFileOptimizations": false,
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"vsicons.dontShowNewVersionMessage": true,
"sync.forceUpload": true,
"eslint.alwaysShowStatus": true,
"editor.formatOnPaste": true,
"peacock.favoriteColors": [
{
"name": "Angular Red",
"value": "#b52e31"
},
{
"name": "Auth0 Orange",
"value": "#eb5424"
},
{
"name": "Azure Blue",
"value": "#007fff"
},
{
"name": "C# Purple",
"value": "#68217A"
},
{
"name": "Gatsby Purple",
"value": "#639"
},
{
"name": "Go Cyan",
"value": "#5dc9e2"
},
{
"name": "Java Blue-Gray",
"value": "#557c9b"
},
{
"name": "JavaScript Yellow",
"value": "#f9e64f"
},
{
"name": "Mandalorian Blue",
"value": "#1857a4"
},
{
"name": "Node Green",
"value": "#215732"
},
{
"name": "React Blue",
"value": "#00b3e6"
},
{
"name": "Sparks Red",
"value": "#E43D22"
},
{
"name": "Something Different",
"value": "#832561"
},
{
"name": "Vue Green",
"value": "#42b883"
}
],
"peacock.affectStatusBar": false,
"peacock.surpriseMeOnStartup": true,
"editor.cursorSurroundingLines": 1,
"peacock.affectAccentBorders": true,
"peacock.affectTabActiveBorder": true,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"vsonline.authentication.accountProvider": "Microsoft",
"vsonline.accountProvider": "Microsoft",
"codespaces.accountProvider": "Microsoft",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. 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": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
}
{
"Value from Dot Notation": {
"prefix": "Value from Dot Notation",
"body": [
"const obj = { a: 2, b: { a: 'x', b: [1, { a: 3 }] } };",
"",
"const access = (obj, path) => {",
" return path",
" .split('.')",
" .reduce(",
" (myObj, key) => (myObj && myObj[key] ? myObj[key] : undefined),",
" obj",
" );",
"};",
"",
"console.log(access(obj, 'a'));",
"console.log(access(obj, 'b.a'));",
"console.log(access(obj, 'b.b.1'));",
"console.log(access(obj, 'b.b.1.a'));",
"console.log(access(obj, 'b.b.5.c'));",
""
],
"description": "value from dot notation"
},
"Flatten Object with Keys Preserving Heirarchy": {
"prefix": "Flatten Object with Keys Preserving Heirarchy",
"body": [
"const user = {",
" name: 'Josh',",
" address: {",
" primary: {",
" house: '45',",
" street: {",
" main: '21',",
" cross: '32',",
" },",
" },",
" },",
"};",
"const flattenObject = (obj, keyName) => {",
" let flattendObj = {};",
" Object.keys(obj).forEach((key) => {",
" let newKey = `${keyName}_${key}`;",
" if (typeof obj[key] === 'object' && !flattendObj.hasOwnProperty(newKey)) {",
" Object.assign(flattendObj, flattenObject(obj[key], newKey));",
" } else {",
" flattendObj[newKey] = obj[key];",
" }",
" });",
" return flattendObj;",
"};",
"console.log(flattenObject(user, 'user'));"
],
"description": "Flatten Object with Keys Preserving Heirarchy"
},
"async await": {
"prefix": "async await",
"body": [
"async function getData(url) {",
" try {",
" const response = await fetch(url);",
" if (response.ok) {",
" const data = await response.json();",
" return data;",
" } else {",
" throw new Error(",
" `Data request failed due to http error code: ${response.status}`",
" );",
" }",
" } catch (error) {",
" console.log(error.message);",
" return false;",
" }",
"}",
"",
"const fetchAndStore = (url, store) => {",
" getData(url).then((data) => {",
" if (data) {",
" store.push(...data.results);",
" appInit(store);",
" } else {",
" console.log(`Fetch data failed for: ${url}`);",
" }",
" });",
"};"
],
"description": "async await"
},
"Apply / Call example": {
"prefix": "Apply / Call example",
"body": [
"const obj1 = {",
" result: 0,",
"};",
"",
"const obj2 = {",
" result: 0,",
"};",
"",
"function reduceAdd() {",
" let result = 0;",
" for (let i = 0, len = arguments.length; i < len; i++) {",
" result += arguments[i];",
" }",
" this.result = result;",
" return this;",
"}",
"",
"reduceAdd.apply(obj1, [1, 2, 3, 4, 5]);",
"reduceAdd.call(obj2, 6, 7, 8, 9, 10);",
"",
"console.log(obj1); // { result: 15 }",
"console.log(obj2); // { result: 40 }",
""
],
"description": "Apply / Call example"
},
"Type Fuctions": {
"prefix": "Type Fuctions",
"body": [
"anythingGoes: (...args: any[]) => any;",
"firstArgString: (arg0: string) => any;",
"firstArgTypeSecondArgOption: (arg0: PlatformAuthProps, arg1: 'option 1' | 'option 2') => any;"
],
"description": "Type Fuctions"
},
"Create a type based on an array of another type": {
"prefix": "Create a type based on an array of another type",
"body": [
"type Experience = {",
" experienceDescription: string,",
" experienceEligibleProducts: string[],",
" experienceEnrollmentLimit: number,",
" experienceID: string,",
" experienceName: string,",
"};",
"",
"export type Experiences = Array<Experience> | null;",
""
],
"description": "Create a type based on an array of another type"
},
"Merge two JSON by replacing one property with another": {
"prefix": "Merge two JSON by replacing one property with another",
"body": [
"const mergePeopleAndStarshipsData = () => {",
" PEOPLE_DATA.forEach((person) => {",
" STARSHIPS_DATA.forEach((starship) => {",
" starship.pilots.forEach((pilot) => {",
" if (pilot === person.url) {",
" const pilotStartshipIndex = PILOTS_STARSHIPS_DATA.findIndex(",
" (data) => data.url === person.url",
" );",
" const { pilots, ...starshipNoPilots } = starship;",
" if (pilotStartshipIndex > -1) {",
" PILOTS_STARSHIPS_DATA[pilotStartshipIndex].starships.push(",
" starshipNoPilots",
" );",
" } else {",
" PILOTS_STARSHIPS_DATA.push(person);",
" const pilotsStarhipsDataIndex =",
" PILOTS_STARSHIPS_DATA.length > 0",
" ? PILOTS_STARSHIPS_DATA.length - 1",
" : 0;",
" PILOTS_STARSHIPS_DATA[pilotsStarhipsDataIndex].starships.length = 0;",
" PILOTS_STARSHIPS_DATA[pilotsStarhipsDataIndex].starships.push(",
" starshipNoPilots",
" );",
" }",
" }",
" });",
" });",
" });",
" return PILOTS_STARSHIPS_DATA;",
"};",
""
],
"description": "Merge two JSON by replacing one property with another"
},
"Array secondary sort": {
"prefix": "Array secondary sort",
"body": [
"const secondarySort = () => {",
" const sorted = PEOPLE_DATA;",
" sorted.sort((a, b) =>",
" a.homeworld > b.homeworld",
" ? 1",
" : a.homeworld === b.homeworld",
" ? a.name > b.name",
" ? 1",
" : -1",
" : -1",
" );",
" return sorted;",
"};"
],
"description": "Array secondary sort"
},
"Compositional Inheritance": {
"prefix": "Compositional Inheritance",
"body": [
"// We have some behaviors",
"const canSayHi = (self) => ({",
" sayHi: () => console.log(`Hi! I'm ${self.name}`),",
"});",
"const canEat = () => ({",
" eat: (food) => console.log(`Eating ${food}...`),",
"});",
"const canPoop = () => ({",
" poop: () => console.log('Going to 💩...'),",
"});",
"",
"// Combined previous behaviours",
"const socialBehaviors = (self) =>",
" Object.assign({}, canSayHi(self), canEat(), canPoop());",
"",
"const alligator = (name) => {",
" const self = {",
" name,",
" };",
"",
" const alligatorBehaviors = (self) => ({",
" bite: () => console.log('Yum yum!'),",
" });",
"",
" return Object.assign(self, socialBehaviors(self), alligatorBehaviors(self));",
"};",
"",
"const jack = alligator('jack');",
"jack.sayHi(); // Hi! I'm jack",
"jack.eat('Banana'); // Eating Banana...",
"jack.bite(); // Yum yum!",
""
],
"description": "Compositional Inheritance"
},
"Object Inheritance": {
"prefix": "Object Inheritance",
"body": [
"class Person {",
" constructor(name) {",
" this.name = name;",
" }",
"}",
"",
"class Student extends Person {",
" constructor(grade, ...args) {",
" super(...args);",
" this.grade = grade;",
" }",
" takeTest() {",
" console.log(this.name + \" takes a test\");",
" }",
" gotGrade() {",
" console.log(this.name + \" got a grade of \" + this.grade);",
" }",
"}",
"",
"class Teacher extends Student {",
" constructor(tenure, ...args) {",
" super(...args);",
" this.tenure = tenure;",
" }",
" gradesTest() {",
" console.log(this.name + \" grades the test\");",
" }",
" hasTenure() {",
" console.log(this.name + \" has \" + this.tenure + \" years of tenure.\");",
" }",
"}",
"",
"class Principal extends Teacher {",
" constructor(cash, ...args) {",
" super(...args);",
" this.cash = cash;",
" }",
" hiresTeacher(description) {",
" console.log(this.name + \" hires a \" + description + \" teacher\");",
" }",
"}",
"",
"const Al = new Student(\"A\", \"Al\");",
"const Josh = new Teacher(5, \"B\", \"Josh\");",
"const Jess = new Principal(200, 10, \"C\", \"Jess\");",
"",
"Jess.takeTest();",
"",
"Jess.gotGrade();",
"",
"Jess.hiresTeacher(\"new\");",
"",
"Jess.hasTenure();",
""
],
"description": "Object Inheritance"
},
"Object Inheritance 2": {
"prefix": "Object Inheritance 2",
"body": [
"'use strict';",
"",
"const Engine = {",
" accelerate(speed, incrementSpeed) {",
" return speed + incrementSpeed;",
" },",
" decelerate(speed, decrementSpeed) {",
" return speed - decrementSpeed;",
" },",
"};",
"",
"const Breaks = {",
" stop(speed) {",
" if (speed > 0) this.stop(speed - 3);",
"",
" return 0;",
" },",
"};",
"",
"const Design = {",
" colour: 'Orange',",
" model: 'Huracan Spyder',",
"};",
"",
"Object.seal(Design);",
"",
"const Lambo = function (Design, Engine, Breaks) {",
" const design = Object.create(Design);",
" const engine = Object.create(Engine);",
" const breaks = Object.create(Breaks);",
" const props = {",
" speed: 0,",
" colour: design.colour,",
" model: design.model,",
" seats: design.seats,",
" toilet: design.toilet,",
" };",
" Object.seal(props);",
" return {",
" set(name, value) {",
" props[name] = value;",
" },",
"",
" get(name) {",
" return props[name];",
" },",
"",
" log(name) {",
" console.log(`${name}: ${props[name]}`);",
" },",
"",
" slowDown() {",
" props.speed = engine.decelerate(props.speed, 3);",
" },",
"",
" speedUp() {",
" props.speed = engine.accelerate(props.speed, 3);",
" },",
"",
" stop() {",
" props.speed = breaks.stop(props.speed);",
" },",
" };",
"};",
"",
"const lambo = Lambo(Design, Engine, Breaks);",
"lambo.set('speed', 200);",
"lambo.log('speed');",
"lambo.speedUp();",
"lambo.log('speed'); //-> 3",
"lambo.slowDown();",
"lambo.log('speed'); //-> 0",
"lambo.stop();",
"lambo.log('speed');",
"lambo.log('colour'); //-> orange",
"// we can change the colour",
"lambo.set('colour', 'black');",
"// see it has changed",
"lambo.log('colour'); //-> black",
"",
"const bookah = Lambo(Design, Engine, Breaks);",
"bookah.log('colour');",
"bookah.set('seats', 'velvet');",
"bookah.log('seats');",
"bookah.set('rims', 'chrome');",
"bookah.log('rims');",
""
],
"description": "Object Inheritance 2"
},
"Recursion 1": {
"prefix": "Recursion 1",
"body": [
"let company = {",
" // the same object, compressed for brevity",
" sales: [",
" { name: \"John\", salary: 1000 },",
" { name: \"Alice\", salary: 1600 },",
" ],",
" development: {",
" sites: [",
" { name: \"Peter\", salary: 2000 },",
" { name: \"Alex\", salary: 1800 },",
" ],",
" internals: [{ name: \"Jack\", salary: 1300 }],",
" },",
"};",
"",
"// The function to do the job",
"function sumSalaries(department) {",
" if (Array.isArray(department)) {",
" // case (1)",
" return department.reduce((prev, current) => prev + current.salary, 0); // sum the array",
" } else {",
" // case (2)",
" console.log(\"wut\");",
" let sum = 0;",
" for (let subdep of Object.values(department)) {",
" sum += sumSalaries(subdep); // recursively call for subdepartments, sum the results",
" }",
" return sum;",
" }",
"}",
"",
"console.log(sumSalaries(company)); // 7700",
"console.log(sumSalaries(company.sales)); // 2600",
""
],
"description": "Recursion 1"
},
"Linked List": {
"prefix": "Linked List",
"body": [
"function LinkedList() {",
" this.head = null;",
" this.tail = null;",
"}",
"",
"function Node(value, next, prev) {",
" this.value = value;",
" this.next = next;",
" this.prev = prev;",
"}",
"",
"// Add nodes methods",
"",
"LinkedList.prototype.addToHead = function (value) {",
" const newNode = new Node(value, this.head, null);",
" if (this.head) this.head.prev = newNode;",
" else this.tail = newNode;",
" this.head = newNode;",
"};",
"",
"LinkedList.prototype.addToTail = function (value) {",
" const newNode = new Node(value, null, this.tail);",
" if (this.tail) this.tail.next = newNode;",
" else this.head = newNode;",
" this.tail = newNode;",
"};",
"",
"// Remove nodes methods",
"LinkedList.prototype.removeHead = function () {",
" if (!this.head) return null;",
" let value = this.head.value;",
" this.head = this.head.next;",
"",
" if (this.head) this.head.prev = null;",
" else this.tail = null;",
"",
" return value;",
"};",
"",
"LinkedList.prototype.removeTail = function () {",
" if (!this.tail) return null;",
" let value = this.tail.value;",
" this.tail = this.tail.prev;",
"",
" if (this.tail) this.tail.next = null;",
" else this.head = null;",
"",
" return value;",
"};",
"",
"// Search method",
"",
"LinkedList.prototype.search = function (searchValue) {",
" let currentNode = this.head;",
"",
" while (currentNode) {",
" if (currentNode.value === searchValue) return currentNode;",
" currentNode = currentNode.next;",
" }",
" return null;",
"};",
"",
"const list = new LinkedList();",
"",
"list.addToHead(1);",
"list.addToTail(2);",
"",
"console.log(list.search(1));",
"console.log(list.search(2));",
"console.log(list.search(3000));",
""
],
"description": "Linked List"
},
"Linked List - SwapEveryTwo": {
"prefix": "Linked List - SwapEveryTwo",
"body": [
"function LinkedList() {",
" this.head = null;",
" this.tail = null;",
"}",
"",
"function Node(value, next) {",
" this.value = value;",
" this.next = next;",
"}",
"",
"function swapEveryTwo(head) {",
" if (!head || !head.next) {",
" return head;",
" }",
"",
" let second = head.next;",
" let third = second.next;",
" second.next = head;",
"",
" head.next = swapEveryTwo(third);",
" return second;",
"}",
"",
"const list = new Node(1);",
"list.next = new Node(2);",
"list.next.next = new Node(3);",
"list.next.next.next = new Node(4);",
"",
"console.log(JSON.stringify(swapEveryTwo(list)));",
""
],
"description": "Linked List - SwapEveryTwo"
},
"uuid": {
"prefix": "uuid",
"body": [
"function uuidv4() {",
" return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>",
" (",
" c ^",
" (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))",
" ).toString(16)",
" );",
"}",
"",
"console.log(uuidv4());",
"",
"function uuidv4Basic() {",
" return \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, function (c) {",
" var r = (Math.random() * 16) | 0,",
" v = c == \"x\" ? r : (r & 0x3) | 0x8;",
" return v.toString(16);",
" });",
"}",
"",
"console.log(uuidv4Basic());",
""
],
"description": "uuid"
},
"Event Delegation": {
"prefix": "Event Delegation",
"body": [
"function addEvent(el, event, callback, useCapture = false) {",
" if (!el || !event || !callback || typeof callback !== \"function\") return;",
" if (typeof el === \"string\") {",
" el = document.querySelector(el);",
" }",
" el.addEventListener(event, callback, useCapture);",
"}",
"",
"addEvent(document, \"DOMContentLoaded\", () => {",
" const child = document.querySelector(\".child\");",
" const parent = document.querySelector(\".parent\");",
" const grandparent = document.querySelector(\".grandparent\");",
"",
" addEvent(child, \"click\", function (e) {",
" console.log(\"child\");",
" });",
"",
" addEvent(parent, \"click\", function (e) {",
" console.log(\"parent\");",
" });",
"",
" addEvent(grandparent, \"click\", function (e) {",
" console.log(\"grandparent\");",
" });",
"",
" addEvent(document, \"click\", function (e) {",
" console.log(\"document\");",
" });",
"",
" addEvent(\"html\", \"click\", function (e) {",
" console.log(\"html\");",
" });",
"",
" addEvent(window, \"click\", function (e) {",
" console.log(\"window\");",
" });",
"});",
""
],
"description": "Event Delegation"
},
"Filter Map Reduce": {
"prefix": "Filter Map Reduce",
"body": [
"function filter(arr, filterCallback) {",
" if (!Array.isArray(arr) || !arr.length || typeof filterCallback !== 'function') ",
" {",
" return [];",
" } else {",
" let result = [];",
" for (let i = 0, len = arr.length; i < len; i++) {",
" if (filterCallback(arr[i], i, arr)) { ",
" result.push(arr[i]);",
" }",
" }",
" return result;",
" }",
"}",
"",
"function map(arr, mapCallback) {",
" if (!Array.isArray(arr) || !arr.length || typeof mapCallback !== 'function') { ",
" return [];",
" } else {",
" let result = [];",
" for (let i = 0, len = arr.length; i < len; i++) {",
" result.push(mapCallback(arr[i], i, arr)); ",
" }",
" return result;",
" }",
"}",
"",
"function reduce(arr, reduceCallback, initialValue) {",
" if (!Array.isArray(arr) || !arr.length || typeof reduceCallback !== 'function') ",
" {",
" return [];",
" } else {",
" let hasInitialValue = initialValue !== undefined;",
" let value = hasInitialValue ? initialValue : arr[0];",
"",
" for (let i = hasInitialValue ? 0 : 1, len = arr.length; i < len; i++) {",
" value = reduceCallback(value, arr[i], i, arr); ",
" }",
" return value;",
" }",
"}"
],
"description": "Filter Map Reduce"
},
"settimeout iife": {
"prefix": "settimeout iife",
"body": [
"for (var i = 0; i < 5; i++) {",
" ((n) => {",
" setTimeout(() => {",
" console.log(n);",
" }, 1000);",
" })(i);",
"}"
],
"description": "settimeout iife"
},
"Recursion Basic": {
"prefix": "Recursion Basic",
"body": [
"function factorial(num) {",
" if (num === 1) {",
" return num;",
" } else {",
" return num * factorial(num - 1);",
" }",
"}",
""
],
"description": "Recursion Basic"
},
"balanced sets matched pairs": {
"prefix": "Balanced Sets Matched Pairs",
"body": [
"let isBalancedParenthesis = (str) => {",
" return !str.split(\"\").reduce((uptoPrevChar, thisChar) => {",
" if (thisChar === \"(\" || thisChar === \"{\" || thisChar === \"[\") {",
" return ++uptoPrevChar;",
" } else if (thisChar === \")\" || thisChar === \"}\" || thisChar === \"]\") {",
" return --uptoPrevChar;",
" }",
"",
" return uptoPrevChar;",
" }, 0);",
"};",
"",
"console.log(isBalancedParenthesis(\"[()]{}{[()()]()}\")); // returns true",
"console.log(isBalancedParenthesis(\"[{()()}({[]})]({}[({})])((((((()[])){}))[]{{{({({({{{{{{}}}}}})})})}}}))[][][]\")); // returns true",
"console.log(isBalancedParenthesis(\"({(()))}}\")); // returns false"
],
"description": "balanced sets matched pairs"
},
"Traverse Object": {
"prefix": "Traverse Object",
"body": [
"const traverse = (x) => {",
" if (isArray(x)) {",
" traverseArray(x)",
" } else if ((typeof x === 'object') && (x !== null)) {",
" traverseObject(x)",
" } else {",
"",
" }",
"}",
"",
"const traverseArray = (arr) => {",
" arr.forEach(function (x) {",
" traverse(x)",
" })",
"}",
"",
"const traverseObject = (obj) => {",
" for (const key in obj) {",
" if (obj.hasOwnProperty(key)) {",
" traverse(obj[key])",
" }",
" }",
"}",
"",
"const isArray = (o) => {",
" return Object.prototype.toString.call(o) === '[object Array]'",
"}",
"",
"// usage:",
"traverse(largeObject)"
],
"description": "Traverse Object"
},
"Recursive Directory Print": {
"prefix": "Recursive Directory Print",
"body": [
"function printSubFiles(dir) {",
" files = fs.readdirSync(dir);",
" files.forEach(function (file) {",
" absName = `${dir}/${file}`;",
" if (fs.statSync(absName).isDirectory()) {",
" printSubFiles(absName);",
" } else {",
" // base case, stop recurring",
" console.log(file);",
" }",
" });",
"}",
""
],
"description": "Recursive Directory Print"
}
}
{
"SQL Queries": {
"prefix": "SQL Queries",
"body": [
"-- Inner Join",
"SELECT *",
"FROM Table_A",
"JOIN Table_B;",
"",
"SELECT *",
"FROM Table_A",
"INNER JOIN Table_B;",
"",
"-- Left Outer Join",
"SELECT *",
"FROM Table_A A",
"LEFT JOIN Table_B B",
"ON A.col = B.col;",
"",
"-- Right Outer Join",
"SELECT *",
"FROM Table_A A",
"RIGHT JOIN Table_B B",
"ON A.col = B.col;",
"",
"-- Full Outer Join",
"SELECT *",
"FROM Table_A A",
"FULL JOIN Table_B B",
"ON A.col = B.col;",
"",
"-- Self Join",
"SELECT A.emp_id AS \"Emp_ID\",A.emp_name AS \"Employee\",",
"B.emp_id AS \"Sup_ID\",B.emp_name AS \"Supervisor\"",
"FROM employee A, employee B",
"WHERE A.emp_sup = B.emp_id;",
"",
"-- Cross Join",
"SELECT stu.name, sub.subject ",
"FROM students AS stu",
"CROSS JOIN subjects AS sub;",
"",
"-- Sub / Nested Query",
"SELECT name, email, mob, address",
"FROM myDb.contacts",
"WHERE roll_no IN (",
"\\t SELECT roll_no",
"\\t FROM myDb.students",
"\\t WHERE subject = 'Maths');",
"",
"-- Match options:",
"SELECT * \\t /* Matches first names with five or more letters OR where K is the 3rd letter */",
"FROM students",
"WHERE first_name LIKE '_____%' OR LIKE '__K%'",
"",
"-- Return limi",
"SELECT *",
"FROM students",
"ORDER BY age ASC",
"LIMIT 1 OFFSET 1;"
],
"description": "SQL Queries"
}
}
{
"CSS JSS ordered list": {
"prefix": "CSS JSS ordered list",
"body": [
"ol: {",
" '& > li': {",
" listStyleType: 'none',",
" marginBottom: '0.75rem'",
" },",
" '& > li::before': {",
" content: 'counter(ordered-list) \". \"',",
" 'counter-increment': 'ordered-list'",
" },",
" '& li > ol': {",
" 'counter-reset': 'nestedOrdered-list'",
" },",
" '& li > ol > li::before': {",
" content: 'counter(nestedOrdered-list, lower-roman) \". \"',",
" 'counter-increment': 'nestedOrdered-list'",
" },",
" '& ul > li::before': {",
" content: 'none'",
" },",
" 'counter-reset': 'ordered-list',",
" listStyleType: 'none'",
"}"
],
"description": "CSS JSS ordered list"
},
"cURL commands": {
"prefix": "cURL commands",
"body": [
"/**",
" * Basic GET",
" * curl https://google.com",
" * Return only headers",
" * curl -I https://google.com",
" * Add additional header",
" * curl -H \"X-Header: value\" https://google.com",
" * Resume Download",
" * curl -C - -O https://google.com/myDownload.zip",
" * Test Download Time",
" * curl -D - https://google.com/myDownload.zip -o /dev/null",
" * Set Max Transfer rate (can set K, M, G)",
" * curl --limit-rate 200K -O https://google.com/myDownload.zip ",
" * HTTP/2 support check",
" * curl -I --http2 https://google.com",
" * Retrieving a particular byte-range",
" * curl -r 0-20000 -o myOtherFile.zip https://google.com/myDownload.zip",
" * Request methods DELETE, GET, POST, PUT",
" * curl --request GET https://google.com ",
" * Send data with cURL",
" * curl -X POST https://google.com/ -d 'username=yourusername&password=yourpassword'",
"*/ ",
""
],
"description": "cURL commands"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment