Skip to content

Instantly share code, notes, and snippets.

View jsbonso's full-sized avatar
🎯
portal.tutorialsdojo.com

Jon Bonso jsbonso

🎯
portal.tutorialsdojo.com
View GitHub Profile
@jsbonso
jsbonso / uploadToS3.sh
Created December 20, 2022 03:00
Upload new file to Amazon S3 via AWS CLI
# Get the latest file that's added in the folder
LATEST_FILE=`ls -tp | grep -v /$ | head -1`
echo $LATEST_FILE
# Upload the new file to your Amazon S3 Bucket.
# In this example, the "jonbonso-media" S3 bucket has an associated CloudFront distribution
# with a custom domain of "media.jonbonso.com"
aws s3 cp $LATEST_FILE s3://jonbonso-media
@jsbonso
jsbonso / automated_serverresponse_check.sh
Created December 20, 2022 00:14
Automated Script to Check TTFB for N Times
#!/bin/bash
for i in {1..250}
do
curl -o /dev/null \
-w "%{time_starttransfer}\n" \
https://google.com >> prod.txt
done
@jsbonso
jsbonso / addMyIp.sh
Last active February 27, 2023 22:36
Shell Script to add your IP to your EC2 Security Group using AWS CLI
MY_IP=`curl checkip.amazonaws.com`
echo $MY_IP
aws ec2 authorize-security-group-ingress \
--group-id sg-01298cde13c80c75 \
--protocol tcp \
--port 22 \
--cidr $MY_IP/32 \
--region us-east-1
@jsbonso
jsbonso / FindTheLengthOfLongestSubstringUsingWhileLoop.java
Created October 19, 2022 10:09
Find the Length Of Longest Substring using Sliding Window Technique via a WHILE Loop
class FindTheLengthOfLongestSubstringUsingWhileLoop {
public int lengthOfLongestSubstring(String s) {
/**
Examples:
#1 -
eabcdabcbb = 4
"abcd" is the longest substring
4 is the length of "abcd"
@jsbonso
jsbonso / FindTheLengthOfLongestSubstring.java
Created October 19, 2022 10:06
Find the Length Of Longest Substring using Sliding Window Technique
class FindTheLengthOfLongestSubstring {
public int lengthOfLongestSubstring(String s) {
/**
Examples:
#1 -
eabcdabcbb = 4
"abcd" is the longest substring
4 is the length of "abcd"
@jsbonso
jsbonso / Palindrome.java
Created October 18, 2022 21:18
Check if a Given String is a Palindrome
public class Palindrome
{
public static void main(String[] args) {
String input = "ababa";
String input1 = "mom";
String input2 = "nono";
String input3 = "A man, a plan, a canal: Panama!";
@jsbonso
jsbonso / TwoSumMethodsPerformanceChecks.java
Last active October 18, 2022 19:46
Tracks the Elapsed Time for the 2 Solutions for the Classic Two Sum Problem
/**
This tracks the Elapsed Time for the 2 Solutions for the Classic Two Sum Problem
You will discover how immensely better an (O)n solution is (twoSumOptimized)
than a brute force (O)n^2 solution (twoSumBruteForce) by checking the start and end
times of both methods
*/
import java.util.Map;
@jsbonso
jsbonso / TwoSumUsingHashMapSinglePass.java
Last active October 18, 2022 03:29
Two Sum Solution #2 - Using a HashMap and iterates the array in a single pass approach
/**
*
Two Sum Solution #2 - Using a HashMap and iterates the array in a single pass approach
Author: Jon Bonso
Goal: Get the two indices from the array that sums up to the value of the given target
MATH THEORY:
@jsbonso
jsbonso / TwoSumBruteForce.java
Created October 15, 2022 08:58
Two Sum Solution #1 - Brute Force Approach
/**
*
Two Sum Solution #1 - Brute Force Approach
Approach
- Brute force approach by using a nested loop
- Create the two loops to process the array, wherein the second loop is one step ahead of the previous loop and traversing the array elements in a quadratic manner
- The first loop uses the variable i to hold the first index while the second loop uses the variable j to hold the latter one.
- Compare the values of the i and j indices. If they are the same, return the indices as output
@jsbonso
jsbonso / OddOrEven.java
Last active October 17, 2022 13:19
Simple Odd or Even Coding Example
/*
Simple Odd or Even Coding Example
Author: Jon Bonso
Demo Link: https://www.online-java.com/BYJCIjwhpg
Mathematical Theory:
- Parity is the property of an integer which determines if it is even or odd.
- An even number is an integer that can be divided exactly by 2 is an even number.