Skip to main content
Base Platform  /  Code Snippet Archive

Code Snippet & Reference Library

Battle-tested, copy-pasteable snippets across PHP, Python, JavaScript, VB.NET, SQL and Bash — compiled from real SaaS engineering sessions.

469
Snippets Indexed
2
PHP
0
JavaScript
7
Python

Showing 469 snippets

SNP-2025-0006 HTML 2024-01-18

Creating your first web page in pure HTML 🎉

THE PROBLEM
<p>A paragraph of text</p>

<ul>
  <li>First item</li>
  <li>Second item</li>
  <li>Third item</li>
</ul>

While this allowed us to create a functional HTML page, it lacked some fundamental elements necessary for a well-formed HTML document. Consider the following improved version:

<!DOCTYPE html>
<html>
  <head>

  </head>
  <body>
    <p>A paragraph of text</p>

    <ul>
      <li>First item</li>
      <li>Second item</li>
      <li>Third item</li>
    </ul>
  </body>
</html>
  • <!DOCTYPE html>: This declaration, placed at the top, signals to the browser that the document is an HTML file.
  • <html>: The root element that wraps the entire HTML document. Inside it, you'll find the <head> and <body> sections.
  • <head>: This section contains meta-information about the document, such as the title, character set, linked stylesheets, and more. In this example, it's left empty for simplicity.
  • <body>: The container for the visible elements of the page. It encompasses the content you want to display, including paragraphs, lists, images, and more.

It's crucial to note that an HTML document should have only one occurrence of the <html>, <body>, and <head> elements.

Additionally, notice the indentation used in this example. Each nested tag, such as <head> inside <html> or <ul> inside <body>, is indented for clarity. Indentation helps maintain a "tree structure," making it easier to visually parse and understand the hierarchy of elements in an HTML file.

Whether you prefer a 2-character or 4-character indentation (or tabs), consistency is key to ensuring a clean and organized HTML structure. Adopting a systematic approach will greatly enhance your ability to navigate and modify HTML files effectively.

Open Full Snippet Page ↗
SNP-2025-0012 SQL 2024-01-18

How to insert data into your Table, the correct way

THE PROBLEM

You can now start adding data into it with the INSERT INTO command:

  1. Inserting a single record:
INSERT INTO people VALUES (20, 'Tony');
  1. Inserting multiple records:
INSERT INTO people VALUES (57, 'Joe'), (8, 'Ruby');
  1. Inserting data into specific columns:
INSERT INTO people (name) VALUES ('Harry');

To execute these queries using TablePlus SQL editor, follow these steps:

  1. Open TablePlus and connect to your database.
  2. In the SQL editor, paste one of the provided queries.
  3. Select the query with your mouse.
  4. Click on "Run Current" to execute the query.

After executing the queries, you can refresh the database view, click on the "people" table, and inspect its content. You'll see the inserted data reflecting the changes made.

These INSERT INTO commands allow you to populate your database tables with the necessary data, providing a foundation for meaningful interactions and queries. Feel free to experiment with different values and combinations to familiarize yourself with the process of inserting data into a SQL database.

Open Full Snippet Page ↗
SNP-2025-0005 Tech 2024-01-18

Introduction to HTML 📖

THE PROBLEM

Now I want to tell you something about HTML you should know.

HTML is not presentational. It’s not concerned with how things look.

Instead, it’s concerned with what things mean.

You don’t tell “make this paragraph red” in HTML.

That’s a presentational aspect.

HTML is just concerned with content.

It just adds some predefined styles here and there, like for example with the list. But that’s it. There’s no customization you can do on how it looks, in HTML.

This will be the job of CSS, but that’s a story for another lesson.

REAL-WORLD USAGE EXAMPLE
<p>A paragraph of text</p>

<ul>
  <li>First item</li>
  <li>Second item</li>
  <li>Third item</li>
</ul>

This HTML snippet says that A paragraph of text is a paragraph. And then we have a list of 3 items.

p stands for paragraphul stands for unordered list, and li stands for list item.

For each of them, we have an opening tag (like <p>), the content, and a closing tag (like </p>).

So <opening tag> …content … </closing tag>.

Open Full Snippet Page ↗
SNP-2025-0014 HTML 2024-01-17

CSS Selectors: Class and ID basic filtering for HTML elements

THE PROBLEM

To target elements with a specific class, use the class selector syntax: .class {}. Here's an example:

HTML:

<p class="dog-name">Roger</p>

CSS:

.dog-name {
  color: yellow;
}
<p class="dog-name">Roger</p>

