Categories
General

If Else Statement in 10 Different Programming Languages

I have written code in many programming languages. Some languages have strange syntax while others invite you to write more code. In this post, I want to write if else statements in 10 different languages so you can share what you like or dislike about each language.

Python

amount = 0
if amount < 0:
print('Negative amount')
elif amount > 0:
print('Positive amount')
else:
print('Zero')

Java

int amount = 0;
if (amount < 0) {
  System.out.println("Negative amount");
} else if (amount > 0) {
  System.out.println("Positive amount");
} else {
  System.out.println("Zero");
}

Ruby


amount = 0
if amount < 0
puts "Negative amount"
elsif amount > 0
puts "Positive amount"
else
puts "Zero"

C#

int amount = 0;
if (amount < 0) {
  Console.WriteLine("Negative amount");
} else if (amount > 0) {
  Console.WriteLine("Positive amount");
} else {
  Console.WriteLine("Zero");
}

Swift

let amount = 0
if amount < 0 {
print("Negative amount")
}
else if amount > 0 {
print("Positive amount")
}
else {
print("Zero")
}

Objective-C

int amount = 0;
if (amount < 0) {
  NSLog("Negative amount");
} else if (amount > 0) {
  NSLog("Positive amount");
} else {
  NSLog("Zero");
}

Go


amount := 0
if amount < 0 {
fmt.Println("Negative amount")
}
else if amount > 0 {
fmt.Println("Positive amount")
}
else {
fmt.Println("Zero")
}

Javascript

const amount = 0;
if (amount < 0) {
Console.Log("Negative amount");
}
else if (amount > 0) {
Console.Log("Positive amount");
}
else {
Console.Log("Zero");
}

Rust

let amount = 0;
if amount < 0 {
print!("Negative amount");
}
else if amount > 0 {
print!("Positive amount");
}
else {
print!("Zero");
}

C++

int amount = 0; 
if (amount < 0) {
cout << "Negative amount";
}
else if (amount > 0) {
cout << "Positive amount";
}
else {
cout << "Zero";
}

There you have it. If else statement in 10 different programming languages. Leave me a comment with your favorite language.

Categories
Azure Container Instances Container Registry Docker

Deploy Angular App to Azure Container Instances.

Azure Container Instances, Angular 8, Docker

As I continue my quest to learn more about Azure services, I have decided to play with Azure Container Instances. In this post, I will share how to take a simple app, integrate Docker, and finally deploy it to Azure Container Instances.

First, let’s create a new Angular app using Angular CLI command ng new angular8docker. If you want to see the Angular app, take a look at this repo https://github.com/agileraymond/angular8docker.

Now that we have our app in place, let’s integrate it with Docker. So what is Docker? Let me share opensource.com’s definition, “Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.”

To integrate our Angular app with Docker, we need to add a Dockerfile. Dockerfile is a file that tells Docker how to build an image.

This file tells Docker to base the image from node:12.2.0. WORKDIR sets the working directory for our app. Next we set the path for our node modules. The COPY command copies package.json file to our app/package.json. Next, we run 2 npm install commands: one installs our app dependencies and the second installs angular cli tool. Next we copy entire contents to /app directory. And finally ng serve to run our app.

We have a very simple Dockerfile. If you want to learn more about this file, visit https://docs.docker.com/engine/reference/builder/. In addition to the Dockerfile, we also need to have a .dockerignore file.

This file tells Docker to ignore these files or folders. We are ignoring node_modules, .git and .gitignore. Using a .dockerignore file will keep our app small with only files needed to run it.

At this point, we are ready to build our app. Make sure you have Docker Desktop setup on your computer. Using a terminal, run “docker build -t angular8docker .”. This command will build our image by reading the Dockerfile and tag it as angular8docker.

After our image has been created, we need to run the app locally. On a terminal window, run “docker run -p 80:80 angular8docker”. This command will run our app by publishing port 80 to the host and will use angular8docker image. Very simple. Now using a browser, go to http://localhost and you should see your angular 8 app.

Now let’s host this app on Azure Container Instances. I’m going to use Azure CLI on this post so make sure you have the CLI installed locally. First we need to create a resource group. Run this command on your terminal: “az group create –name myResourceGroup –location eastus”. With our resource group in place, we can create our container registry with this command “az acr create –resource-group myResourceGroup –name angular8docker –sku Basic –admin-enabled true”.

