≡ Menu

17 Practical Python Tuples Examples

[Python Tuple Examples]Tuple is similar to List in python language, both are sequential, index based data structure.

The main difference between tuples and list is that tuples are immutable i.e. we cannot modify a tuple’s content but List is mutable data structure. Also, tuples uses parenthesis and list uses square brackets.

This article will discuss about following in Tuples:

  1. Create an Empty Tuple
  2. Create Tuple with Homogeneous Elements
  3. Create Tuple with Heterogeneous Elements
  4. Create Tuple with Single Element
  5. Modify Elements of Tuple
  6. Accessing Elements of Tuple – From the Front
  7. Accessing Elements of Tuple – From the Back
  8. Search Within a Tuple
  9. Add Elements to a Tuple
  10. Delete an Element from a Tuple
  11. Iterate Over a Tuple
  12. Concatenation of Tuples
  13. Identify Length of a Tuple
  14. Slice a Tuple
  15. Count the Number of Elements in a Tuple
  16. Identify the Index of an Element in a Tuple
  17. All Tuple Examples in one Example tuples.py Program

(more…)

[AWS OpsWorks]In your AWS environment, for configuration management, you can use AWS OpsWorks which provides managed instances of either Chef or Puppet. You have the following three options when using AWS OpsWorks.

  1. AWS Opsworks for Chef Automate
  2. AWS OpsWorks for Puppet Enterprise
  3. AWS OpsWorks Stacks – This is for application modeling and management. You can model your app as a stack with different layers (e.g: web layer, db layer, etc.). This uses Chef solo in the backend to configure nodes.

This tutorial provides the following examples on how you can manage your AWS OpsWorks servers from CLI using aws opsworks-cm command.

  1. Create OpsWorks Server (Chef or Puppet) using create-server
  2. View OpsWorks Server Details using describe-servers
  3. Delete an OpsWorks Server using delete-server
  4. View Account Attributes and Server Events of a Server
  5. Update Server Maintenance and Backup Window using update-server
  6. Disable or Enable Automated Backups
  7. Specify Backup Retention Count
  8. Reset Chef Server’s Private Key (or) Update Puppet Admin Password
  9. Take a Backup of OpsWorks Server using backup-server
  10. View Available Backups using describe-backups
  11. Delete an OpsWorks Backup using delete-backup
  12. Restore OpsWorks Server from a Backup using restore-server

(more…)

OOP stands for Object Oriented Programming. This concept is a style of solving programming problems where properties and behavior of a real-life object is packaged as a single entity in the code.

This style of coding enables modularizing and scaling with least amount of issues.

Python is a dynamically typed, high level interpreted programming language. Python supports several OOP features including the following:

  • Classes and Objects
  • Encapsulation
  • Inheritance
  • Polymorphism

(more…)

While using git, for most part, you shouldn’t be working directly on the master branch.

Any development work, or hotfixes, or research work that you do, you’ll typically create a new branch, and make changes to your code on that branch.

If you are happy with your code changes on your branch, then you’ll merge it to the master branch.

Or, if you created a branch to quickly test something by making some code change without the intention of keeping your code change, then after your testing, you can simply discard your code changes by deleting the branch that you created for your testing purpose. This way, the code in your master branch is not affected.

This tutorial explains the following steps:

  1. Create a new dev branch
  2. Do your work on local dev branch
  3. Push dev branch from your local to central git repository
  4. Once your work is done, merge dev branch to master
  5. Finally, delete the dev branch from both local and central git repository

 

(more…)

Splunk supports three types of authentication: Native Authentication, LDAP and Scripted Authentication API.

For most part, Native Authentication is referred as Splunk authentication, which takes high priority over any external authentication.

So, if an user exists in both Splunk native authentication and LDAP, Splunk will use the user in the native authentication.

Typically, you’ll create an user, and then assign the user to a role. This is called role-based access control system. You can do this either using Splunk CLI or from Splunk Web.
(more…)

[GoLang Slice Examples]Slice is an essential component of Go programming language.

When writing a go program, for most common use-cases, you’ll be using slice instead of array.

An array is fixed in size. But slices can be dynamic. The number of elements in a slice can grow dynamically.

But, keep in mind that slice uses array in the backend. Slice by itself doesn’t store any data. Think of slice like a reference to an array. All it does is to describe part of the underlying array.

This tutorial explains the following slice concepts:

  1. Declare Slice Variable and Make a Slice with X number of Elements
  2. Declare and Initialize Slice at the same time without using Make
  3. Initialize a Slice using Multi-Line Syntax
  4. Assign a Value to a Specific Element in a Slice
  5. Access a particular Element in a Slice
  6. Display All or Specific Elements from a Slice
  7. Create Slice with Low and High values using Colon Syntax
  8. Slice Refers to an Array underneath – Implication of Changing Slice Element Value
  9. Slice of Structs
  10. Identify Length of a Slice – How many Elements are there?
  11. Slice Capacity – Length vs Capacity
  12. Empty Slice without an Array Underneath
  13. Append one or more Elements to an existing Slice
  14. Copy elements from one Slice to another (Duplicate Slice)
  15. Two Dimensional Slices
  16. Loop through Slice Elements using For and Range
  17. Loop through a Slice and get only the Values (Ignore Slice Index)
  18. Full Working GoLang Code with All Slice Examples

For details on Go Array, refer to our previous tutorial: 12 Practical Go Array Examples

(more…)

[AWS Configure Example]To use AWS CLI, you need to first make sure your AWS access key credentials are configured properly.

Once you have your AWS access_key_id and secret_access_key, you can either manually add them to the credentials file, or use aws configure command to set it up on your local machine.

This tutorials explains all the options available in aws configure command along with how to manage multiple profiles:

  1. First Time Configuring AWS Credentials – Default Profile
  2. ~/.aws Directory – Config and credentials File for Default Profile
  3. Edit Default Profile Credentials – Connect to Different AWS Account
  4. Create Multiple AWS Profiles – Dev and Prod
  5. ~/.aws Directory – Config and credentials File for Multiple Profiles (Dev and Prod)
  6. Switching Between Different AWS Profiles using –profile Option
  7. Switching Between Different AWS Profiles using AWS_PROFILE Env Variable
  8. View Profile Information using list Option
  9. Change Default Config and Credentials FileName and Location
  10. View a Specific Profile Parameter Value using get Option
  11. Set a Specific Profile Parameter Value using set Option
  12. Add New Model using add-model Option

(more…)

[GoLang Array Examples]To get a good handle on Go programming language, it is essential to understanding arrays and slices.

If you are developer, or sysadmin who is new to Go, it is important to understand the following key differences in how array is handled in Go when compared to other language:

  • You cannot change the size of the array once it is declare.
  • The array size should be specified when you declare an array. To overcome this limitation, you’ll be using slices for most part in GoLang. But, it still sill important to understand how array works, as slices works on top of array.
  • When you assign an array to another array, essentially you are copying all the elements from one to another.
  • The above is important to understand, as when you are passing an array as a parameter in an function, the function will really get a copy of the array and will work on it. It is not a pointer that we are passing. It is copy of the whole array.

This tutorial explains the following basics of array handling in Go, with a full working example along with the output that is provided at the end of this tutorial.
(more…)