Skip to content

Instantly share code, notes, and snippets.

@LearnWebCode
LearnWebCode / yourFunction.js
Created November 13, 2020 22:19
Connect to MongoDB / Atlas within Netlify / AWS Lambda Serverless Function File
const mongodb = require("mongodb")
exports.handler = async function (event, context) {
const client = await mongodb.connect(process.env.CONNECTIONSTRING, { useUnifiedTopology: true })
const db = client.db()
try {
const dogs = await db.collection("pets").find({ species: "dog" }).toArray()
client.close()
return {
@LearnWebCode
LearnWebCode / javascriptreact.json
Created March 11, 2021 22:59
React Visual Studio Code Snippets for component, useEffect, useState, and useImmerReducer
{
"React Component": {
"prefix": "rc",
"body": ["import React, { useEffect } from \"react\"", "", "function ${1:ComponentName}() {", " return (", " <>", " $2", " </>", " )", "}", "", "export default ${1:ComponentName}"],
"description": "React Component"
},
"useEffect": {
"prefix": "ue",
"body": ["useEffect(() => {", " $2", "}, [$1])"],
"description": "useEffect"
@LearnWebCode
LearnWebCode / settings.json
Last active September 8, 2022 02:06
My personal Visual Studio Code settings
{
"php.validate.executablePath": "/usr/local/bin/php",
"editor.minimap.enabled": false,
"editor.fontSize": 16,
"editor.fontFamily": "Menlo, Monaco, 'Courier New', monospace",
"terminal.integrated.fontSize": 16,
"workbench.editor.showTabs": true,
"editor.hover.enabled": false,
"editor.tabSize": 2,
"telemetry.telemetryLevel": "off",
@LearnWebCode
LearnWebCode / chrome.scpt
Last active September 23, 2022 21:01
macOS Tell Chrome & Safari to Be Certain Size in Certain Screen Position
tell application "Google Chrome" to activate
tell application "System Events"
tell process "Google Chrome"
click menu item "New Incognito Window" of menu "File" of menu bar 1
end tell
end tell
tell first window of application "Google Chrome" to set bounds to {0, 109, 967, 658}
@LearnWebCode
LearnWebCode / keybindings.json
Last active April 6, 2023 19:57
In VS Code on Mac; change from control + number to cmd + number to jump between open editors.
// Place your key bindings in this file to override the defaults
[
{ "key": "cmd+1", "command": "workbench.action.openEditorAtIndex1" },
{ "key": "cmd+2", "command": "workbench.action.openEditorAtIndex2" },
{ "key": "cmd+3", "command": "workbench.action.openEditorAtIndex3" },
{ "key": "cmd+4", "command": "workbench.action.openEditorAtIndex4" },
{ "key": "cmd+5", "command": "workbench.action.openEditorAtIndex5" },
{ "key": "cmd+6", "command": "workbench.action.openEditorAtIndex6" },
{ "key": "cmd+7", "command": "workbench.action.openEditorAtIndex7" },
{ "key": "cmd+8", "command": "workbench.action.openEditorAtIndex8" },
@LearnWebCode
LearnWebCode / delete-ds_store.sh
Last active June 30, 2021 16:58
Delete all ".DS_Store" files in current (and all nested) folder(s)
find . -name ".DS_Store" -delete
@LearnWebCode
LearnWebCode / index.js
Created July 21, 2021 23:41
Puppeteer / Node.js Automation & Web Scraping Tutorial from YouTube
// in a new folder be sure to run "npm init -y" and "npm install puppeteer"
const puppeteer = require("puppeteer")
const fs = require("fs/promises")
async function start() {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto("https://learnwebcode.github.io/practice-requests/")
const names = await page.evaluate(() => {
-- MySQL dump 10.13 Distrib 8.0.26, for macos11 (x86_64)
--
-- Host: localhost Database: petfoodsreference
-- ------------------------------------------------------
-- Server version 8.0.26
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8 */;
@LearnWebCode
LearnWebCode / index.js
Created December 3, 2021 04:20
Example Express app for YouTube WSL video.
const express = require('express')
const mysql = require('mysql2/promise')
const app = express()
let db
async function go() {
db = await mysql.createConnection({
host: 'localhost',
@LearnWebCode
LearnWebCode / docker-compose.yml
Created December 3, 2021 04:20
Docker compose example for YouTube WSL video.
# Use root/example as user/password credentials
version: '3.1'
services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
ports: