0. Welcome to Cacher

# Welcome to Cacher

We're delighted you've chosen Cacher to be your snippet organizer! Whether you're a solo developer or a member of your team, Cacher is here to help you organize and use snippets more efficiently.

Our users create snippets to:

- Remember project-specific algorithms
- Create cheatsheets for useful libraries
- Share knowledge with colleagues

Take a few minutes to look over our **Getting Started** snippets. To view more detailed information on features, you can visit [Cacher 

AppSync API Key 365 Days Expire


GOTCHA!
AppSync API Keys expire MAX 365 days.

Is in AppSync->Settings->API Keys

https://docs.aws.amazon.com/appsync/latest/devguide/security-authz.html#api-key-authorization

AppSync API key docs: API keys are configurable for up to 365 days, and you can extend an 
existing expiration date for up to another 365 days from that day.


RESET HIGH COUNTRY API KEY
https://us-west-1.console.aws.amazon.com/appsync/home?region=us-west-1#/b5erzbe2cjd2zclhqio6xmqrau/v1/settings

2559. Count Vowel Strings in Ranges

You are given a 0-indexed array of strings words and a 2D array of integers queries. Each query queries[i] = [li, ri] asks us to find the number of strings present in the range li to ri (both inclusive) of words that start and end with a vowel. Return an array ans of size queries.length, where ans[i] is the answer to the ith query. Note that the vowel letters are 'a', 'e', 'i', 'o', and 'u'.
/**
 * @param {string[]} words
 * @param {number[][]} queries
 * @return {number[]}
 */
// Helper function to check if a character is a vowel
function isVowel(c) {
    return ['a', 'e', 'i', 'o', 'u'].includes(c.toLowerCase());
};

// Helper function to check if a word starts and ends with a vowel
function startsAndEndsWithVowel(word) {
    return word && isVowel(word[0]) && isVowel(word[word.length - 1]);
};

// Function to create a prefix sum array for vowel start/end words
function preprocess

Split Nav / Center Logo Nav

This snippet takes the Native Main Nav and inserts a logo at a specific index. For some reason using methods such as data.slice(0, Math.ceil(data.length / 2)) causes the navigation to break. Until someone finds a solution to this, the index has to be changed depending on the number of nav items there are. example site: https://nuhuskies.com/
<!-- ko if: name() === 'main-nav' -->
<div class="component c-navigation c-navigation--main flex flex-align-center flex-justify-center" data-bind="css: ko.observable().matchMedia('(min-width:1025px)')() ? 'c-navigation--desktop' : 'c-navigation--mobile'">
    <!-- ko switch-->
        <!-- ko case: ko.observable().matchMedia('(min-width:1025px)') -->
            <!-- ko if: $index() === 4 -->
                <div class="c-navigation__logo">
                    <a href="/index.aspx">
     

gcloud app deploy

Issues following the tutorials for Google Cloud Spring Boot Deploy [course](https://www.cloudskillsboost.google/course_templates/20/labs/499573) and had to make some alterations to directions to get it working.
# Deploying to AppEngine fixes

When you get to the point of building and deploying instead of running `./mvnw package appengine:deploy -DskipTests` instead run `mvn clean install -DskipTests` your output should look like the following:

```bash
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------------< com.example:guestbook >------------------------
[INFO] Building guestbook 0.0.1-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]-------------------------

How to set up Windows 11 without internet or Microsoft-Account?

https://answers.microsoft.com/en-us/windows/forum/all/how-do-i-set-up-windows-11-without-internet/e348329d-f136-4460-b2f7-bc2bfa32c4e7
You can press SHIFT+F10 keys to open Command Prompt.

Execute `OOBE\BYPASSNRO` command then.

After this, setup will reboot the computer and after reboot, you’ll get a new option I don’t have Internet or Continue with limited setup to skip the Internet requirement.

dataset, global data sets

https://github.com/unsplash/datasets?tab=readme-ov-file
https://unsplash.com/developers

images

Install VPN using docker

# Install VPN using docker
Source: https://openvpn.net/as-docs/docker.html#prerequisites-169854

Download an run docker image:

```
sudo docker pull openvpn/openvpn-as
```

Run the Docker container based on the Access Server image with these parameters.

```
sudo docker run -d \
  --name=openvpn-as --device /dev/net/tun \
  --cap-add=MKNOD --cap-add=NET_ADMIN \
  -p 943:943 \
  -p 443:443 \
  -p 1194:1194/udp \
  -v <path to data>:/openvpn \
  openvpn/openvpn-as
```

Replace <path to date> with 

1422. Maximum Score After Splitting a String

Given a string s of zeros and ones, return the maximum score after splitting the string into two non-empty substrings (i.e. left substring and right substring). The score after splitting a string is the number of zeros in the left substring plus the number of ones in the right substring.
/**
 * @param {string} s
 * @return {number}
 */
var maxScore = function(s) {
    // Variable to track the maximum score found
    let maxScore = 0;

    // Iterate through each possible split position (from 1 to s.length - 1)
    for (let i = 1; i < s.length; i++) {
        // Left substring contains the first i characters
        let left = s.slice(0, i);
        // Right substring contains the characters from i to the end of the string
        let right = s.slice(i);

        // Calculate the

AWS Identity Center Snips

# List Current
aws identitystore list-groups --identity-store-id <IDENTITY-STORE-ID>

aws identitystore create-group --identity-store-id <IDENTITY-STORE-ID>

aws identitystore create-group \
--identity-store-id <IDENTITY-STORE-ID> \
--display-name <GROUP-NAME>
--description <GROUP-DESCRIPTION>

EC2 configuration for Terraform

# Terraform Configuration ```terraform terraform { required_version = "~> 1.10.0" required_providers { aws = { source = "hashicorp/aws" version = "~> 5.82.0" } } } ``` - **terraform block**: Specifies the required Terraform version and providers. Here, it ensures that Terraform version 1.10.0 or later is used and that the AWS provider version is 5.82.0 or later. ### Provider Configuration ```terraform provider "aws" { region = "us-east-1" } ``` - **provider "aws"**: Configures the AWS provider to use the `us-east-1` region for all resources. ### Data Source: EC2 Instance Connect Managed Prefix List ```terraform data "aws_ec2_managed_prefix_list" "ec2_instance_connect" { name = "com.amazonaws.us-east-1.ec2-instance-connect" } ``` - **data "aws_ec2_managed_prefix_list"**: Retrieves the managed prefix list for EC2 Instance Connect, which is used to allow SSH access from AWS services. ### Security Group ```terraform resource "aws_security_group" "allow_ssh" { vpc_id = aws_vpc.my_vpc.id description = "Security group allowing SSH access" ingress { from_port = 22 to_port = 22 protocol = "tcp" prefix_list_ids = [data.aws_ec2_managed_prefix_list.ec2_instance_connect.id] description = "Allow SSH from EC2 Instance Connect" } ingress { from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["73.27.108.253/32"] description = "Allow SSH from personal IP" } egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] description = "Allow all outbound traffic" } tags = { Name = "allow_ssh" } } ``` - **aws_security_group**: Defines a security group that allows SSH access. It has two ingress rules: one for EC2 Instance Connect and another for a specific personal IP. The egress rule allows all outbound traffic. ### VPC ```terraform resource "aws_vpc" "my_vpc" { cidr_block = "10.0.0.0/16" enable_dns_support = true enable_dns_hostnames = true tags = { Name = "my_vpc" } } ``` - **aws_vpc**: Creates a Virtual Private Cloud (VPC) with a CIDR block of `10.0.0.0/16`, enabling DNS support and hostnames. ### Subnet ```terraform resource "aws_subnet" "public_subnet" { vpc_id = aws_vpc.my_vpc.id cidr_block = "10.0.1.0/24" map_public_ip_on_launch = true availability_zone = "us-east-1a" tags = { Name = "public_subnet" } } ``` - **aws_subnet**: Creates a public subnet within the VPC, mapping public IPs on launch and specifying an availability zone. ### Internet Gateway ```terraform resource "aws_internet_gateway" "igw" { vpc_id = aws_vpc.my_vpc.id tags = { Name = "my_igw" } } ``` - **aws_internet_gateway**: Attaches an Internet Gateway to the VPC, allowing internet access. ### Route Table ```terraform resource "aws_route_table" "public_route_table" { vpc_id = aws_vpc.my_vpc.id route { cidr_block = "0.0.0.0/0" gateway_id = aws_internet_gateway.igw.id } tags = { Name = "public_route_table" } } ``` - **aws_route_table**: Creates a route table with a route to the Internet Gateway, allowing outbound internet traffic. ### Route Table Association ```terraform resource "aws_route_table_association" "public_subnet_association" { subnet_id = aws_subnet.public_subnet.id route_table_id = aws_route_table.public_route_table.id } ``` - **aws_route_table_association**: Associates the route table with the public subnet, enabling internet access for resources in the subnet. ### IAM Role ```terraform resource "aws_iam_role" "ec2_assume_role" { name = "cloud-architect-course" assume_role_policy = jsonencode({ Version = "2012-10-17", Statement : [ { Action = "sts:AssumeRole", Effect = "Allow", Principal = { Service = "ec2.amazonaws.com" } } ] }) } ``` - **aws_iam_role**: Creates an IAM role that EC2 instances can assume, allowing them to interact with AWS services. ### IAM Role Policy Attachment ```terraform resource "aws_iam_role_policy_attachment" "ec2_ssm_policy_attachment" { role = aws_iam_role.ec2_assume_role.name policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore" } ``` - **aws_iam_role_policy_attachment**: Attaches the `AmazonSSMManagedInstanceCore` policy to the IAM role, allowing EC2 instances to use AWS Systems Manager. ### IAM Instance Profile ```terraform resource "aws_iam_instance_profile" "ec2_instance_profile" { name = "cloud-architect-course" role = aws_iam_role.ec2_assume_role.name } ``` - **aws_iam_instance_profile**: Creates an instance profile for the IAM role, which can be attached to EC2 instances. ### AMI Data Source ```terraform data "aws_ami" "amazon_linux" { most_recent = true owners = ["amazon"] filter { name = "name" values = ["al2023-ami-2023.*-x86_64"] } filter { name = "virtualization-type" values = ["hvm"] } filter { name = "boot-mode" values = ["uefi-preferred"] } filter { name = "root-device-type" values = ["ebs"] } filter { name = "state" values = ["available"] } } ``` - **data "aws_ami"**: Retrieves the most recent Amazon Linux AMI that matches specified filters, ensuring compatibility with the instance type and boot mode. ### EC2 Instance ```terraform resource "aws_instance" "ec2_instance" { ami = data.aws_ami.amazon_linux.id instance_type = "t2.micro" subnet_id = aws_subnet.public_subnet.id key_name = "dominiquehallan-alt-admin" vpc_security_group_ids = [aws_security_group.allow_ssh.id] monitoring = true iam_instance_profile = aws_iam_instance_profile.ec2_instance_profile.name ebs_optimized = true tags = { Name = "cloud-architect-course" Owner = "terraform.nwwem@fastmail.com" Project = "cloud-architect-course" Env = "dev" Terraform = "true" Managed-by = "devops" } metadata_options { http_tokens = "required" } root_block_device { encrypted = true } } ``` - **aws_instance**: Launches an EC2 instance using the specified AMI and instance type. It includes security group settings, monitoring, and an IAM instance profile. The root block device is encrypted for security.
# main.tf

terraform {
  required_version = "~> 1.10.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.82.0"
    }

    random = {
      source  = "hashicorp/random"
      version = "~> 3.6.3"
    }
  }
}