Repeating Classes vs. Unique IDs

  • Repeating Classes: You can repeat the same class value across multiple elements within an HTML document. For example, several elements can share the class "dog-name."
  • Unique IDs: An id must be unique within an HTML document. It can only be used once. For instance, an id like "dog-name" should be assigned to a single element.

To target elements with a specific id, use the id selector syntax: #id {}. Here's an example:

HTML:

<p id="dog-name">Roger</p>

CSS:

#dog-name {
  color: yellow;
}

Understanding the nuances of class and id selectors provides you with powerful tools for styling specific elements or groups of elements within your HTML documents. As you progress, you'll discover more advanced selectors and techniques to enhance your CSS styling capabilities. Stay tuned for further exploration into the world of CSS.

Open Full Snippet Page ↗
SNP-2025-0013 HTML 2024-01-16

Introduction to CSS 🚀

THE PROBLEM

CSS can be applied in various ways:

1. Inline Style

<p style="color: red;">This is a red paragraph.</p>

2. Internal Style (Within HTML Document)

<head>
  <style>
    p {
      color: red;
    }
  </style>
</head>

3. External Style (In Separate CSS File)

<head>
  <link href="style.css" rel="stylesheet" />
</head>

You can list multiple CSS rules to apply different styles to various elements:

p {
  color: red;
}

a {
  color: blue;
}

A selector can target one or more items:

p, a {
  color: red;
}

Selectors can target one or more items, and spacing is insignificant in CSS:

p,a {
  color: red;}
p,a {              color: red;
         }
  • Each declaration in the declaration block should end with a semicolon (;).
  • Proper indentation and spacing enhance readability but are not required by the browser.

Understanding these fundamental concepts equips you to enhance the visual aspects of your HTML documents using CSS. As you delve deeper, you'll discover the versatility and power CSS brings to web development. Stay tuned for more insights into advanced CSS techniques and best practices.

REAL-WORLD USAGE EXAMPLE

Here's a basic example of a CSS rule that styles paragraph tags:

p {
  color: red;
}
  • Selector (p): Identifies the HTML element to which the styling rules will be applied.
  • Declaration Block ({ color: red; }): Contains one or more declarations. Each declaration comprises a property (color) and its corresponding value (red).
Open Full Snippet Page ↗
SNP-2025-0015 Javascript 2024-01-16

JavaScript Basics: Literals, Identifiers, and Variables

THE PROBLEM

Definition: A literal is a value that is directly written in the source code. It can be a simple value like a number, string, boolean, or more complex constructs like Object Literals or Array Literals.

Examples:

5
'Test'
true
['a', 'b']
{ color: 'red', shape: 'Rectangle' }

Key Point: Literals are the fundamental units of JavaScript, representing simple or complex values directly within the code.

Definition: An identifier is a sequence of characters used to identify a variable, function, or object in JavaScript. It can start with a letter, the dollar sign $, or an underscore _, and may contain digits.

Examples:

5
'Test'
true
['a', 'b']
{ color: 'red', shape: 'Rectangle' }

Usage of Dollar Sign: The dollar sign is commonly used to reference DOM elements in JavaScript.

Note: Some names are reserved for JavaScript internal use and cannot be used as identifiers.

Definition: A variable is a reference to a value. It allows us to store and later access that value through a given name. JavaScript is loosely typed, allowing flexibility in variable usage.

Declaration:

// Using const (for constants)
const a = 0;

// Using let (for mutable variables)
let b = 'Hello';

// Using var (older way, less commonly used today)
var c = true;

Case Sensitivity: Identifiers in JavaScript are case-sensitive.

Key Point: Variables provide a way to store and manage values, offering flexibility through different declaration keywords (const, let, var).

Understanding these fundamental concepts sets the groundwork for further exploration into JavaScript programming. As we progress, we'll delve into more advanced constructs and practices. Stay tuned for more insights into JavaScript development!

Open Full Snippet Page ↗
SNP-2025-0011 SQL 2024-01-15

Introduction to DBMS and SQL

THE PROBLEM

A database is a systematic collection of information organized into a cohesive system. Imagine a list of people with their corresponding age and email addresses, or a catalog of blog posts featuring titles and content. These organized sets of data form the backbone of databases.

It's crucial to note that databases are not exclusively computer-based; they can be as simple as a paper list or index cards. In the digital world, a Database Management System (DBMS) takes charge of managing and accessing this data.

