Skip to content

Instantly share code, notes, and snippets.

View webgtx's full-sized avatar
:accessibility:
Hope is not a strategy

Alex Zolotarov webgtx

:accessibility:
Hope is not a strategy
View GitHub Profile
@webgtx
webgtx / eipninstance.tf
Created July 26, 2023 20:48
Attaching an EIP to an Instance with a pre-assigned private ip (VPC Only) [AWS]
resource "aws_vpc" "default" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.default.id
}
resource "aws_subnet" "tf_test_subnet" {
@webgtx
webgtx / tfadv.md
Last active July 24, 2023 08:10
Terraform Pros and Cons.

Terraform is a popular infrastructure as code (IaC) tool used to provision and manage cloud resources from various providers like Amazon Web Services (AWS), Microsoft Azure, Google Cloud Platform (GCP), and others. It allows users to define infrastructure configurations in a declarative manner, making it easier to manage and automate the deployment process. Let's explore some of the advantages and disadvantages of using Terraform:

Advantages of Terraform:

  1. Infrastructure as Code (IaC): Terraform enables you to define your infrastructure in code, making it versionable, maintainable, and easier to collaborate on with other team members. This brings many benefits like reproducibility, consistency, and easier rollbacks.

  2. Multi-Cloud Support: Terraform provides a unified way to manage infrastructure across multiple cloud providers. This allows organizations to avoid vendor lock-in and leverage the best features of different cloud platforms.

  3. Declarative Syntax: Terraform uses a declarative la

@webgtx
webgtx / instance-by-resources.tf
Created July 16, 2023 17:34
Sample resources for instance in terraform declared only by resources
data "template_file" "user_data" {
template = file("cloudinit/addpubkey.yml")
}
resource "aws_vpc" "mainvpc" {
cidr_block = "10.1.0.0/16"
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.mainvpc.id
@webgtx
webgtx / sublimeyamlfix.md
Created July 15, 2023 07:44
How to fix YAML highlighting in sublime text

Just call Preferences => Customize Color Scheme

and add this between the square brackets under "rules":

        {
            "name": "Mapping Key Names",
            "scope": "meta.mapping.key string",
            "foreground": "#ff79c6"
        }
@webgtx
webgtx / thepowerofsubnetting.txt
Created July 7, 2023 03:22
The power of subnetting
192.168.1.0 - 192.168.1.31
192.168.1.32 - 192.168.1.63
192.168.1.64 - 192.168.1.95
192.168.1.96 - 192.168.1.127
192.168.1.128 - 192.168.1.159
192.168.1.160 - 192.168.1.191
192.168.1.192 - 192.168.1.223
192.168.1.224 - 192.168.1.255
192.168.1.0/32
@webgtx
webgtx / cloudinit_example.md
Last active July 2, 2023 11:01
Usage example for cloudinit in terraform on AWS

Add the cloud-init script to the Terraform configuration

Open the main.tf file. Notice how the template_file.user_data data block retrieves the contents of the add-ssh-web-app.yaml file. Then, it is passed into aws_instance.web as a user_data value to be initialized when the instance is created.

data "template_file" "user_data" {
  template = file("../scripts/add-ssh-web-app.yaml")
}

resource "aws_instance" "web" {
  ami                         = data.aws_ami.ubuntu.id
@webgtx
webgtx / snippet.sql
Created June 21, 2023 03:47
Cheatsheet with sql
SELECT
EXTRACT(MONTH FROM payment_date) AS month,
COUNT(*) AS total_count,
SUM(amount) AS total_amount,
COUNT(*) FILTER (WHERE staff_id = 1) AS mike_count,
SUM(amount) FILTER (WHERE staff_id = 1) AS mike_amount,
COUNT(*) FILTER (WHERE staff_id = 2) AS jon_count,
SUM(amount) FILTER (WHERE staff_id = 2) AS jon_amount
FROM payment
GROUP BY month
@webgtx
webgtx / main.md
Created June 17, 2023 18:32
routing issue for SPA in the cloud

Redirects for single page web apps (SPA)

Most SPA frameworks support HTML5 history.pushState() to change browser location without triggering a server request. This works for users who begin their journey from the root (or /index.html), but fails for users who navigate directly to any other page.

The following example uses regular expressions to set up a 200 rewrite for all files to index.html, except for the file extensions specified in the regular expression.

rules = </^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|woff2|ttf|map|json|webp)$)([^.]+$)/>

| Original address | Destination Address | Redirect Type |

@webgtx
webgtx / sample.ps1
Created June 17, 2023 04:15
Sample ICACLS commands to set owner, grant full control, read-only, and read plus execute access
::Set Owner of a specific file
ICACLS "D:\test\test.txt" /setowner "administrator"
::Grant Full Control
ICACLS "D:\test\test.txt" /grant:r "administrator:(F)" /C
::Grant Read and Execute Access of a specific file
ICACLS "D:\test\test.txt" /grant:r "users:(RX)" /C
::Grant Read-only Access of a specific file
@webgtx
webgtx / guesstheword.rb
Created June 16, 2023 04:37
Guess the word
require "base64"
secret_word = Base64.decode64("bGlnaHRzYWJlcg==")
player_word = "*" * secret_word.length
attempts = 11
puts """
Welcome to the game where you have to guess a word !
secret word has #{secret_word.length} letters, good luck.