Skip to content

Instantly share code, notes, and snippets.

View prismhead26's full-sized avatar

Aiden Wahed prismhead26

View GitHub Profile
@prismhead26
prismhead26 / lazy-git.sh
Last active April 19, 2024 06:29
LazyGit Bash Script
#!/bin/bash
function lazygit() {
git add -A
git commit -m "$1"
git push origin main
}
@prismhead26
prismhead26 / calculator.sh
Created April 19, 2024 06:19
Calculator Bash Script
#!/bin/bash
# create a variable to keep track if we want to keep using the calculator
runCalculator="y"
# while the value of `runCalculator` is 'y' for 'yes', run the calculator functionality
# use `;` between statements to terminate one and begin the other, or simply move the second statement to the following line
while [ $runCalculator = "y" ]; do
# clear the command line for a cleaner experience
@prismhead26
prismhead26 / email.js
Last active April 21, 2024 07:03
Email Regular Expression
const email = /^(?<username>[\w\.-]+)@(?<domain>\w+)\.(?<extension>\w{3})(?<loc>\.\w{2,8})?$/
// Email RegEx
// (username) @ (domain) . (extension) (.again)
// 1. any letters, numbers, dots and/or hyphens
// 2. any letters, numbers, and/or hyphens
// 3. any letters
// 4. a dot (.) then any letters
@prismhead26
prismhead26 / anagram.js
Created April 19, 2024 06:32
Anagram Javascript
const str = 'coding money';
const str2 = 'money coding';
const str3 = 'RAIL! SAFETY!';
const str4 = 'fairy tales';
function anagram(str1, str2) {
const str1Arr = str1.toLowerCase().replace(/[\W]/g,'').split('').sort();
console.log(str1Arr);
const str2Arr = str2.toLowerCase().replace(/[\W]/g,'').split('').sort();
@prismhead26
prismhead26 / array-chunks.js
Created April 19, 2024 06:33
Array Chunks Javascript
function chunk(array, size) {
return array.reduce((acc, val, i) => {
if (i % size === 0) {
acc.push([]);
console.log(acc);
console.log(i);
}
console.log(val);
acc[acc.length - 1].push(val);
return acc;
@prismhead26
prismhead26 / max-char.js
Created April 19, 2024 06:34
Maximum Characters Javascript
const str = 'abbccccddd';
function maxChar(str) {
let charMap = {};
let max = 0;
let char = '';
for (char of str) {
charMap[char] = ++charMap[char] || 1
@prismhead26
prismhead26 / interview-questions.js
Created April 19, 2024 06:36
Top 5 Interview Questions
/* Top 5 most popular
5: What is the difference between GET and POST when making an AJAX request?
GET and POST are two different HTTP requests
Use GET when retrieving data from the server
Use POST when sending data from the client to the server to create/update a resource
@prismhead26
prismhead26 / phone-num-regex.js
Created April 19, 2024 06:51
Phone Number Regular Expression
const phoneRegEx = /(?:(?<international>\+1)[ -])?\(?(?<areacode>\d{3})\)?[ -]?(?<prefix>\d{3})[ -]?(?<line_number>\d{4})/
// 1234567890
// 123-456-7890
// 123 456 7890
// (123) 456 7890
// +1 123 456 7890
@prismhead26
prismhead26 / createCounter.js
Created April 19, 2024 17:08
Counter algorithm in Javascript
/* Write a function (createCounter). It should accept an intitial integer (init).
It should return an object with three functions.
The three functions are:
-- increment() increases the current value by 1 and then returns it
-- decrement() reduces the current value by 1 and then returns it
-- reset() sets the current value to (init) and then returns it.
*/
const createCounter = function(init) {
@prismhead26
prismhead26 / fizzbuzz.js
Created April 19, 2024 17:09
Classic fizzbuzz
function fizzBuzz(num) {
let output = [];
for (let i = 1; i <= num; i++) {
if (i % 3 === 0 && i % 5 === 0) {
output.push('FizzBuzz');
} else if (i % 3 === 0) {
output.push('Fizz');
} else if (i % 5 === 0) {
output.push('Buzz');