Skip to content

Instantly share code, notes, and snippets.

View zachgoll's full-sized avatar

Zach Gollwitzer zachgoll

View GitHub Profile
const simpleObject = { myVariable: 'some value' };
// Using dot notation to access property value
console.log(simpleObject.myVariable);
// Using bracket notation to access property value
console.log(simpleObject['myVariable']);
const numbersArray = [10, 20, 30, 40];
const stringArray = ['red', 'green', 'blue'];
const booleanArray = [true, true, false];
const mixedArray = [true, 'red', 10];
const variable1 = 10;
const variable2 = variable1;
const variable3 = "Zach";
const variable4 = {
variableType: "object",
variableValue: "some value",
};
const variable5 = (function () {
return "Hello, my name is ";
})();
const yourFirstVariable = "learning to code gives you superpowers";
const yourSecondVariable = 10;
const yourThirdVariable = { name: "third variable", value: 40 };
// This is a comment
/*
This is also a comment, and extends
to multiple lines
*/
console.log("the console.log statement prints values to the console");
// Oh hey, this is a comment because the line starts with two forward slashes. It doesn't affect the code
let counterVariable = 1;
// Increases the variable by 1
counterVariable = counterVariable + 1;
// ALSO increases the variable by 1 (this is the shorthand version)
counterVariable++;
@zachgoll
zachgoll / function-api-example.js
Created October 30, 2020 12:46
function api example
function computeMortgagePayment(
interestRate: number,
price: number,
term: number
): number {
// No need for us to know the implementation details because we have an API!
}
@zachgoll
zachgoll / vision-api.js
Created October 30, 2020 12:45
vision-api example
async function analyzeText(url) {
// Imports the Google Cloud client library
const vision = require("@google-cloud/vision");
// Creates a client
const client = new vision.ImageAnnotatorClient();
const request = {
image: {
source: { imageUri: url },
},
@zachgoll
zachgoll / git-revert-example.sh
Created October 23, 2020 19:45
Git revert example
# log command for reference: git log --oneline --decorate --graph --all
git init
touch file-1.txt
git add .
git commit -m "first commit"
git checkout -b develop
touch file-created-by-develop-branch.txt
git add .
git commit -m "add develop branch file"
@zachgoll
zachgoll / asking-user-timezone.js
Last active October 2, 2020 13:44
Asking user timezone
const dateValue = dateInput.value; // Notice that we are grabbing the raw value, not the date value
const userSpecifiedTimezone = "EDT"; // Assume, this was selected by the user
// The date value is now a string, so grab the pieces
const dateParts = dateValue.split("-");
const year = dateParts[0];
const month = dateParts[1];
const day = dateParts[2];
// Construct a new JS date using the individual pieces and timezone specification