Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>BetterSnippetsNew to Visual Studio Code? Get it now.
BetterSnippets

BetterSnippets

ExtensionsMG

|
16 installs
| (0) | Free
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Snippets Collection

This collection includes snippets for Python, CSS, HTML, and JavaScript to enhance development efficiency. Here's the updated list:




Python Snippets

Data Science Utilities

  • Prefix: tools-imports
  • Description: Imports all required libraries (pandas, numpy, seaborn, matplotlib, scipy.stats, statsmodels, sklearn) for plotting and statistical analysis snippets.


Plotting and Visualization Snippets

  • Prefix: plot-histogram
  • Description: Plots a histogram for a single column with dynamically calculated bins. Optionally enables KDE with kde=True.

  • Prefix: plot-histogram-multi
  • Description: Plots overlapping histograms for multiple categories with customizable transparency, dynamically handling all unique values in the category column.

  • Prefix: plot-boxplot
  • Description: Creates a boxplot for a single numerical column with a whisker length of 1.5 IQR.

  • Prefix: plot-boxplot-multi
  • Description: Creates a boxplot comparing a numerical column across categories, dynamically handling multiple category levels.

  • Prefix: plot-boxplot-subplots
  • Description: Creates side-by-side boxplots for multiple conditions with consistent y-axis limits, dynamically handling all unique values in the category column.

  • Prefix: plot-countplot
  • Description: Creates a count plot for a categorical column with dynamic category labels.

  • Prefix: plot-histogram-normal-distribution
  • Description: Plots a histogram with hue and overlaid normal distribution curves for each hue category.

  • Prefix: plot-heatmap-corr
  • Description: Plots a heatmap of correlation coefficients for selected numerical columns with customizable correlation method (pearson, spearman, kendall). Specify columns as individual names, e.g., 'col1', 'col2'.

  • Prefix: plot-pairplot
  • Description: Generates a pairplot for selected columns, with customizable diagonal plot type (hist or kde).

  • Prefix: plot-linear-regression
  • Description: Plots a scatter plot with a linear regression line and prints model parameters.

  • Prefix: plot-lineplot-df
  • Description: Creates a line plot for selected numerical columns in a dataframe with customizable legend. Specify columns as a list, e.g., ['col1', 'col2'].

  • Prefix: plot-autocorrelation
  • Description: Plots the autocorrelation function for a specified column with customizable lag count.

  • Prefix: plot-lineplot-multi
  • Description: Plots multiple numerical columns as lines with a customizable color palette (e.g., Set2, viridis) and legend. Specify columns as individual names, e.g., 'col1', 'col2'.

  • Prefix: plot-bar
  • Description: Creates a bar plot comparing a numerical value across categories with a customizable palette (e.g., husl, Set2) and label rotation. Specify columns as individual names, e.g., 'category', 'value'.

  • Prefix: plot-violin
  • Description: Creates a violin plot showing the distribution of a numerical column across categories with a customizable palette (e.g., husl, Set2) and label rotation. Specify columns as individual names, e.g., 'category', 'value'.

  • Prefix: plot-scatter
  • Description: Creates a scatter plot of two numerical columns with customizable hue, size, and palette (e.g., deep, muted). Specify columns as individual names, e.g., 'x_col', 'y_col'.


Statistical Analysis Snippets

  • Prefix: stat-statistical-measures
  • Description: Computes various statistical measures (min, max, mean, median, mode, variance, etc.) for a numerical DataFrame column. Ensures the column is numeric.

  • Prefix: stat-statistical-outliers
  • Description: Detects outliers using Z-scores and the IQR method for a numerical DataFrame column. Requires mean_value, std_dev, Q1, Q3, and IQR from stat-statistical-measures.

  • Prefix: stat-linreg-direction
  • Description: Fits a linear regression model using a specified predictor column and prints the intercept, slope coefficient, and R² score.

  • Prefix: stat-trendline-residuals
  • Description: Calculates the trendline and residuals from a linear regression model. Requires regression_model from stat-linreg-direction.

  • Prefix: stat-exp-smoothing
  • Description: Optimizes the alpha parameter for exponential smoothing of residuals and applies it. Requires residuals from stat-trendline-residuals. Step size is configurable.

  • Prefix: stat-pred-exp-smoothing
  • Description: Predicts values using trendline and exponentially smoothed residuals, then calculates MAE. Requires trendline from stat-trendline-residuals and exp_smooth from stat-exp-smoothing.

  • Prefix: stat-pred-seasonal-reg
  • Description: Adjusts trendline with seasonal averages by a grouping column and calculates MAE. Requires trendline and residuals from stat-trendline-residuals. Uses vectorized operations.

  • Prefix: stat-moving-average-mape
  • Description: Calculates moving average, absolute error, and MAPE for a numerical column with a specified window size, shifted by one period. Handles division by zero with NaN. Includes error checking. Requires pandas and numpy.

  • Prefix: stat-exp-smoothing-mae
  • Description: Applies exponential smoothing to a column with a specified alpha, computes MAE, and prints it. Requires pandas.

  • Prefix: stat-check-missing
  • Description: Checks for missing values in a DataFrame and handles them by dropping rows or filling with column means. Requires pandas.

  • Prefix: stat-clean-outliers-iqr
  • Description: Fills missing values with mean and removes outliers from a numeric column using the IQR method. Requires pandas.

  • Prefix: stat-clean-outliers-std
  • Description: Fills missing values with mean and removes outliers from a numeric column using the STD method. Requires pandas.

  • Prefix: stat-interpolate
  • Description: Interpolates missing values in numeric columns using linear interpolation. Requires pandas.

  • Prefix: stat-timeseries-resample
  • Description: Converts a date column to datetime and resamples a value column to monthly averages. Requires pandas.

  • Prefix: stat-onehot-encode
  • Description: Performs one-hot encoding on a categorical column and drops the original column. Requires pandas.


MySQL Snippets

  • Prefix: mysql-config
  • Description: Configuration file template for MySQL connection settings. Includes placeholders for user, host, port, password, database, and driver, used by mysql-connector-python.

  • Prefix: mysql-dboperations
  • Description: A class for managing MySQL database operations with connection management using a configuration file. Includes methods for reading data (get_rows, get_one_row) and executing CRUD operations (execute_sql) with robust error handling and transaction support.

  • Prefix: mysql-create
  • Description: Creates a new record in the specified table with the given columns and values using a parameterized query to prevent SQL injection.

  • Prefix: mysql-read-by-id
  • Description: Reads a single record from the specified table by its ID using a parameterized query.

  • Prefix: mysql-update
  • Description: Updates specified columns in a record of the given table based on the ID using a parameterized query.

  • Prefix: mysql-patch
  • Description: Updates specified column in a record of the given table based on the ID using a parameterized query.

  • Prefix: mysql-soft-delete
  • Description: Soft deletes a record in the specified table by setting 'is_deleted' to 1 based on the ID using a parameterized query.

  • Prefix: mysql-delete
  • Description: Deletes a record from the specified table by its ID using a parameterized query.

  • Prefix: mysql-read-all
  • Description: Reads all records from the specified table.


Socket.IO Snippets

  • Prefix: socketio-server
  • Description: Initialize python-socketio AsyncServer. Requires an existing ASGI application (e.g., app = FastAPI()) for socketio_app. Use specific CORS origins in production for security.

  • Prefix: socketio-on
  • Description: Define a Socket.IO event handler. Emits to the triggering client (room=sid) or omit room to broadcast to all clients.

  • Prefix: socketio-connect
  • Description: Emit initial data to the connecting client on Socket.IO connect (room=sid). Omit room to broadcast to all clients. Requires DataRepository.read_all() to be implemented.

  • Prefix: socketio-emit
  • Description: Emits a Socket.IO event to all clients (if room is omitted) or a specific room/session ID (if room=${5:sid} is included).

  • Prefix: socketio-on-disconnect
  • Description: Handles client disconnection. Add emit without room to notify all clients.

  • Prefix: socketio-join-room
  • Description: Joins a client to a Socket.IO room and notifies others in the room. Omit room to broadcast to all clients.

  • Prefix: socketio-leave-room
  • Description: Removes a client from a Socket.IO room and notifies others in the room. Omit room to broadcast to all clients.


FastAPI Snippets

  • Prefix: fastapi-get-all
  • Description: FastAPI endpoint to retrieve all items of a resource. Returns a list of items or raises a 404 if none are found. Requires Python 3.9+ for list[${2:DTOModel}] type hint.

  • Prefix: fastapi-get-one
  • Description: FastAPI endpoint to retrieve a single item of a resource by its ID. Returns the item or raises a 404 if not found.

  • Prefix: fastapi-post-create
  • Description: FastAPI endpoint to create a new item of a resource. Returns the created item or raises a 400 if creation fails.

  • Prefix: fastapi-put-update
  • Description: FastAPI endpoint to update an existing item of a resource by its ID. Returns the updated item or raises a 404 if not found, or a 400 if the update fails.

  • Prefix: fastapi-patch-field
  • Description: FastAPI PATCH endpoint to update a specific field of a resource by ID using a Pydantic DTO. Returns the updated item or raises a 404 if not found, or a 400 if the update fails. Replace ${5:field_name} with the DTO field name.

  • Prefix: fastapi-delete
  • Description: FastAPI endpoint to delete an item of a resource by its ID. Returns a confirmation message or raises a 404 if not found, or a 400 if deletion fails.

  • Prefix: fastapi-lifespan
  • Description: Define a FastAPI async lifespan manager.

  • Prefix: fastapi-cors
  • Description: Instantiate FastAPI with CORS, configured for local development by default.

  • Prefix: fastapi-uvicorn
  • Description: Entrypoint for running a FastAPI application with Uvicorn. Adjust ${1:module} to the module and ${2:app_name} to the app instance.


