Posts

Initializing shallow 2D arrays in Python

Image
"Wild life: Heron In Shallow Water shot#2" by Jangra Works is licensed under CC BY 2.0 You may have seen that there is an easy way to initiate an array or 2D array with default values by multiplying the array with number of elements.  row, col = 2 , 3 array = [[ 0 ] * col] * row print (array) [ [ 0 , 0 , 0 ], [ 0 , 0 , 0 ] ] This list is created as shallow list, which means outer array is pointing to the same inner arrays. When you change any value in the inner array, it will be visible to all outer arrays. Here is a good visual representation ( ref ). When you make a change on any element of the inner array, it will make a change to all out array values as well because they are referencing to the same inner array (columns).  array[ 0 ][ 1 ] = 1 print (array) [ [ 0 , 1 , 0 ], [ 0 , 1 , 0 ] ] In order to make a independent 2D elements, you may use the list comprehension with inner and outer array. This subtle difference can be difficult to debug sometime

3S slice notation for Python arrays

Image
"Climbing the Rocky steps" by Scott SM is licensed under CC BY-NC 2.0 Do you want to quickly select every nth element in a Python array? No problem, arrays in Python have built-in 3S property (aka slice notation), where you can specify start , stop and step to filter items in an array. Syntax is pretty simple, array[start:stop:step]. Implicitly if you don’t specify the property, Python will default to the largest unfiltered value and stop value is not included. Default stop value is length of the array, default start value is 0 and default step value is 1. Following snippet shows a few examples on a sample array. numbers = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] # Select numbers smaller than 5 and larger than 1 print (numbers[ 2 : 5 ]) [ 2 , 3 , 4 ] # Print all even numbers except 0 print (numbers[ 2 :: 2 ]) [ 2 , 4 , 6 , 8 ] # Print all odd numbers reversed print (numbers[ ::- 2 ]) [ 9 , 7 , 5 , 3 , 1 ] # Python is nice in case you use an invalid index, it returns empt

Rounding numbers in Python

Image
"Decorated ceiling at art school" by sallysetsforth is licensed under CC BY-NC-SA 2.0 Dividing integers is a pretty common operation in programming. Based on your need, you may want to round to the ceiling or to the floor integer if the result of the division is not an integer. Let's take a look at these two examples in Python. >>> 5 / 2 2.5 >>> round ( 5 / 2 ) 2 >>> 7 / 2 3.5 >>> round ( 7 / 2 ) 4 As you can see in the example above, rounding 2.5 resulted as 2 (floor integer); whereas, 3.5 resulted as 4 (ceiling integer). Why is that? Starting v3, Python implemented Banker's rounding (also known as round to even rounding, statistician's rounding, Gaussian rounding) as its default rounding method. Legacy method of always rounding 0.5 up technique results in a bias toward a higher number. When we make millions of these calculations, the magnitude of this bias becomes significant. One caveat of this method is that increasing t

3 Must Haves of a Status Report

Image
If you are a project manager, status report is the vital part of your communication to the leadership and audiences interested in your project. The purpose of the status report is not to drive a project with stakeholders. Project planning and driving should be handled separately. Status report has a single purpose, describe the status of the project. That's it. Here are the 3 attributes a status report should have. 1. Brief and Clear A status should be short and well thought. Remember what Mark Twain said, "I didn't have time to write a short letter, so I wrote a long one instead.". If your status report is long and hard to follow, it means you did not think enough on it. If you have not spend time on your status report, why would other people spend more time on your status report to understand. Even worse, if they read and try to decipher what you have written, each person may interpret it differently. Therefore, keep important updates at the top and use clear

Curl "No status code specified in the response"

Sarps-Mac $ curl -vvv -X GET "https://jmd88pxp.execute-api.us-west-2.amazonaws.com/dev/user?limit=10" Note: Unnecessary use of -X or --request, GET is already inferred. *   Trying 54.192.119.190... * Connected to jmd88pxp.execute-api.us-west-2.amazonaws.com (54.192.119.180) port 443 (#0) * TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 * Server certificate: *.execute-api.us-west-2.amazonaws.com * Server certificate: Symantec Class 3 Secure Server CA - G4 * Server certificate: VeriSign Class 3 Public Primary Certification Authority - G5 > GET /dev/user?limit=10 HTTP/1.1 > Host: jmd88pxp.execute-api.us-west-2.amazonaws.com > User-Agent: curl/7.49.1 > Accept: */* >  < HTTP/1.1 502 Bad Gateway < Content-Type: application/json < Content-Length: 36 < Connection: keep-alive < Date: Sun, 18 Dec 2016 00:54:14 GMT < X-Cache: Error from cloudfront < Via: 1.1 66ed69e8b47ad05050331602c798133a.cloud

AWS encryption chart (SSE-S3 vs SSE-KMS vs SSE-C)

IN TRANSIT AT REST SSL/TLS Server Side Managed Keys Client Side Managed Keys S3 (SSE-S3) Each object is encrypted with a key. Amazon encrypts the key with a master key, which rotates regularly. AWS Key Management Service (SSE-KMS) Allows you to audit trail (who and when used the key), extra cost and you manage the master key. Customer provided (SSE-C) User manages the keys but encryption done by Amazon User encrypts the data on client-side and uploads to S3

Is Wharton Business Foundations Specialization Good?

Last year, I have been accepted to a traditional MBA program. However, I dropped out and decided to get business education from online resources. I received an e-mail from  Coursera website  about Wharton Business Foundations Specialization. Wharton is #4 ranked MBA school according to US News  and online specialization includes the following courses with a final capstone project. Introduction to Marketing (#2 in US News) Introduction to Financial Accounting (#2 in US News) Introduction to Operations Management (#2 in US News) Introduction to Corporate Finance (#1 in US News) Wharton Business Foundations Capstone Wharton does not have part-time MBA curriculum and I want to keep working while learning business. I signed up the same week I received the e-mail and it took me couple of months to complete the specialization (weekends only). I learned a lot during all these courses and had chance to apply them at work. Long story short, I would like to share my final Capstone pro