We have to login to our container registry before we can push images to it. Use this command: “az acr login –name angular8docker”. If the login request was successful, you will receive a successful message otherwise an error message. Now let’s get our login server using this command “az acr show –name angular8docker –query loginServer –output table”. In my case, I received my loginServer as “angular8docker.azurecr.io”.

Now we need to see a list of our docker images with this command “docker images”. This will help us tag the image and associated with our container registry. Use this command to tag it: “docker tag angular8docker angular8docker.azurecr.io/angular8docker:v1”.

Run docker images again to verify the tag.

Finally let’s push our v1 image to Azure Container Registry with this command: "docker push angular8docker.azurecr.io/angular8docker:v1"

With our docker image in our Azure Container Registry, we can create an Azure Container Instance to run our angular 8 app. Run this command to create container instance “az container create –resource-group myResourceGroup –name angular8docker –image /angular8docker:v1 –cpu 1 –memory 1 –registry-login-server angular8docker.azurecr.io –registry-username angular8docker –registry-password <password> –dns-name-label rayangular8docker –ports 80”. After couple of minutes, you will receive confirmation message.

Find the FQDN in the confirmation message above and open up a browser window to see your app online. If you don’t see your app online double check port settings. Let’s do a final clean up so we don’t incur additional cost. Run “az group delete –name myResourceGroup” and all resources attached to this group will be deleted for us.

In a future post, I will show you how to troubleshoot Azure Container Instances.


Categories
Azure Cloud

Creating a Virtual Machine using Azure Portal

At work, we use Azure as our primary cloud provider. Our infrastructure runs on Azure and there is a need to learn Azure and its services. With my AWS background, I believe it is going to help me gain a deeper knowledge of Microsoft’s cloud. In the past I have written about Azure but now I want to start preparing for Azure certifications. I need to drink Azure Kool-Aid. I want to start this process by creating a virtual machine.

Let’s create a virtual machine using Azure Portal.

Azure Portal - Create Virtual Machine - Basics
Azure Portal – Create Virtual Machine – Basics

Fill out your basic details like operating system under Image. Here you have linux and windows machines. For this post, I’m choosing an ubuntu server. After completing required inputs on basics tab, I move on to the disk section. Here I accept default parameters. I continue with networking, management, advanced, tags, and finally review and create.

Azure Portal - Virtual Machine - Review
Azure Portal – Virtual Machine – Review

After creating my virtual machine, I noticed that my server is ready within 2 minutes. At this moment, I’m curious what resources were created. At the top of the list, I see my virtual machine. I also see network interfaces, storage account, network security group, virtual networks, and public ip addresses.

Since I’m not going to use this virtual machine, I will delete this resource so I don’t get charge for it. In a future post, I’m going to explore the .NET SDK and create a virtual machine writing C# code.

Categories
AWS EBS EC2 KMS

Easy way to encrypt EBS volume

Back in January 2019, I wrote an article on how to encrypt an EBS volume. It was a very tedious process. However, things have changed for good. AWS has simplified this process. In this article, I want to share how easy is to encrypt an EBS volume.

Before we launch a new EC2 instance, we need to use a key. Just like you lock and unlock your house door using a physical or digital key. Same principle applies to encrypted EBS volumes. To create a new KMS key, go to the key management service console and select customer managed keys from the left side menu.

Now create a new key. Once you have a new KMS key, we can launch a new EC2 instance. When you get to the storage option, pay attention to the encryption option. 

As you can see from image above, you will see your KMS keys in the encryption option. Go ahead and select a key and continue with your EC2 configuration wizard. 

That’s it. We have to be thankful to AWS for making this process easier. 

Categories
General

Advice for JR software developers

Back in 2007, I went to work for a startup company. It was my first job in IT. I did everything from desktop support, software development, and server maintenance. After a year and a half, I decided to leave this company so I can focus more on software development. In this post, I want to share tips on how to find great companies where developers can grow and advance their careers.

Find a Mentor
When you are starting your career as a software developer, there are many questions on how to do your job. What tools to use? What process to follow? How to write clean code? All of these questions can be answered with the help of a mentor. When I joined PrintPlace back in 2007, the company was in rapid growth mode. There was not much time to train or develop people. After my first year with the company, I knew that I needed to find a company where I can have access to mentors. I was fortunate enough to work with the CTO of the company. After PrintPlace, I joined Ristken, a software company that specialized in the auto industry. The IT group was made up of 10 developers, 3 QA, and IT director. In this company, I was able to work with the software architect and learned a great deal about software development. He was a very patient person that had the heart of a teacher. I also learned from the other developers in the company. Many came from different countries and that made conversations interesting. In addition to these mentors, I also watched youtube videos on software development. This is where I found my online mentor, Scott Hanselman. Before Scott joined Microsoft, he works at a bank. He shares valuable info thru his blog and podcast.

