Following are the usage instructions for the attached code.
- Create a virtual environment by executing
virtualenv venv
and activate it by executingsource venv/bin/activate
. - Download the
requirements.txt
and install the dependencies by runningpip3 install -r requirements.txt
. - Download the
main.py
file and run it usingpython3 main.py
. - On another terminal, type in
curl "http://127.0.0.1:5000/?tz=Europe/Paris&hr=10&min=5"
. - You should get the output
{"hour": "08", "mint": "05"}
. - If a source timezone is not entered, this would make use of the local timezone of the server. So for
curl "http://127.0.0.1:5000/?hr=10&min=6"
command... - You should get the output
{"hour": "04", "mint": "36"}
. (Local timezone being IST = UTC +05:30) - If no parameters are passed, this would make use of the local time and the local timezone of the server. So for
curl "http://127.0.0.1:5000"
command... - You should get a variable output
{"hour": "02", "mint": "47"}
. (Local timezone being IST = UTC +05:30, Local time being 08:17 at the time of executing this)
The following are the steps I took in order to perform the mentioned tasks.
- Created an empty repository on GitHub under my own username namespace with the following settings.
- Repository has been named
pythview
. - Repository description has been set to
Random repository here - Please ignore if you have run into it by mistake
. - Visibility of the repository has been set to
Public
. - No README.md file was added automatically.
- No .gitignore file was added automatically.
- No default license was chosen from the repository.
- Repository has been named
- Cloned the repository locally by executing
git clone https://github.com/Zlopez/python_interview.git
. - Removed the existing upstream by executing
git remote remove origin
. - Added a new remote
origin
location for the repository by executinggit remote add origin https://github.com/t0xic0der/pythview.git
. - Displayed the name of all available branches locally by executing
git branch --all
. - With
main
being the only branch present, executedgit branch -M main
as the remote has no branches with the namemain
available. - Pushed the code of the current
main
branch to the new remote location by executinggit push -u origin main
. - Executed the code
python test.py
.[t0xic0der@fedorable python_interview]$ python test.py Traceback (most recent call last): File "/home/t0xic0der/Projects/python_interview/test.py", line 41, in <module> no_dup_list = remove_duplicates(unsorted_list) File "/home/t0xic0der/Projects/python_interview/test.py", line 18, in remove_duplicates return no_dup_dct NameError: name 'no_dup_dct' is not defined
- There seemed to be a typographical mistake on line #18. Changed variable name
no_dup_dct
tono_dup_dict
. - Executed the code again
python test.py
.[t0xic0der@fedorable python_interview]$ python3 test.py Traceback (most recent call last): File "/home/t0xic0der/Projects/python_interview/test.py", line 44, in <module> assert no_dup_list == [1, 2, 5, 3, 20, 15] AssertionError
- An assertion error occurred as the first comparison resulted
False
. Made some changes in theremove_duplicates
function in order for it to function properly and executed it againpython3 test.py
.[t0xic0der@fedorable python_interview]$ python3 test.py Traceback (most recent call last): File "/home/t0xic0der/Projects/python_interview/test.py", line 53, in <module> assert sorted_list == [1, 2, 3, 5, 15, 20] AssertionError
- Another assertion error occurred as the second comparison resulted
False
. Made some changes in thesort_list
function in order for it to function properly and executed it againpython3 test.py
.[t0xic0der@fedorable python_interview]$ python3 test.py
- The program executed just fine. Then, the changes were committed and pushed to new branch called
miscellaneous-fixes
by executing the following commands in succession.[t0xic0der@fedorable python_interview]$ git branch add miscellaneous-fixes
[t0xic0der@fedorable python_interview]$ git checkout miscellaneous-fixes
[t0xic0der@fedorable python_interview]$ git add test.py
[t0xic0der@fedorable python_interview]$ git commit -m "Fixed the function definitions" [miscellaneous-fixes 4028b0d] Fixed the function definitions
[t0xic0der@fedorable python_interview]$ git push --set-upstream origin miscellaneous-fixes 1 file changed, 6 insertions(+), 2 deletions(-) Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 387 bytes | 387.00 KiB/s, done. Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (2/2), completed with 2 local objects. remote: remote: Create a pull request for 'miscellaneous-fixes' on GitHub by visiting: remote: https://github.com/t0xic0der/pythview/pull/new/miscellaneous-fixes remote: To https://github.com/t0xic0der/pythview.git * [new branch] miscellaneous-fixes -> miscellaneous-fixes Branch 'miscellaneous-fixes' set up to track remote branch 'miscellaneous-fixes' from 'origin'.
- The code can be found here at https://github.com/t0xic0der/pythview and the changes made by me can be found at https://github.com/t0xic0der/pythview/tree/miscellaneous-fixes.
The following are the steps that I would take in order to troubleshoot the situation when the connection to internet is down on my machine.
- Try opening up different websites on browser to confirm if there is a total outage or an inability to connect to certain services only. (Firefox or any such browser)
- Toggle connection from my machine to my Wifi router off and on to see if that helps to restore the connection and brings back online. (GNOME settings)
- Visit the Wifi router management page
http://192.168.0.1/admin/index.html#/home
to check on ingress-egress activity on the WAN connection. (DLink router page on Firefox or any such browser) - Check if there is an excessive usage of bandwidth by any of the locally connected device - that results in unavailability on my machine. (DLink router page on Firefox or any such browser)
- Confirm if there any active firewalls running which disallows connections or if any VPN service is enabled to allow for certain traffic conditions only. (firewalld if installed or GNOME settings)
- Substantiate DNS, gateways and route configurations and verify if they have not been changed inexplicably by any misbehaving applications. (GNOME settings - Wifi page)
- If all else fails, reach out to the internet service provider to inquire about downtimes and of estimated time of service getting back online. (Phone)
In order to update my fork with the upstream changes on a specific branch (here, master
), the following steps were performed.
- The project
forge
was forked from AstroSonic's namespace (i.e. https://github.com/astrosonic/forge) to my namespace (i.e. https://github.com/t0xic0der/forge). - The upstream repo was cloned locally and changes were made to the
requirements.txt
file in order to make sure that the dependencies do not point to a specific version. - The changes were committed to a branch called
non-specific-requirements
(https://github.com/astrosonic/forge/tree/non-specific-requirements), pushed (https://github.com/astrosonic/forge/pull/42/commits/5d1eecdf3f4962ae08dc98e33308c5626db719f3), a PR was created (astrosonic/forge#42) and merged tomaster
. - Now, the fork from my namespace is cloned locally and the following commands were executed in succession.
[t0xic0der@fedorable forge]$ git remote add upstream https://github.com/astrosonic/forge.git
[t0xic0der@fedorable forge]$ git fetch upstream remote: Enumerating objects: 6, done. remote: Counting objects: 100% (6/6), done. remote: Compressing objects: 100% (3/3), done. remote: Total 4 (delta 2), reused 2 (delta 1), pack-reused 0 Unpacking objects: 100% (4/4), 888 bytes | 888.00 KiB/s, done. From https://github.com/astrosonic/forge * [new branch] electron-application -> upstream/electron-application * [new branch] legacy-layout -> upstream/legacy-layout * [new branch] master -> upstream/master * [new branch] modern-layout -> upstream/modern-layout * [new branch] non-specific-requirements -> upstream/non-specific-requirements
[t0xic0der@fedorable forge]$ git rebase upstream/master Successfully rebased and updated refs/heads/master.
[t0xic0der@fedorable forge]$ git push origin master Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 To https://github.com/t0xic0der/forge 48f679f..8673de6 master -> master
- This happened seamlessly here because there were no changes made to the fork, which were disjoint from those of the
upstream
. In a way, it can be said that the commits in the fork were a subset of that of theupstream
. But if there are changes made to the fork which do not exist in theupstream
- these changes would be divergent and in such cases, a normal push may be rejected due to disjoint changes. Then, one can either merge the changes from theupstream
to the fork to have both of the changes or force-push the rebase. Discretion is advised with using the latter as that would end up overwriting the changes made on the fork in the favor of retaining those of theupstream
.