How to Resize an AWS EBS Volume in Bash

If you need to resize an EBS volume in AWS, you can do so using bash. Step 1 – Create a bash file Create a bash file called resize.sh: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 #!

How to get all checked checkboxes in Javascript

If you need to get all the checked checkboxes using Javascript, then you can do the following: Option 1 – In a single line 1 const checkedBoxes = document.querySelectorAll('input[name=mycheckboxes]:checked'); Option 2 – Another one liner 1 const data = [...document.querySelectorAll('.mycheckboxes:checked')].map(e => e.value); Option 3 – Create a helper function 1 2 3 4 5 6 7 8 9 10 function getCheckedBoxes(checkboxName) { var checkboxes = document.getElementsByName(checkboxName); var checkboxesChecked = []; for (var i=0; i<checkboxes.

How to Setup Credential Helper for AWS CodeCommit

AWS CodeCommit is a git code repository service by Amazon Web Services. You will want to clone your repository and setup your remotes using credential helper. Step 1 – Setup Credential Helper 1 2 git config --global credential.helper '!aws codecommit credential-helper $@' git config --global credential.UseHttpPath true This will write to your local user’s ~/.gitconfig, and the file will look something like: 1 2 3 [credential] helper = !aws --profile CodeCommitProfile codecommit credential-helper $@ UseHttpPath = true You can edit this file by running the following git command:

How to Flex Grid 2 Columns using CSS

If you would like to flex grid 2 columns in CSS then you need three (3) divs. Step 1 – Set your HTML template Create some HTML with this layout. 1 2 3 4 5 6 7 8 <div class="Parent"> <div class="child1"> <h1>Left</h1> </div> <div class="child2"> <h1>RIGHT</h1> </div> </div> Step 2 – Container Div Create a Parent div that uses the Flexbox display model. 1 2 3 4 .Parent { display: flex; flex-direction: row; } Step 3 – Child Divs Create two (2) divs that are both 50% of the parent container.

How to Create a Hashtag Generator in Javascript

If you want to create a hashtag generator in Javascript, then you can do the following: 1 2 3 4 5 6 7 8 9 10 11 12 function generateHashtag(string) { if (string.trim() === '') return false; const stringWithCamelCase = string .split(' ') .map(word => word.charAt(0).toUpperCase() + word.slice(1)) .join(''); const stringWithHashtag = `#${stringWithCamelCase.trim()}`; return stringWithHashtag.length > 140 ? false : stringWithHashtag; } How to use the Hashtag Generator 1 2 3 4 const hashtag = generateHashtag("My New Hashtag !

How to Confirm before Leaving Page in Javascript

You can implement a function to be called before the user leaves a page with Javascript as follows: 1 2 3 window.onbeforeunload = function(e) { return "Do you want to exit this page?"; }; This is a typically solution for when you want the user to confirm their changes are saved before allowing them to close the current page in editing tools.

What are the multiples of 3 from 1 to 1000

If you need to calculate the multiples of 3, starting from 1 up until 1000, then you can use the following code: 1 2 3 4 5 n = 1 v = [] while n <= 1000: v.append(n) n = n + 3 This will generate the list of numbers which are the multiples of 3 from 1 to 1000: 1 1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97, 100, 103, 106, 109, 112, 115, 118, 121, 124, 127, 130, 133, 136, 139, 142, 145, 148, 151, 154, 157, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 199, 202, 205, 208, 211, 214, 217, 220, 223, 226, 229, 232, 235, 238, 241, 244, 247, 250, 253, 256, 259, 262, 265, 268, 271, 274, 277, 280, 283, 286, 289, 292, 295, 298, 301, 304, 307, 310, 313, 316, 319, 322, 325, 328, 331, 334, 337, 340, 343, 346, 349, 352, 355, 358, 361, 364, 367, 370, 373, 376, 379, 382, 385, 388, 391, 394, 397, 400, 403, 406, 409, 412, 415, 418, 421, 424, 427, 430, 433, 436, 439, 442, 445, 448, 451, 454, 457, 460, 463, 466, 469, 472, 475, 478, 481, 484, 487, 490, 493, 496, 499, 502, 505, 508, 511, 514, 517, 520, 523, 526, 529, 532, 535, 538, 541, 544, 547, 550, 553, 556, 559, 562, 565, 568, 571, 574, 577, 580, 583, 586, 589, 592, 595, 598, 601, 604, 607, 610, 613, 616, 619, 622, 625, 628, 631, 634, 637, 640, 643, 646, 649, 652, 655, 658, 661, 664, 667, 670, 673, 676, 679, 682, 685, 688, 691, 694, 697, 700, 703, 706, 709, 712, 715, 718, 721, 724, 727, 730, 733, 736, 739, 742, 745, 748, 751, 754, 757, 760, 763, 766, 769, 772, 775, 778, 781, 784, 787, 790, 793, 796, 799, 802, 805, 808, 811, 814, 817, 820, 823, 826, 829, 832, 835, 838, 841, 844, 847, 850, 853, 856, 859, 862, 865, 868, 871, 874, 877, 880, 883, 886, 889, 892, 895, 898, 901, 904, 907, 910, 913, 916, 919, 922, 925, 928, 931, 934, 937, 940, 943, 946, 949, 952, 955, 958, 961, 964, 967, 970, 973, 976, 979, 982, 985, 988, 991, 994, 997, 1000

How to Count Files in Directory on Linux

If you need to count how many files are in a directory on Linux, then you can use a combination of the ls command to list all the files, and the wc command to count how many lines are printed: Option 1 – Using wc 1 ls | wc -l You can specify a directory as follows: 1 ls <directory> | wc -l Option 2 – Using find You can count files recursively by using the find command:

How to Read a File Line by Line in Java

If you need to read a file line by line in Java, then you can use one of the following three (3) options. Option 1 You can use the FileReader and BufferedReader packages as follows: 1 2 3 4 5 6 7 8 9 10 11 File file = new File("./your/file.txt"); try (FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr);) { String line; while ((line = br.readLine()) != null) { System.

How can I clear or empty a StringBuilder

You can use Java’s StringBuilder to create and manipulate Strings as follows: 1 2 3 4 5 StringBuilder sb = new StringBuilder(); sb.append("Some").append(" ").append("String"); System.out.println(sb.toString()); // "Some String" The following three (3) options allow you to clear or empty a StringBuilder. Option 1 – using setLength 1 sb.setLength(0); Option 2 – reinstantiating 1 sb = new StringBuilder(); Option 3 – using delete 1 sb.delete(0, sb.length());

How to Approve a SageMaker model in AWS CLI

Sometimes you will need to manually approve a SageMaker model package from the AWS CLI. Step 1 – Get a list of the available packages 1 aws sagemaker list-model-packages --model-package-group-name "the-model-package-group" This will produce the following output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 { "ModelPackageSummaryList": [ { "ModelPackageGroupName": "...", "ModelPackageVersion": "...", "ModelPackageArn": "the-arn-we-will-use-below", "ModelPackageDescription": "...", "CreationTime": "...", "ModelPackageStatus": "Completed", "ModelApprovalStatus": "PendingManualApproval" }, .

How to Assume Role across Accounts in AWS

If you need to assume role between AWS accounts, or allow an account to assume a role and use resources in another AWS account, then you need to create a role and attach the following policy. The following two (2) steps creates a Trust Relationship between the accounts. Step 1 – In the Source Account 1 2 3 4 5 6 7 8 9 10 11 12 { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": [ "sts:AssumeRole" ], "Resource": [ "arn:aws:iam::DESTINATION-ACCOUNT-ID:role/DESTINATION-ROLENAME" ] }] } Step 2 – In the Destination Account 1 2 3 4 5 6 7 8 9 10 { "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::SOURCE-ACCOUNT-ID:role/SOURCE-USERNAME" }, "Action": "sts:AssumeRole" }] }

How to Style an Element using Javascript

If you need to style an element using Javascript then you can use the style object to support all your CSS needs. 1 2 3 4 5 6 7 8 9 10 11 12 13 <html> <body> <p id="p1">Hello World!</p> <script> document.getElementById("p1").style.color = "red"; </script> <p>The paragraph above was changed by a script.</p> </body> </html> If you need to do this purely in a Javascript file itself, then: 1 2 3 4 5 6 // Get a reference to the element var myElement = document.

How to Wait 1 Second in Javascript

If you need your Javascript code to wait one (1) second (or more) while executing, then there are a couple of ways to achieve this. Option 1 – Creating a delay Promise 1 2 3 4 5 function delay(time) { return new Promise(resolve => setTimeout(resolve, time)); } delay(1000).then(() => console.log('ran after 1 second elapsed')); Option 2 – Using setTimeout 1 2 3 setTimeout(function(){ console.log("Ready") }, 1000); Option 3 – Using an async Promise 1 2 3 4 5 6 7 async function test() { console.

How to use forEach method in Javascript

Arrays come with a useful forEach function that allows you to loop through the array. 1 2 3 4 5 6 7 8 9 var colors = ['red', 'blue', 'green']; colors.forEach(function(color) { console.log(color); }); // red // blue // green You can also get the index in each loop as follows: 1 2 3 4 5 6 7 8 9 const colors = ['red', 'blue', 'green']; colors.forEach((item, index)=>{ console.log(index, item) }); // 0 'red' // 1 'blue' // 2 'green'

How to Remove an Element from an Array in Javascript

If you need to remove an element from an array in Javascript, then you can use one of the following five (5) options: Option 1 – Use splice to remove an element Example 1 using splice: 1 2 3 4 5 var colors = ["red","blue","car","green"]; var carIndex = colors.indexOf("car"); colors.splice(carIndex, 1); // colors = ["red","blue","green"] Example 2 using splice: 1 2 3 4 var myArray = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; // Remove Sunday -- index 0 and Monday -- index 1 myArray.

How to get the Alphabet as Array in Javascript

If you need to get an array of alphabetical letters in Javascript then you can use one of the following: Option 1 – Explicitly define the array first 1 const alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]; Option 2 – Split a string of alphabetical characters 1 const alphabetArray = "abcdefghijklmnopqrstuvwxyz".split(""); Option 3 – Split a string and UpperCase characters 1 const alphabetArrayUp = toUpperCase("abcdefghijklmnopqrstuvwxyz").split("");

The Power of Two (2) Table

With the Power of Two, you can ask the following: How do you find the powers of 2? What does the power of 2 stand for? How much is the power of 2? The Power of Two (2) Table (Powers of Two) Power <td> <strong>Value</strong> </td> <td> 1 </td> 1 <td> 2 </td> 2 <td> 4 </td> 3 <td> 8 </td> 4 <td> 16 </td> 5 <td> 32 </td> 6 <td> 64 </td> 7 <td> 128 </td> 8 <td> 256 </td> 9 <td> 512 </td> 10 <td> 1,024 </td> 11 <td> 2,048 </td> 12 <td> 4,096 </td> 13 <td> 8,192 </td> 14 <td> 16,384 </td> 15 <td> 32,768 </td> 16 <td> 65,536 </td> 17 <td> 131,072 </td> 18 <td> 262,144 </td> 19 <td> 524,288 </td> 20 <td> 1,048,576 </td> 21 <td> 2,097,152 </td> 22 <td> 4,194,304 </td> 23 <td> 8,388,608 </td> 24 <td> 16,777,216 </td> 25 <td> 33,554,432 </td> 26 <td> 67,108,864 </td> 27 <td> 134,217,728 </td> 28 <td> 268,435,456 </td> 29 <td> 536,870,912 </td> 30 <td> 1,073,741,824 </td> 31 <td> 2,147,483,648 </td> 32 <td> 4,294,967,296 </td> 33 <td> 8,589,934,592 </td> 34 <td> 17,179,869,184 </td> 35 <td> 34,359,738,368 </td> 36 <td> 68,719,476,736 </td> 37 <td> 137,438,953,472 </td> 38 <td> 274,877,906,944 </td> 39 <td> 549,755,813,888 </td> 40 <td> 1,099,511,627,776 </td> 41 <td> 2,199,023,255,552 </td> 42 <td> 4,398,046,511,104 </td> 43 <td> 8,796,093,022,208 </td> 44 <td> 17,592,186,044,416 </td> 45 <td> 35,184,372,088,832 </td> 46 <td> 70,368,744,177,664 </td> 47 <td> 140,737,488,355,328 </td> 48 <td> 281,474,976,710,656 </td> 49 <td> 562,949,953,421,312 </td> 50 <td> 1,125,899,906,842,624 </td> 51 <td> 2,251,799,813,685,248 </td> 52 <td> 4,503,599,627,370,496 </td> 53 <td> 9,007,199,254,740,992 </td> 54 <td> 18,014,398,509,481,984 </td> 55 <td> 36,028,797,018,963,968 </td> 56 <td> 72,057,594,037,927,936 </td> 57 <td> 144,115,188,075,855,872 </td> 58 <td> 288,230,376,151,711,744 </td> 59 <td> 576,460,752,303,423,488 </td> 60 <td> 1,152,921,504,606,846,976 </td> 61 <td> 2,305,843,009,213,693,952 </td> 62 <td> 4,611,686,018,427,387,904 </td> 63 <td> 9,223,372,036,854,775,808 </td> 64 <td> 18,446,744,073,709,551,616 </td> 65 <td> 36,893,488,147,419,103,232 </td> 66 <td> 73,786,976,294,838,206,464 </td> 67 <td> 147,573,952,589,676,412,928 </td> 68 <td> 295,147,905,179,352,825,856 </td> 69 <td> 590,295,810,358,705,651,712 </td> 70 <td> 1,180,591,620,717,411,303,424 </td> 71 <td> 2,361,183,241,434,822,606,848 </td> 72 <td> 4,722,366,482,869,645,213,696 </td> 73 <td> 9,444,732,965,739,290,427,392 </td> 74 <td> 18,889,465,931,478,580,854,784 </td> 75 <td> 37,778,931,862,957,161,709,568 </td> 76 <td> 75,557,863,725,914,323,419,136 </td> 77 <td> 151,115,727,451,828,646,838,272 </td> 78 <td> 302,231,454,903,657,293,676,544 </td> 79 <td> 604,462,909,807,314,587,353,088 </td> 80 <td> 1,208,925,819,614,629,174,706,176 </td> 81 <td> 2,417,851,639,229,258,349,412,352 </td> 82 <td> 4,835,703,278,458,516,698,824,704 </td> 83 <td> 9,671,406,556,917,033,397,649,408 </td> 84 <td> 19,342,813,113,834,066,795,298,816 </td> 85 <td> 38,685,626,227,668,133,590,597,632 </td> 86 <td> 77,371,252,455,336,267,181,195,264 </td> 87 <td> 154,742,504,910,672,534,362,390,528 </td> 88 <td> 309,485,009,821,345,068,724,781,056 </td> 89 <td> 618,970,019,642,690,137,449,562,112 </td> 90 <td> 1,237,940,039,285,380,274,899,124,224 </td> 91 <td> 2,475,880,078,570,760,549,798,248,448 </td> 92 <td> 4,951,760,157,141,521,099,596,496,896 </td> 93 <td> 9,903,520,314,283,042,199,192,993,792 </td> 94 <td> 19,807,040,628,566,084,398,385,987,584 </td> 95 <td> 39,614,081,257,132,168,796,771,975,168 </td> 96 <td> 79,228,162,514,264,337,593,543,950,336 </td> 97 <td> 158,456,325,028,528,675,187,087,900,672 </td> 98 <td> 316,912,650,057,057,350,374,175,801,344 </td> 99 <td> 633,825,300,114,114,700,748,351,602,688 </td> 100 <td> 1,267,650,600,228,229,401,496,703,205,376 </td> The Power of Two (2) Tables from 1 to 100 Below you will find the Power of Two (2) tables from 1 to 100.

How to get the Screen Width in Javascript

Javascript gives a few options to determine the screen width. When we say screen, we mean the browser window’s width itself. Option 1 – Using Native Javascript Using native Javascript objects, we can find the innerWidth and innerHeight: 1 2 var w = window.innerWidth; var h = window.innerHeight; The window object also allows for: 1 2 3 window.screen.width // or simply screen.width We can write some code to tell us the width and height with fallbacks:

How to Read a File in Rust

If you need to read a file in Rust, then you can use the fs package from the standard library: 1 2 3 4 5 6 7 8 use std::fs; fn main() { let contents = fs::read_to_string(filename) .expect("Something went wrong reading the file"); println!("With text:\n{}", contents); }