Promotions
I’m not a big fan of the title of JR developers. I prefer software developers. When it comes to promotions, you have to find companies where you can develop your skills and grow. Ask other developers in your team when was the last time they were promoted. In a healthy organization, promotions have to be open within the organization. Let me explain this point. If the company needs to hire a senior developer, do they look within or they go outside to find that talent. Make sure you see a path to go from JR developer to mid-level and then to senior developer / architect. If you are in a small company, there might be less opportunity to advance your career. You might have to look at a mid size company with a good track record of promoting within.

Skills
In this career, you have to always be learning something new. Technology that does not advance, it’s technology that stays behind. Nowadays I’m seeing entertainment services moving to on-demand streaming. With this change, there will be less demand on DVD players for example. Is redbox going to stay competitive with their business model? We, as software developers, face the same challenge. We have to stay relevant with current technology changes. Currently Cloud and DevOps come to mind. If you have experience with cloud computing, your skills are in high demand.

See you next week.

Categories
AWS

AWS Solutions Architect – Associate

After a very long process, I was able to take and passed the AWS Certified Solutions Architect Associate exam. In my current job, we don’t use AWS and that made it more difficult to gain hands on experience with AWS services. To prepare for the exam, I used 4 resources:

Acloudguru – I took at least 30 minutes to watch acloudguru videos. I also paused the videos to take notes. It is so many material to cover so it’s better to have notes for future use.

Frequently ask questions – There is so much information on AWS FAQ documents. Based on the acloudguru videos, I wrote down what services I needed to read the FAQs. I highly recommend to take additional notes as well. It will come handy before you take the exam.

Re:Invent videos – During my commute to work and back, I use my phone to listen to re:invent videos. I listened to EC2, S3, ALB videos and they were very beneficial to reinforce what I learned in the past.

Hands on experience – I also gained hands on experience by using AWS console or using the SDK. If you search on my blog, you will find many posts with detailed information on different AWS services.

I hope this post will help you prepare for any AWS certifications.

Categories
General

The Overnight Success that took 4 years

Back in April 2014, I started this blog to share my experiences as a software developer. I was motivated to write by Scott Hanselman. Many articles took long hours to write. Others were written in a couple of minutes. Without a clear goal for this blog, I was determined to help other software developers with common issues. In average, I receive 10 visits to my blog everyday. Recently I have written exclusively on AWS and .NET. Last year I read articles on AWS Lambda and was very impressed with this service. I also watched youtube videos to understand lambda. With this information, I started taking notes on lambda and how to use it with .NET Core.

After I shared this article on Linkedin and Twitter, AWS liked it and they included it on https://github.com/aws/aws-lambda-dotnet with a short description. This link is taking my blog to a new dimension. I’m getting more visits to my site and I’m happy that someone is starting to appreciate my articles.

It’s been a long 4 years writing technical articles and it’s finally paying off. Like many people say, “this is an overnight success that only took 4 years.”

Categories
General

How to Encrypt an EBS Volume

When you create a new AWS instance, you don’t see an option to encrypt the root volume. In this post, I’m going to show you step by step how to encrypt root volumes using the console.

First, we need to create a new AWS instance. Pay attention to the storage section. I’m unable to change the encrypted option. If you add a new volume, you will see that the encrypted option is also missing.

ebs root volume - no encryption option

Go ahead and configure your new instance. After the instance is launched, that’s when our real work begins. While the instance is in the initialization stage, go to volumes and create a new snapshot.

ebs volume - create new snapshot

Now that we have our new snapshot, we can copy it to a new region.

In this example, I’m copying this snapshot from US N. Virginia to EU London. As you can see, we have an option to encrypt this snapshot and also select a master key. Go ahead and click on copy button. Now we can switch to EU London region and go to the snapshots page.


Now we see that our London snapshot is encrypted. From this same page, select the encrypted snapshot and create a new image.

create image from encrypted snapshot

Now go to the AMIs page, select your newly created image and launch a new instance. Pay special attention to the storage section.