A DBMS, short for Database Management System, is the software that empowers us to manage a database efficiently and interact with its data. It handles tasks such as storing, retrieving, editing, and persisting data to disk. While the terms "database" and "DBMS" are often used interchangeably, for the sake of simplicity, we'll treat them as synonymous in this Bootcamp.

Popular DBMS options include Postgres, MySQL, SQLite, and more. These systems are critical for ensuring the efficiency, persistence, security, privacy, and shared access of data within a database.

A robust DBMS must possess several key characteristics:

  • Efficiency: It must provide optimal performance for storing and retrieving data.
  • Persistence: Data stored in the database should be permanent, surviving software terminations or machine reboots.
  • Privacy and Security: The DBMS ensures private and secure data storage, granting access to multiple users with specific permissions.
  • Shared Access: Multiple users, with appropriate permissions, can access and edit shared data. This extends to multiple applications accessing the same database.
  • Data Management: The database must handle substantial amounts of data, scaling according to needs. This scalability doesn't mean a database is only valuable with vast datasets; it can be beneficial even with minimal entries.

To interact with relational databases, we employ the Structured Query Language (SQL). SQL enables us to instruct the creation of a database, define table schemas, populate tables with data, and query the data as needed. Born as a language for database querying and interaction, SQL is not a traditional programming language. Each database has its own dialect of SQL, with slight variations.

In the upcoming sections, we'll delve into the basics of SQL, providing you with the essentials to navigate and work with databases effectively. Stay tuned as we embark on a journey into the fundamental aspects of database management and SQL proficiency.

Open Full Snippet Page ↗
SNP-2025-0017 Guides 2024-01-10

Final steps to Deploy on Netlify

THE PROBLEM
Select import method
  1. Clicked on "Import from Git" on Netlify.
  2. Chose GitHub and authorized Netlify to access GitHub repositories.
  1. Picked the GitHub repository you want to deploy.
  2. Clicked "Deploy site" on Netlify.
Allow Access
  1. Netlify proceeded to deploy the site using the code from the GitHub repo.
  2. You monitored the deployment progress on Netlify.

View Live Site:

  1. The site was successfully deployed on a .netlify.app domain.
  2. You viewed your live site on the provided domain.
  1. Netlify automatically detected the change and redeployed the site.
  2. You saw the changes live on the .netlify.app domain.
Import from Github
  • Custom Domain: Consider buying and assigning a custom domain if your project becomes more serious. Netlify allows easy integration with custom domains.
  • Automated Deployment: The beauty of this setup is the automatic deployment. Every time you make changes, commit, and push to GitHub, Netlify takes care of deploying the updates.
  • Productivity Boost: This automated deployment process enhances productivity by eliminating manual deployment steps.

Congratulations on successfully deploying your site! If you have any further questions or if there's anything else you'd like to explore, feel free to ask. Happy coding!

Open Full Snippet Page ↗
SNP-2025-0016 Tech 2024-01-10

Getting Started with Netlify Deployment

THE PROBLEM

Netlify is a powerful deployment platform known for its speed, reliability, and seamless integration with version control systems like GitHub. It supports hosting static files, static site generators, and serverless functions.

  1. Visit Netlify.
  2. Click on "Sign Up" to create a new account.
  3. You can sign up using your GitHub account or provide the required information to create a new Netlify account.
Import from GIT
  1. After creating an account, log in to your Netlify dashboard.
  2. Click on the "New site from Git" button.
  3. Choose GitHub as the continuous deployment source.
  1. Select the repository you want to deploy.
  2. Configure your build settings. For a simple HTML site, the default settings should work.
  3. Click on the "Deploy site" button.
  1. Clone your GitHub repository to your local machine.
  2. Make changes to your HTML files or any other assets.
  3. Commit and push the changes to your GitHub repository.
  4. Netlify will automatically detect the changes and redeploy your site.
Allow Netlify Permissions
  1. Go back to your Netlify dashboard.
  2. You'll see a new deployment triggered by your recent push.
  3. Once the deployment is complete, you can visit the provided Netlify URL to view your live site.
  • Netlify provides features like custom domains, serverless functions, and more. Explore the settings in your Netlify dashboard to customize your deployment.
  • For advanced projects, you can explore static site generators like Hugo or Gatsby and leverage Netlify's features for a seamless deployment pipeline.

By following these steps, you'll be able to deploy and update your website with ease using Netlify. Feel free to explore more features offered by Netlify to enhance your web development workflow. Happy coding!

Open Full Snippet Page ↗

PAGE 47 OF 47 · 469 SNIPPETS INDEXED