Skip to content

Instantly share code, notes, and snippets.

View nitrotap's full-sized avatar

Kartik Jevaji nitrotap

View GitHub Profile
@nitrotap
nitrotap / gist:245740dc82cd988d375af8e5aeb7d361
Created April 15, 2022 03:59
function declaration regular function
function isOdd(n) {
if (n % 2 != 0) {
return true;
} else {
return false;
}
}
@nitrotap
nitrotap / Car.js
Last active April 15, 2022 04:42
Class Function - OOP using ES6 - demonstrating private and static methods
class Car {
#privateField;
constructor(make, model) {
this.make = make;
this.model = model;
this.#privateField = 42;
}
honk() {
console.log('beep beep');
}
@nitrotap
nitrotap / simple-project-setup.txt
Created April 15, 2022 04:32
one line for simple html project setup
touch index.html; mkdir assets; cd assets; mkdir css; mkdir js; mkdir images; cd css; touch styles.css; cd ..; cd js; touch script.js
@nitrotap
nitrotap / randNum.js
Created April 15, 2022 04:33
random number generator
var randomNum = function (min, max) { var a = Math.floor(Math.random() * (max - min + 1) + min); return a;};
module.exports = {randomNum};
@nitrotap
nitrotap / regex-url-tutorial.md
Last active April 23, 2022 22:42
Regular Expression Tutorial - URL Validation

Regex for URL validation

/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/i

The purpose of this tutorial gist is to explain the regex for URL validation. This regex value demonstrates protocol optional URL validation.

The expression begins with a capture grouping expression. It searches for http in order, with an s as optional. It checks for a : and two //'s to make up https://. That entire part is wrapped in a capture group and is made optional by the ?.

npm install express express-handlebars mysql2 sequelize dotenv bcrypt express-session connect-session-sequelize
@nitrotap
nitrotap / fizzBuzz.js
Created May 2, 2022 01:22
Fizz Buzz solution
// Write code to loop through the array of numbers
// At each iteration, if a number is evenly divisible by 3 print "Fizz"
// If a number is evenly divisible by 5 print "Buzz"
// If a number is evenly divisible by both 3 AND 5, print "Fizz Buzz"
// If a number is not divisible by 3 or 5, print the number
const fizzBuzz = function(arr) {
for (let i in arr) {
let currentNumber = arr[i];
@nitrotap
nitrotap / regex.js
Last active May 2, 2022 02:16
regex
/*
Matching a Hex Value – /^#?([a-f0-9]{6}|[a-f0-9]{3})$/
Matching an Email – /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/
Matching a URL – /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
Matching an HTML Tag – /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/
*/
const chkHex = (str) => {
const regexHex = new RegExp(/^#?([a-f0-9]{6}|[a-f0-9]{3})$/);
return regexHex.test(str);
@nitrotap
nitrotap / charCount.js
Last active May 2, 2022 02:07
character count
// Write code to create a function that accepts a string and returns an object containing the number of times each character appears in the string
const characterCount = function (str) {
const charObj = {};
for (let i = 0; i < str.length; i++) {
let char = str[i];
if (char in charObj) {
charObj[char]++;
<?php
// abstracted code
// create the abstract class
// basically a class that says any child classes need a method called get_drink_name and a variable called _drink_state
abstract class HotDrinksAbstract
{
abstract function get_drink_name();
// now if anyone else uses the HotDrinksAbstract Class, they will all have to specify a get_drink_name function
protected $_drink_state = 'hot';
// now all child classes will have the variable _drink_state available to them, and it will return hot