Our Encrypted column shows Encrypted. That’s what we want it. I hope this post was helpful to you. See you soon!

Categories
General

2018 Year In Review

The year is coming to an end. I want to take this opportunity to review what I accomplished this year. I also want to share ups and downs during this year.

January

December 15 2017 was my last day at MD Buyline. I worked there for 2 1/2 years. For a very long time, I tried to convince my wife that I needed to take a couple of months off from work. She never agree with me on taking a sabbatical. This was the perfect opportunity to take time off and spent time with the family. During this month, my wife became very sick with a cold/flu that refused to go away. I was her nurse. She got better one week and the next one she got sick again. Her immune system was very weak and that’s why she couldn’t recover sooner. I took my son to school everyday and had a great time doing it. After coming back from school, I would prepare breakfast and clean the house. Somedays I would go to the park to walk and relax. This month I wrote couple of posts on AWS CodeDeploy, a continuous deployment service.

Creating AWS CodeDeploy Application Using .NET SDK

February

Same story with my wife’s situation. Cold/flu refused to go away. She visited different doctors and nothing seem to cure her. She continued resting and taking her medications. I began to worry about my wife’s situation. She was not getting better. I believe she started getting sick from December 2017. It was a long time to be sick. I’m glad I didn’t have a full-time job during this time. I had the opportunity to take care of my wife and kids. My wife’s aunt lives with us and she was able to help as well. My aunt is an excellent cook so food was not a problem for us. With more time in my hands, I was able to write 2 blog posts and also continue gaining hands on experience with AWS. Last week of February, I updated my resume and was planning to look for a job next month. I also wrote some python code and created the following blog post:

Sending emails with AWS Python SDK

March

My wife was feeling better now. Thank God. I started looking for a job using linkedin, dice, indeed, and my network. I contacted Shawn about any job opening he may know. No response for a couple of days. But I was contacted by Justin, owner of JBHWorks, a call center company based on Lewisville Texas. Justin explained me that Shawn gave him my contact information. After speaking with Justin over the phone, we spoke about technology and software for 30 minutes. The following day we had lunch and both parties agree to work together. I was excited because it was a part-time job working from home. Who likes to deal with traffic?

Before I applied to any jobs my wife told me to get a remote job. She was feeling better but was worried that she might get sick again. If I was a remote worker, I would be able to assist her if needed. Since I’m an obedient husband, I applied to remote only jobs thru linkedin. After securing a part time with Justin, Ryan, owner of TheWarehouseCo, replied to my application. I had a 15 minutes hangout with Ryan and the next week a 1 hour technical interview. We both agreed to work together and started work mid March.

This was my first time working remotely. In other jobs, I was only allowed to work from home 1 day per week. This time it was just me and my mac computer. It took me a couple of weeks to get used to working by myself without human interaction. I really missed those 5 minute coffee break.

How to deal with 2 part-time jobs?

During the mornings, I wrote web forms code for JBHWorks. After lunch, I wrote .net core code for TheWarehouseCo. March 6 was my birthday but didn’t celebrate it because my wife was not fully recovered. Sometimes we have to make sacrifices for the people we love.

I also wrote a blog post on using AWS Python SDK and Simple Queue Service.

Using AWS Python SDK to Read Simple Queue Service Messages

April

April is one of my favorites months of the year. Weather is perfect. I took advantage of the weather and took my break from work to go to Kiest park. It was awesome experience to walk and listen to the birds. I continued working for both companies during this time. I learned more about .NET Core, React, Docker, and Twilio.

May

I continued working for both companies. My daughter’s birthday was coming up soon. On a Friday, we were playing outside and she had an accident. The rope broke from her swing and she felt hard on the concrete. She landed on her right cheek. She hugged me and didn’t wanted to let go. Next day we took Abby to see a doctor and the x-ray shows a broken collar bone. We were devastated with these news. Doctor suggested to see an specialist to see if surgery was needed. We went to Medical city and the doctor took new sets of x-rays and same thing, broken collar bone. The doctor explained that no surgery is needed since kids’ bone are growing.

I wrote about a very useful Jenkins plugin to integrate AWS CodeDeploy.

Jenkins Plugin – AWS CodeDeploy

June

We went to see Abby’s doctor again. The new x-rays shows bones growing and coming together. Great news! As far as work is concerned, I was able to integrated 2 CRM providers: ConnectWise and AutoTask. I had a very difficult time with ConnectWise’s upload documents api and after many tries I was able to integrated with JBHWorks’ services. I wrote a post with sample code to help other developers.

How to Upload Documents using ConnectWise API

July

During this month, both of my contracts ended. I spoke with my wife and decided to take another break from work. Working as a contractor has advantages and disadvantages. One of the advantage is that you can plan how much you want to work. For example, commit to a 3 month contract and then plan to take a month off after your contract ends. I take this time to spend time with the family. My son was on vacation so I take this opportunity to spend time with him. I continued learning more about AWS. In 2017, I took the AWS certified developer associate exam and failed at it. But this time, I have more time to study and prepare for a re-take exam. Created my Azure account and began using different services. I also wrote a blog post titled Azure Resource Group.

Azure Resource Group

August

Purchased all supplies for my kids’ school. My daughter started pre-kinder 4. She cried a little at home for the first 2 weeks. It’s normal, right? Now she is having fun learning at school. My son, Samuel, helped her sister during this time. He encouraged her sister to go to school.

I have only used 2 recruiters in my career: Robert Half and Prestige Staffing. Robert Half assisted me when I move from PrintPlace to TailLight. Prestige helped with my transition from Verizon Cloud to MD Buyline. For this transition, I worked exclusively with Prestige and went to couple of interviews. I was offered a job but Plano was too far of a commute for me. I also didn’t perform well on other interviews.

Once you start writing, it’s difficult to stop. In this month, I wrote 3 blog posts:

Understanding IAM policies

Host a website using AWS S3

How I landed my first job in IT

September

In addition to working with Prestige, I decided to get more help with my job search. I contacted Robert Half and worked with Ashley. After our initial talk, we agreed on salary expectations and a comfortable commute. She gave me a list with 2 companies: Elevate, and Code America. With Code America, I went thru this process: non-technical phone interview, coding problem thru hackerank, and a final face to face interview. With Elevate, I went thru a similar process: technical phone inteview, and a final face to face interview. During the same week, I received job offers from both companies but at the end I decided to go with Elevate. To force me to learn more about AWS service, I wrote a blog post about Lambda using .NET Core.

My First AWS Lambda Using .NET Core

In this month I also became AWS certified developer associate. This was my second attempt and I passed with 86 out off 100. In my first attempt, I received a 55 since I wasn’t prepare to take the exam.

October

Now with a full time job, things have changed. I’m no longer able to work wearing my pajamas. I have to get up early and dress up. At work, everyone has been very helpful so far. We use Git, Azure, Visual Studio 2017, Angular, C#. Elevate has chosen Azure for their cloud needs so I decided to learn more about it.

Resources to get you started with Azure

November

I wrote a blog post about failures. Even the cloud providers with their extensive teams, and infrastructure have failed to keep their services running. I think software developers don’t expect enough time designing for failures. What do you think?

Thinking About Failures

 December

For the last few months, I have studied for the AWS certified architect associate exam. I’m using acloud guru, reading AWS white papers, and completing labs. I have my own AWS account so I go thru real life scenarios to gain hands on experience. I’m planning to take the exam next month.

Overall I think 2018 was a great year for me and my family. Happy holidays.

 

Categories
General

Thinking About Failures


Recently, I was listening to a re-invent talk where Werner Vogels, AWS CTO, mentioned that everything fails all the time. As I was getting close to home, I started thinking about failures. Power failures. Hardware failures. Software failures. Software developers also encountered failures while building applications. One day might be a database issue. In other situations, it might be a hardware issue that it’s preventing you from getting things done. One of the main problems is that developers are not wired to think about failures. We are builders. We get paid to create new software programs. If you take a look at job descriptions, you will not find many references to failures. In many instances there is no planning for failures. We can learn a lot from Netflix as they have pioneer chaos engineering. Netflix relies on AWS infrastructure to run all its operations. At the beginning, every outage was an opportunity to ask questions without blaming anybody. It was an opportunity to improve the system. By asking the difficult questions, Netflix learned more about its strength and weaknesses. Soon Netflix realized that they needed to test these failures with complete control. A different team was created to bring chaos to Netflix’s system and processes. Without notice, an availability zone was removed. In another day, it was removing an entire AWS region. When these failures occurred, Netflix’s system will stop traffic to the failing region and start re-routing traffic to a good standing region.

We, as software developers, need to spend more time thinking about failures because they will happen sooner or later.

What do you think? Do software developers think enough about failures?