# Provider Configuration
provider "aws" {
  region = "us-east-1"
}

provider "random" {}

# Data Source: EC2 Instance Connect Managed Prefix List
data "aws_ec2_managed_prefix_list" "ec2_instance_connect" {
  name = "com.amazonaws.us-east-1.ec2-instanc

983. Minimum Cost For Tickets

You have planned some train traveling one year in advance. The days of the year in which you will travel are given as an integer array days. Each day is an integer from 1 to 365. Train tickets are sold in three different ways: a 1-day pass is sold for costs[0] dollars, a 7-day pass is sold for costs[1] dollars, and a 30-day pass is sold for costs[2] dollars. The passes allow that many days of consecutive travel. For example, if we get a 7-day pass on day 2, then we can travel for 7 days: 2, 3, 4, 5, 6, 7, and 8. Return the minimum number of dollars you need to travel every day in the given list of days.
/**
 * @param {number[]} days
 * @param {number[]} costs
 * @return {number}
 */
var mincostTickets = function(days, costs) {
    // Find the maximum day of travel
    const maxDay = days[days.length - 1];

    // Create a DP array to store the minimum cost up to each day
    const dp = new Array(maxDay + 1).fill(0);

    // Create a set for quick lookup of travel days
    const travelDays = new Set(days);

    // Iterate through each day from 1 to maxDay
    for (let i = 1; i <= maxDay; i++) {

Default Hero

Cache-friendly default hero banner Credit: Carson
<picture class="banner">
   <source media="(min-width: 1440px)" srcset="">
   <source media="(min-width: 768px)" srcset="" data-size="?w=1440">
   <source media="(min-width: 0px)" srcset="" data-size="?w=768">
   <img class="banner__image" src="" role="presentation" alt="Lamplighter School" />
</picture>

<script>
   // create a global banner object, populate it with matrix items, and select a random image
   window.banner = {};
   banner.images = { items: {{ List.Items | Map: 'FieldVa

Broken Spring Boot Actuator in IntelliJ

I was attempting to use Spring Boot Actuator in IntelliJ and was running into issues. After reaching out to a colleague who knows Java better than me, he suggested a few fixes. Add the changes to `application.properties`, `pom.xml` and then you need to edit the run/debug configuration by selecting the three dots next to run and click edit. From here you select the `Modify Options` and under the Java section in the drop down chose `Add VM Options` once that text field shows up in it add `-Djava.rmi.server.hostname=localhost` and the rerun your application. ![Run/Debug Edit](https://cdn.cacher.io/attachments/u/3d3fnb2l8w7yt/Izm99yuGaBMr5ptrl29Os4GXJG3-mbUP/58ncic6m6.jpeg)
spring.application.name=sb-ecomm

# Expose more endpoints for IntelliJ integration
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
management.endpoint.health.probes.enabled=true

# Enable Spring Boot Admin features that IntelliJ uses
spring.application.admin.enabled=true
spring.jmx.enabled=true

Spelling Errors

| **Misspelled Word**   | **Correct Spelling**   |
|------------------------|------------------------|
| unpredicatable         | unpredictable          |
| inflaction             | inflation              |
| dramaticaly            | dramatically           |
| sigifiies              | signifies              |
| Fianlly                | Finally                |
| ged                    | get                    |
| impense                | immense                |
| appartment             | apartm

b2b prices

SELECT bpp.products_id, pd.products_name, bpp.products_price FROM business_products_prices bpp inner join products_description pd on bpp.products_id = pd.products_id where bpp.customers_id = 5 and pd.language_id = 2 order by products_id asc;