Posts

MAC shortcuts

Image
Here the simple mac shortcuts found from the difference sources such as 1 . Here the general tips: Mac keyboard shortcuts from Apple Support. run the caffeinate in the terminal to keep the computer wake unlimitedly 2 . Expand print dialog box by default: defaults write -g PMPrintingExpandedStateForPrint -bool TRUE Enable or disable character accent menu: // disable defaults write -g ApplePressAndHoldEnabled -bool false Add Dock space. defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}' killall Dock Dock transition delay. defaults write com.apple.dock autohide-time-modifier -float 0 killall Dock Spotlight In the spotlight, once find the file, hold down the CMD key to show the location of the file bottom of the window if you press CMD+R, the file will be show in the file explorer. Browser Some important browser shortcuts Functionality Browser Key Combination To show th...

Calling AWS Services

To programmatically connect to the AWS Services, need to use endpoints. The AWS SDK and the CLI use the default endpoint of the region to access the service. The regional endpoint is protocol://service-code.region-code.amazonaws.com standard. But services such as IAM not support the region. Some example of calling 1 to AWS services via API calls. All CLI calls are signed by Signature version 4 2 . To list all the active regions: (if you want to sort add the | sort to the end. aws ssm get-parameters-by-path --path /aws/service/global-infrastructure/regions --query Parameters[].Name In the above command regions is the important word. This command will return the following: --------------------------------------------------------------- | GetParametersByPath | +-------------------------------------------------------------+ | /aws/service/global-infrastructure/regions/ap-northeast-1 | | /aws/service/global-infrastructure/regions/eu-c...

Java Collectors recipes

Java Collectors is a utility class with several reduction operations. Here a few of the example you can do with the Collectors class. For example, grouping functionality first. import java.util.stream.Collectors; import java.util.stream.Stream; // basic functionality of the collector Stream.of("one", "two", "three", "four", "five") .collect(Collectors.groupingBy(n -> n.length())); // = {3=[one, two], 4=[four, five], 5=[three]} In the above code, n -> n.length() is the classifier . The return type is Map<Integer, List<String>> in the line# 5 - 6. The grouping allows having a downstream collector which do the subsequent collection operation. For example, // basic functionality of the collector Stream.of("one", "two", "three", "four", "five") .collect(Collectors.groupingBy(n -> n.length() , Collectors.counting())); // = {3=2, 4=...

Parse the namespace based XML using Python

In this blog, I am considering how to parser and modify the xml file using python. For example, I need to parser the following xml 1 (slightly modified for this blog) and need to write the modified xml to out.xml file. Here the country.xml <?xml version="1.0"?> <actors xmlns:fictional="http://characters.example.com" xmlns="http://people.example.com"> <actor type='T1'> <name>John Cleese</name> <fictional:character>Lancelot</fictional:character> <fictional:character>Archie Leach</fictional:character> </actor> <actor type='T2'> <name>Eric Idle</name> <fictional:character>Sir Robin</fictional:character> <fictional:character>Gunther</fictional:character> <fictional:character>Commander Clement</fictional:character> </actor> </actors> In ...

Terraform SSH connection to AWS EC2

Image
The instances are created via Terraform, but Terraform can only used existing key pairs. First thing is to create the key pair as explained in the AWS documentation 1 . NOTE: However, if you are not familiar with Terraform, please go through the following blogs before this blog Basic example of creating AWS EC2 with Terraform Creating AWS S3 bucket with Terraform Connect to the EC2 instance, the most important thing is key value pair which is create in the time of the EC2 instance is created. But this is not currently possible in the Terraform. Therefore we need to create the mykey first. For example aws ec2 create-key-pair --key-name mykey --query 'KeyMaterial' --output text > ~/.aws/mykey.pem If you are connecting from the Linux or Mac, because need read permission. chmod 400 ~/.aws/mykey.pem To display aws ec2 describe-key-pairs --key-name mykey To retrieve the public key from the pem file (Optional) ssh-keygen -y -f ~/.aws/mykey.pem Before th...

Creating AWS S3 bucket with Terraform

I recommend to read the first example 1 ,because this is a extenstion to that. However, instead of AWS EC2, here the target resource is AWS S3 for the simplicity. Here the providers.tf file. provider "aws" { region = "${var.s3_region}" } terraform { required_version = ">= 0.11.13" backend "s3" { bucket = "ojitha" key = "test/backbone" region = "ap-southeast-2" encrypt = "true" } } As shown in the above, the stage is maintain in the S3 bucket instead of locally as specified in the line# 7. resource "aws_s3_bucket" "main" { bucket = "${var.s3_bucket_prefix}-${var.environment}-${var.s3_region}" acl = "private" tags = "${local.s3_tags}" region = "${var.s3_region}" lifecycle { prevent_destroy = "false" } server_side_encryption_configuration { rule { ...

Basic example of creating AWS EC2 with Terraform

Here the very basic example. This is just a note of creating single EC2 instance using Terraform. First you need to define the provider in the example.tf file provider "aws" { region = "ap-southeast-2" } # resource "aws_s3_bucket" "example" { # bucket = "ojithatest1" # acl = "private" # } resource "aws_instance" "example" { ami = "${lookup(var.amis, "ubuntu-server")}" instance_type = "t2.micro" # depends_on = ["aws_s3_bucket.example"] provisioner "local-exec" { command = "echo ${aws_instance.example.public_ip} > ip_address.txt" } } resource "aws_eip" "ip" { instance = "${aws_instance.example.id}" } If you need S3 bucket depends on that EC2 uncomment the above code. In the above code, we are just creating EC2 instance and the assciated Elastic IP address. Above code use the variables...