General Python Snippets

  • Prefix: property-getter-setter
  • Description: Creates a property with getter and setter methods, including type validation. Raises a TypeError if the value is not of the expected type. Requires a valid Python type (e.g., int, str) for ${2:type} and initialization of the private attribute in the class (e.g., in init).

  • Prefix: read-json-function
  • Description: Reads a JSON file and returns the parsed content. Includes error handling for file not found, invalid JSON, permission issues, and other I/O errors, with logging for debugging. Requires logging configuration (e.g., logging.basicConfig()) for logs to be visible. Returns Any to accommodate various JSON types (dict, list, str, etc.).


JavaScript Snippets

  • Prefix: initDom
  • Description: Creates an init function and binds it to DOMContentLoaded.

  • Prefix: socketkMsg
  • Description: Socket.io listener for 'B2F_message' event.

  • Prefix: buttonClick
  • Description: Adds a click event listener to a button.

  • Prefix: updateHTML
  • Description: Selects a detail container and sets its innerHTML.

  • Prefix: getUrlParam
  • Description: Gets a query parameter from the current URL.

  • Prefix: urlSetup
  • Description: Base setup for LAN IP, Socket.io connection, and API endpoint. Customize the API URL for different environments.


CSS Snippets

  • Prefix: flexbox
  • Description: Creates a flexible container using CSS Flexbox with customizable alignment, spacing, and wrapping.

  • Prefix: grid
  • Description: Creates a responsive CSS Grid layout with customizable columns and spacing.

  • Prefix: mediaquery
  • Description: Defines a media query for responsive design with a customizable breakpoint.

  • Prefix: button
  • Description: Creates a styled button with hover and focus effects for accessibility and interaction.

  • Prefix: animationkeyframes
  • Description: Creates a fade-in animation with customizable timing, easing, and movement.

  • Prefix: pseudoelements
  • Description: Adds a pseudo-element (e.g., ::before) with customizable content and styling.

  • Prefix: variables
  • Description: Defines reusable CSS custom properties (variables) with an example usage.

  • Prefix: structure
  • Description: Provides a structured CSS file template with organized sections for settings, generic styles, elements, objects, components, and utilities.

  • Prefix: reset
  • Description: A modern CSS reset to normalize styles across browsers with improved typography and layout defaults.


HTML Snippets

  • Prefix: navbar
  • Description: Creates a simple, accessible navigation bar with semantic markup and support for indicating the current page.

  • Prefix: table
  • Description: Creates an accessible HTML table with a caption, semantic structure, and ARIA attributes for better screen reader support.

  • Prefix: dropdown
  • Description: Creates an accessible dropdown list with a label, default option, wrapping div, and form validation attributes.

  • Prefix: radiogroup
  • Description: Creates an accessible group of radio buttons with a legend, optional default selection, and form validation attributes.

  • Prefix: checkboxgroup
  • Description: Creates an accessible group of checkboxes with a legend, optional default selections, and ARIA role for better accessibility.

  • Prefix: button
  • Description: Inserts an accessible button element with a class, customizable type, and explicit role.

  • Prefix: form
  • Description: Creates an accessible form with a labeled input field, submit button, and form validation attributes.

  • Prefix: video
  • Description: Inserts an accessible video element with a source, fallback text, and ARIA label for screen readers.

  • Prefix: audio
  • Description: Inserts an accessible audio element with a source, fallback text, and ARIA label for screen readers.

  • Prefix: card
  • Description: Creates an accessible card structure with an image, heading, content, and semantic markup.



Usage

Creative Commons Attribution-NoDerivatives 4.0 International License (CC BY-ND 4.0)

This work is licensed under the Creative Commons Attribution-NoDerivatives 4.0 International License.

Permissions:

  • Use and share this work as is.
  • Attribution to the author is required.

Restrictions:

  • No modifications or derivative works.
  • No distribution of altered versions.

THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. THE AUTHORS OR COPYRIGHT HOLDERS SHALL NOT BE LIABLE FOR ANY CLAIM OR DAMAGES ARISING FROM THE USE OF THIS WORK.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft