I am a web developer and software engineer currently living in Delhi, India. My interests range from technology to entrepreneurship. I am also interested in running, fitness, and programming.
Monday, 25 May 2020
Understanding focal length and aperture | Become a photographer with Shubham Part-9
Important websites for a programmer
- Feeling stressed? Get some relaxing natural sounds: https://asoftmurmur.com/
- Having something to write again and again and don't want to use regex: https://nimbletext.com/Live
- Write front code on the go: https://codepen.io/
- Always fighting with cron job timings, here is one to do that for you: https://crontab.guru/
- See the regex working in a real environment: https://regexr.com/
- Working in an industry or running your own business overseas, troubling with time zones. Let this site bear all that trouble for you: https://everytimezone.com/
Sunday, 24 May 2020
Six simple ways to improve communication skills | Learn English with Shubham - Part 2
- Start naming everything in english. Instead of "Chai", say it "Tea".
- Try to speak every days happenings in english.
- Try to speak new happenings in english.(What you did new today)
- Try to make paragraph from the sentences made in step 2 and 3.
- Check the grammar, review yourself.
- Speak, record, review repeat.
How to deliver a perfect talk | Learn English with Shubham - Part 1
- Reach the venue well before in time, say 15 mins. Talk to audience before talk, get familiar with them. You can watch these familiar faces during the talk without facing difficulty. Spot 3 spots, right
one, left one , and the middle one. Use these spots to watch during the talk. - Rather than starting by saying "Good morning friends, I'm here to talk about ...bla bla bla, it's good to start by your subject "Cleanliness is next to godliness".
- Have some activities in between to get the audience involved.
- Find common things about you and the audience, use those to relate with your talk.
- WITFM: What is there for me. Lets your audience be clear about what they are going to get.
- Do not act like a self-centric-speaker, rather behave like audience-centric-speaker. Do not talk much about you.
- Voice modulation is very very very effective in a talk.
- Mind you meal before the talk. Have some luke warm water and high fiber diet before the talk. You can have water during the talk to keep your throat wet.
- Think and speak should be in sync.
- Try to talk to one person at a time. After you complete one point, try to point to another person.
- Go amongst the audience, be the audience.
- Body language. Don't touch your clothes, don't cross your fingers. Use eye and body to interact.
- Keep it simple silly.
Monday, 18 May 2020
Merge Sort | Learn Data Structure with Shubham part 2
Sunday, 17 May 2020
Quick Sort Implementation in JS | Learn Data Structure with Shubham part 1
function quickPartition(array, start, end) {if (!array || start == end) {return null;}const pivot = array[end - 1];let i = start - 1;for (let j = start; j <= end-1; j++) {if (array[j] < pivot) {i++;array[i] = array[j] + array[i] - (array[j] = array[i]);/* swap ith and jth element */}}i++;// swap ith and ni1th elementarray[i] = array[end - 1] + array[i] - (array[end - 1] = array[i]);return i;}function quickSort(array, start, end) {if(start < end) {const partionedElement = quickPartition(array, start, end);if (partionedElement == null) {return}quickSort(start, partionedElement-1);quickSort(partionedElement+1, end);}}var array = [1, 2, 9, 10, 15];quickSort(array, 0, array.length);Doubts
When pivot is first node, then consider left as beg+1, and right as last index. Why do we start traversing right to left first, why not right to left.
ANSWER: Because leftmost node is pivot node. Left me element aaega jo chota hoga pivot se, and chota element hamesha right wala hi dega, left wala to bada element right me fekta h. Also the logic, pivot se bade utha kr pivot ke baad feko, chote utha kar pivot se pele feko. Left aaega to bada element uthega and pivot se replace krne pr bada element pivot se pele aa jaega.
Eg: 20 22 15 10, considering 20 as pivot node
Left se start kre to 22 > 20, so left se to chote hone chahie pivot se, so replace
22 20 15 10: Ye to ulta ho gya. That’s why, start loop from the right to left first.
When pivot is left most, to pivot ki initial value kya hoti h?
Ek algo or tha, jisme for loop and j++ krte the.
Pivot node kese select kre? Left, middle or right?
ANS: Teeno ka median
Chosing pivot randomly:
To avoid this, you can pick random pivot element too. It won't make any difference in the algorithm, as all you need to do is, pick a random element from the array, swap it with element at the last index, make it the pivot and carry on with quick sort.
Complexities:
Worst Case: When the array is already sorted. O(n^2)
We can eliminate this case by choosing pivot node as median of first, last and the medium node, and replace that with the last node to keep using the same algorithm.
Best case: When the pivot node always come out to be the medium node in each case O(nLogn).
Avg case: (nLogn).To do average case analysis, we need to consider all possible permutation of array and calculate time taken by every permutation which doesn’t look easy.
We can get an idea of average case by considering the case when partition puts O(n/9) elements in one set and O(9n/10) elements in other set. Following is recurrence for this case.
T(n) = T(n/9) + T(9n/10) + \theta(n)
Solution of above recurrence is also O(nLogn)
Space complexity: Space Complexity: O(n*log n)
AFTER HAVING THE WORST CASE COMPLEXITY OF O(n^2), WHY DO WE USE QUICK SORT???
Although the worst case time complexity of QuickSort is O(n2) which is more than many other sorting algorithms like Merge Sort and Heap Sort, QuickSort is faster in practice, because its inner loop can be efficiently implemented on most architectures, and in most real-world data. QuickSort can be implemented in different ways by changing the choice of pivot, so that the worst case rarely occurs for a given type of data. However, merge sort is generally considered better when data is huge and stored in external storage.
For arrays, merge sort loses due to the use of extra O(N) storage space.
Quick Sort is also a cache friendly sorting algorithm as it has good locality of reference when used for arrays.
Quick Sort is also tail recursive, therefore tail call optimizations is done.
Why MergeSort is preferred over QuickSort for Linked Lists?
In case of linked lists the case is different mainly due to difference in memory allocation of arrays and linked lists. Unlike arrays, linked list nodes may not be adjacent in memory. Unlike array, in linked list, we can insert items in the middle in O(1) extra space and O(1) time. Therefore merge operation of merge sort can be implemented without extra space for linked lists.
In arrays, we can do random access as elements are continuous in memory. Let us say we have an integer (4-byte) array A and let the address of A[0] be x then to access A[i], we can directly access the memory at (x + i*4). Unlike arrays, we can not do random access in linked list. Quick Sort requires a lot of this kind of access. In linked list to access i’th index, we have to travel each and every node from the head to i’th node as we don’t have continuous block of memory. Therefore, the overhead increases for quick sort. Merge sort accesses data sequentially and the need of random access is low.
What is 3-Way QuickSort?
In simple QuickSort algorithm, we select an element as pivot, partition the array around pivot and recur for subarrays on left and right of pivot.
Consider an array which has many redundant elements. For example, {1, 4, 2, 4, 2, 4, 1, 2, 4, 1, 2, 2, 2, 2, 4, 1, 4, 4, 4}. If 4 is picked as pivot in Simple QuickSort, we fix only one 4 and recursively process remaining occurrences. In 3 Way QuickSort, an array arr[l..r] is divided in 3 parts:
a) arr[l..i] elements less than pivot.
b) arr[i+1..j-1] elements equal to pivot.
c) arr[j..r] elements greater than pivot.
See this for implementation.
TODOS:
Pivot as middle
Src: https://www.geeksforgeeks.org/quick-sort/
Sunday, 10 May 2020
Sunrise Photography | Become a photographer with Shubham Part-9
There are a couple of ways to expose for the sun so it’s not too bright. You can set your camera to Center-Weighted metering, which ensures the middle of your picture is not too bright or too dark. Another method (and the one which I prefer), is to have your camera evaluate the entire scene but use exposure compensation to under-expose by roughly two stops.
Regardless of how you meter the scene and set your exposure, the end result is the same. In your resulting image, you want the sun to be visible and not too bright.
Small aperture helps: If you have a high-end zoom lens like a 70-200 f/2.8 or a 300mm f/4, you might be tempted to shoot sunrise pictures with the largest possible aperture. Blurry foregrounds and backgrounds are great, right? So why wouldn’t you shoot wide open?
Contrary to what you might think, smaller apertures are better when taking sunrise photos. First, it helps make sure your entire picture is sharp. Bokeh is great on portraits but not so desirable on most landscapes. A blurry foreground (thanks to a wide aperture) can distract the viewer and leave the scene feeling kind of mushy as a result.
Another reason to use smaller apertures, like f/8 or f/11, is that it gives you more control over your exposure. Remember, the sun is really bright, so you don’t need to worry about not getting enough light in your picture! On the contrary, you actually want to limit the amount of light, especially since you want the foreground to be underexposed
Use a fast shutter speed
The sun moves fast – really fast. Or, rather, the earth spins fast. That’s what is actually happening when you see the sun come up. And just like any time you want to capture motion, you need to use a shutter speed that’s up to the task. Slower values like 1/30th and 1/60th will not only make exposure tricky, but result in a blurry sun as it speeds upwards on the horizon. Use a minimum shutter speed of 1/250th, and even faster if possible
src: https://digital-photography-school.com/epic-sunrise-photos-with-a-zoom-lens/
Capture sunset perfect clicks and Silhouette Photography | Become a photographer with Shubham Part-8
- [Good to have] Focus the subject, then turn off the auto focus. It's required because making a dark object in-focus could be challenging for the camera. But make sure the camera should hold this position and do not move after turning off the auto focus.
- ISO: Minimun (100)
- Aperture: Enough to capture the sharp image. Roughly between f4 to f8.
- Metering: Spot metering. Pointed towards the background, say sky.
- Shutter speed: Adjust the shutter speed as the exposure scale should be showing zero. To capture only sun without any other object, do have a slow shutter speed to capture more and more colours in the sky. Use unexposed photos for sun only photos.
- If you want to capture only sunset, point the sun from any stone or any other object lying on the earth to get it more focused. Since the sun will be at bottom during sunrise/sunset.
- Zoom: 100-200mm would be a good range.
- Longer the lens, bigger the size of sun.
Capture milky way | Become a photographer with Shubham Part-7
- Having a tripod or any same gadget is a must to have a stable picture.
- Use this site to find a place to capture: https://darksitefinder.com/maps/world
- If you lie on a green zone, then only you will be able to click one. It's not really possible to capture from white or red spots.
- Moonless night will be the best one to capture such pics because there will be no light coming from any other source.