Skip to content

Instantly share code, notes, and snippets.

View bradtraversy's full-sized avatar
💭
Always Coding :)

Brad Traversy bradtraversy

💭
Always Coding :)
View GitHub Profile
@bradtraversy
bradtraversy / pdocrash.php
Last active September 25, 2023 16:37
PDO & Prepared Statements Snippets
<?php
$host = 'localhost';
$user = 'root';
$password = '123456';
$dbname = 'pdoposts';
// Set DSN
$dsn = 'mysql:host='. $host .';dbname='. $dbname;
// Create a PDO instance
# GET VERSION
yarn -v (or --version)
# GET HELP
yarn help
# CREATE PACKAGE.JSON
yarn init
yarn init -y // Use defaults
@bradtraversy
bradtraversy / stack.js
Created May 29, 2020 14:35
Stack data structure
class Stack {
constructor() {
this.items = []
this.count = 0
}
// Add element to top of stack
push(element) {
this.items[this.count] = element
console.log(`${element} added to ${this.count}`)
@bradtraversy
bradtraversy / brython.html
Last active January 4, 2024 18:18
Python in the browser with Brython
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.8.8/brython.js" integrity="sha256-rA89wPrTJJQFWJaZveKW8jpdmC3t5F9rRkPyBjz8G04=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.8.8/brython_stdlib.js" integrity="sha256-Gnrw9tIjrsXcZSCh/wos5Jrpn0bNVNFJuNJI9d71TDs=" crossorigin="anonymous"></script>
@bradtraversy
bradtraversy / js_linked_list.js
Last active January 13, 2024 05:23
JS Linked List Class
// Construct Single Node
class Node {
constructor(data, next = null) {
this.data = data;
this.next = next;
}
}
// Create/Get/Remove Nodes From Linked List
class LinkedList {
@bradtraversy
bradtraversy / django_cheat_sheet.md
Last active February 24, 2024 23:35
Django command cheat sheet

Django 2.x Cheat Sheet

Creating a virtual environment

We need to create a virtual env for our app to run in: More Here Run this command in whatever folder you want to create your venv folder

python -m venv ./venv
@bradtraversy
bradtraversy / django_crash_course.MD
Last active March 1, 2024 02:44
Commands for Django 2.x Crash Course

Django Crash Course Commands

# Install pipenv
pip install pipenv
# Create Venv
pipenv shell
@bradtraversy
bradtraversy / pdo_db.php
Created February 21, 2018 12:56
PDO Class
<?php
/*
* PDO DATABASE CLASS
* Connects Database Using PDO
* Creates Prepeared Statements
* Binds params to values
* Returns rows and results
*/
class Database {
private $host = DB_HOST;
@bradtraversy
bradtraversy / devcamper_specs.md
Last active March 17, 2024 17:25
Specs for Devcamper Udemy course project

DevCamper Backend API Specifications

Create the backend for a bootcamp directory website. The frontend/UI will be created by another team (future course). The html/css template has been created and can be used as a reference for functionality. All of the functionality below needs to be fully implmented in this project.

Bootcamps

  • List all bootcamps in the database
    • Pagination
    • Select specific fields in result
    • Limit number of results
  • Filter by fields
@bradtraversy
bradtraversy / graphql-queries-mutations.md
Created June 2, 2022 17:37
GraphQL Queries & Mutations

GraphQL Queries & Mutations

These are the GraphQL queries and mutations for the YouTube course.

Get names of all clients

{
  clients {
    name
 }