I spent a week offline here is how I stayed productive
Tags: javascript, cpp, python, productivity
Published: 2020-04-01 13:31:37


Hi there, its been a long time since I have written something here.
I hope all of you are in good health 💪.

> This post was originally written [here](https://bhupesh.codes/i-spent-a-week-offline-here-is-how-i-stayed-productive/)

## Backstory
My Internet was affected recently due to some unforseen reasons, this means that I was completely offline (i.e no texting, no memes & no `git push` 😭).

I was afraid this will hinder my work & stop my learning but as it turns out, my _past decisions_ somehow saved me.
I actually have this habit of downloading & saving useful PDFs (Books to be specific) & never read them again 🙈, so I had started organising them under proper categories.

I started looking for these "PDFs" on my PC & after 15 mins of searching here is how the goldmine of info. looks like

```
PDF-Learning
├── Algorithms & Data Structures
│   ├── Algorithms for dummies.pdf
│   ├── AlgorithmsNotesForProfessionals.pdf
│   ├── CLRS.pdf
│   └── Competitive Programming.pdf
├── C++
│   ├── Accelerated C++.pdf
│   ├── A Tour of C++ - Bjarne Stroustrup (Addison-Wesley, 2018).pdf
│   ├── C-- 11.pdf
│   ├── C++14 syntax reference.pdf
│   ├── C++ Game Development Book.pdf
│   ├── C++ GUI Programming with QT4, Second Edition.pdf
│   ├── C++ Interview Questions.pdf
│   ├── C++ NotesForProfessionals.pdf
│   ├── cpp-best-practices.pdf
│   ├── cpplambda_preview_25th_march_2019.pdf
│   ├── C++ standard library reference.pdf
│   ├── C++ STL_ReferenceManual.pdf
│   └── History_of_C++.pdf
├── Computer Vision
│   ├── OpenCV_Computer_Vision_with_Python_-eBook-.pdf
│   └── opencv-python-tutroals.pdf
├── dotNET
│   ├── complete-reference-vb_net.pdf
│   ├── DotNETFrameworkNotesForProfessionals.pdf
│   ├── Intro to VB.NET.pdf
│   ├── vb.net_tutorial.pdf
│   └── VisualBasic_NETNotesForProfessionals.pdf
├── GNU Octave
│   ├── Jesper Schmidt Hansen - GNU Octave for Beginners.pdf
│   ├── octave.pdf
│   ├── octave_tutorial_coursera.pdf
│   └── rob2-03-octave.pdf
├── HTML5 & CSS
│   ├── book.pdf
│   ├── Bootstrap
│   │   ├── Bootstrap-Programming-Cookbook.pdf
│   │   └── bootstrap_tutorial.pdf
│   ├── CSS 3.pdf
│   ├── cssanimation-101.pdf
│   ├── CSSNotesForProfessionals.pdf
│   ├── css_tutorial.pdf
│   ├── cssvisualdictionary2ND.pdf
│   ├── cssvisualdictionary.pdf
│   ├── HTML5NotesForProfessionals.pdf
│   ├── html5_tutorial.pdf
│   └── wsu-css-cheat-sheet.pdf
├── JS
│   ├── AJAX
│   │   ├── Ajax.pdf
│   │   └── ajax_tutorial.pdf
│   ├── Angular JS
│   │   ├── AngularJSNotesForProfessionals.pdf
│   │   └── angularjs_tutorial.pdf
│   ├── javascriptgrammar-dark.pdf
│   ├── javascriptgrammar-II.pdf
│   ├── javascript-handbook.pdf
│   ├── Javascript JSON and Ajax v2.pdf
│   ├── JavaScriptNotesForProfessionals.pdf
│   ├── Javascript.pdf
│   ├── javascript_tutorial.pdf
│   ├── jQuery
│   │   ├── jQueryNotesForProfessionals.pdf
│   │   ├── jQuery.pdf
│   │   └── jquery_tutorial.pdf
│   ├── Node JS
│   │   ├── Learning Node.pdf
│   │   ├── NodeJSNotesForProfessionals.pdf
│   │   ├── Node js.pdf
│   │   └── nodejs_tutorial.pdf
│   ├── react-in-action.pdf
│   ├── ReactJSNotesForProfessionals.pdf
│   ├── ReactNativeNotesForProfessionals.pdf
│   └── You Don t Know JS by Kyle Simpson.pdf
├── Linux
│   ├── BashNotesForProfessionals.pdf
│   ├── Kali Linux Revealed.pdf
│   ├── Linux Command line.pdf
│   └── LinuxNotesForProfessionals.pdf
├── Machine Learning & Deep Learning
│   ├── A Beginners Guide to the Mathematics of Neural Networks.pdf
│   ├── An Introduction to Machine Learning.pdf
│   ├── Chapman_ _Hall_Crc_Machine_Learning.pdf
│   ├── Deep Learning for NLP.pdf
│   ├── [Harrington_P.]_Machine_learning_in_action(BookZZ.org).pdf
│   ├── Introduction to ml+time series.pdf
│   ├── Logistic Regression.pdf
│   ├── Machine Learning For Dummies.pdf
│   ├── master_machine_learning_algorithms.pdf
│   ├── Mathematics for ML.pdf
│   ├── MLND+2-Term+Syllabus.pdf
│   ├── Ng_MLY01_13.pdf
│   ├── PYTHON_DEEP_LEARNING.pdf
│   └── SLR_Leastsquares.pdf
├── Python
│   ├── Django
│   │   ├── Aratyn T. - Building Django 2.0 Web Applications - 2018.pdf
│   │   ├── djangoapibook.pdf
│   │   ├── djangobook.pdf
│   │   ├── django_cheatsheet.pdf
│   │   ├── django-intro.pdf
│   │   ├── Django Projects Blueprint.pdf
│   │   └── Leanpub.Tango.With.Django.pdf
│   ├── LPTHW.pdf
│   ├── Modern Python Cookbook.pdf
│   ├── Python for Informatics.pdf
│   ├── PythonNotesForProfessionals.pdf
│   ├── Python Web Scraping
│   │   ├── Python Web Scraping - Second Edition [eBook].pdf
│   │   └── scrapy_tutorial.pdf
│   └── Violent Python.pdf
├── Special
│   ├── AndroidNotesForProfessionals.pdf
│   ├── AN INTENSIVE\012INTRODUCTION TO\012CRYPTOGRAPHY.pdf
│   ├── Computer Networking.pdf
│   ├── Getting_Started_with_Go_for_Data_Structures_and_Algorithms.pdf
│   ├── GitNotesForProfessionals.pdf
│   ├── good_concepts.pdf
│   ├── HackerRank_Checklist-for-Screening-Back-End-Developers.pdf
│   ├── HackerRank_Checklist-for-Screening-DevOps.pdf
│   ├── HackerRank_Checklist-for-Screening-Front-End-Developers.pdf
│   ├── HackerRank_Checklist_Screening-Full-Stack.pdf
│   ├── HackerRank-Junior-Senior-Developer-Hiring-Checklist.pdf
│   ├── Hackers Underground.pdf
│   ├── How_to_earn_10_000_while_learning_to_code_-_3rd_Edition.pdf
│   ├── iOSNotesForProfessionals.pdf
│   ├── Matters Computational.pdf
│   ├── MongoDBNotesForProfessionals.pdf
│   ├── PowerShellNotesForProfessionals.pdf
│   └── Rest API.pdf
└── Unclassified Programming Languages
    ├── CSharpNotesForProfessionals.pdf
    ├── HaskellNotesForProfessionals.pdf
    ├── JavaNotesForProfessionals.pdf
    ├── KotlinNotesForProfessionals.pdf
    ├── ObjectiveCNotesForProfessionals.pdf
    ├── php_tutorial.pdf
    ├── RubyOnRailsNotesForProfessionals.pdf
    └── SwiftNotesForProfessionals.pdf

19 directories, 120 files

```

Well ofc I utilised this off-time to start reading some of them.
In this post I share some of the interesting things I got to know through these, This post is going to be quiet long 🙃, so if you are not that patient you can jump to conclusion which suggests my [3 Takeaways](#3-takeaways) from this post.

Otherwise, sit back pick up some ☕
Below is a day-wise journal of some interesting things I learned & did over these 7 days.


## Day 0 : Linux is 💛

- Well we all know that `cat` command right ? it is used to display contents of any file, fine !
But do you know, we also have a `tac` command which is also used to display contents of a file but in **reverse** order.

```bash
$ cat butwhy.sh 
This is first line.
And
This is second line.
And you know what
This is the 3rd line.

$ tac butwhy.sh  
This is the 3rd line.
And you know what
This is second line.
And
This is first line.
```

<figure>
    <img src="https://makeameme.org/media/templates/250/jackie-chan-why.jpg">
    <figcaption>but why ?</figcaption>
</figure>



- **`pwd`**, seems familiar prints the current working directory.
but it has a sister command called `pwdx`.
It is used to print current working directory of a _currently running process_.
```bash
$ sudo pwdx 997 # process id
[sudo] password for bhupesh: 
997: /
# this is the root prcess
```

- Do you guys are sometimes confused with the Linux file system hierarchy 🤔
looking online for what a folder contains is NOT a solution.
Go to your termial and type
```bash
man hier
```
This will print a description of the filesystem hierarchy
Also a similar command to print a less verbose version of FS hierarchy is
```bash
man file-hierarchy
```

- I know this might kinda feel dumb, but i didn't know we had a simple version control in Linux built-in, running the `diff` command prints the difference between 2 files.

<img src="https://drive.google.com/uc?export=view&id=1ILsHOKx5q7ZIF1qL-uFYySxBIshzcwVq">

- `tr`, lets you translate squeeze, and/or delete characters from standard input & write them to standard output.
```bash
> ls | tr a-z A-Z
ALGORITHMS & DATA STRUCTURES
C++
COMPUTER VISION
DOTNET
GNU OCTAVE
HTML5 & CSS
JS
LINUX
MACHINE LEARNING & DEEP LEARNING
PYTHON
SPECIAL
UNCLASSIFIED PROGRAMMING LANGUAGE
```
The above command just translates all lowercase file names to uppercase, note that filenames are not changed.


## Day 1 : Javascript is nice 👌

This day I started reading [javascriptgrammar](https://www.amazon.com/JavaScript-Grammar-Color-Greg-Sidelnikov/dp/1091513465), some of the interesting things i didn't know (mind you I am not a JS programmer, but I write it sometimes)


- `Symbol()`
The Symbol provides a way to define a completely unique key. It doesn’t have a constructor and cannot be initialized using new keyword.
An assignment to Symbol will create a new symbol with a unique ID.

```js
// Simple symbol
const newSymbol = Symbol();
typeof newSymbol === 'symbol' // true
// A symbol with a label
const anotherSymbol = Symbol("label");
// Each symbol is unique
const yetAnotherSymbol = Symbol("label");
yetAnotherSymbol === anotherSymbol; // false

```

One of the use case of symbol that it can be used to create private object properties

- `console.time()` & `console.timeEnd()`
This is not related to JS directly but the console API lets you time how long a piece of code executes.

<img src="https://drive.google.com/uc?export=view&id=1at4UDzRPLf4a7UkA-5MqUrFWewVqKX-x">

- File API
You can read files in Javascript by using the `FileReader()`

```html
<input type="file" id="upload">

<script type="text/javascript">
document.getElementById('upload').addEventListener('change', readFileAsString)
function readFileAsString() {
    var files = this.files;
    if (files.length === 0) {
        console.log('No file is selected');
    return;
    }
    var reader = new FileReader();
    reader.onload = function(event) {
        console.log('File content:', event.target.result);
    };
    reader.readAsText(files[0]);
}
</script>
```


I also learned these 2 cool tricks in linux.

- Builtin debugger for shell scripts (well kinda)
You can see execution of each statement in a shell script by using the `-x` flag while invoking the script via `bash`
```bash
bash -x hello.sh
```

- To print your PC Hardware info in a nice readable format you can pass the `-html` flag in `lshw` (list hardware) command
```bash
sudo lshw -html > myhardware.html
```

<img src="https://drive.google.com/uc?export=view&id=1N7DrbrsF-jmh-9t3D1-Ck0RITXAghhHk">

## Day 2 : HTML5 is 😮

This day I had a look in [HTML5 Notes For Professionals](https://books.goalkicker.com/HTML5Book/) and damn I don't know HTML now.

- You can tell the browser to prefetch a URL so that it can be loaded more quickly.

```html
<link rel="prefetch" href="">
```

- You can validate user input by using [patterns](http://html5pattern.com/Names) within HTML (kinda looks like regex)

```html
<input pattern="\d*" title="Only Numbers">
```

<img src="https://media1.tenor.com/images/29987642643386e96d63b6fe8b8cb032/tenor.gif?itemid=7244010">

- We can sandbox (isolate) an iframe and restrict things an iframe is allowed to execute by using the `sandbox` attribute.
Using this, the contents of the iframe are treated as being from a unique origin and features including scripts, plugins, forms and popups will be disabled.

```html
<iframe sandbox src="http://example.com/"></iframe>

<!-- To allow the page to run scripts & form submission -->
<iframe sandbox="allow-scripts allow-forms" src="http://example.com/"></iframe>
```

## Day 3 : Python is 🔥

This day I explored [Python Notes For Professionals](https://books.goalkicker.com/PythonBook/)

> this day I have also started writing the 1st draft of this post.

Some interesting things that I learned this day:

- The `heapq` library lets you find _n_ largest or smallest numbers in an iteratable.

```python

>>> import heapq
>>> mylist = [120, -34, 0, 56, 444, 78]
>>> heapq.nlargest(2, mylist)
[444, 120]
# notice the order
>>> heapq.nsmallest(3, mylist)
[-34, 0, 56]
>>> 

```
This can be very useful for those who for say do competitive programming in python 🙃


- Python's Default JSON Pretty Printer,
You can invoke the `json.tool` from command line to pretty print a json file

```bash
python -m json.tool journal.json

# sample output :)
{
    "journal": [
        {
            "day0-activity": "I slept"
        },
        {
            "day1-activity": "I slept"
        },
        {
            "day2-activity": "I watched Avengers Endgame"
        }
    ]
}

```

> **Tip** 🚩<br>
You can also use the `pprint` package to prettify things on console.

- Want to input sensitive info. at command line, don't worry Python's default library has something for you.
The `getpass` module lets you take input from user without _echo'ing_ it to the terminal/screen.
```python
>>> from getpass import getpass
>>> pass_in = getpass()
Password: 
>>> pass_in
'iwonttellu'
>>> 
```

## Day 4 : Turn the PC off

I didn't use my PC this day, but I read this book called [CodeComplete 2](https://www.amazon.com/gp/product/0735619670/)

> Again, a previous decision saved me

I read some Software Design Characteristics, here are a few which I understood.

- Minimize Complexity<br>
Creating easy to understand designs is the key. Using designs which are not easily understood defeats the whole purpose of creating and applying Software Design Concepts.

> I recently read somewhere that Netflix's Architecture is so complex that no one person can explain/describe it completely.<br>
_Source: A random YouTube video_

- Reusability/Extensibilty<br>
Make sure to write code in dedicated classes/modules/packages so that someone (or you) can easily extend them sometime in future. <br>
The best example of this is how the FOSS community has grown over these years by creating things which use reusable components or are extended from each other. Most (i bet 80%) of the popular technologies you use are somehow using OpenSource software thus enabling reusability.

- Loose Coupling<br>
Coupling means how different programs/classes are connected together. Coupling should be minimum because it minimizes work during intergration, testing & maintenance.

> Soo far trying to do this, I think it is atleast a bit hard for beginners,

- Portability<br>
It means what it spells, a system should be designed (& developed) so that it can be ported to a different environment easily.

> For e.g you can start simply by structuring your code well, developing in _Virtual Environments_ or use more fancier alternatives like docker.

## Day 5 : The execution 👷 day

- You remember the `tac` command we learned on Day 0 ? here is a simple implementation of the same in python

```python
#!/usr/bin/env python3

"""Simple implementation of tac"""
import sys


def main():
    if sys.argv[1] is not None:
        with open(sys.argv[1], "r") as fp:
            file = fp.readlines()
        file.reverse()
        for line in file:
            print(line, end='')


if __name__ == '__main__':
    main()

```

A sample run
```bash
> python3 tac.py hello.sh
expr 2 + 2
echo "Hello World"
> tac hello.sh           
expr 2 + 2
echo "Hello World"
>
```

- Do you remember that we discovered the `FileReaderAPI` in Javascript on Day 1 ?
I thought this is the time I need to create a pretty basic version of a Simple Notepad
[Here](https://sastanotepad.netlify.com/) it is, and the [source](https://github.com/Bhupesh-V/sastaNotepad) (i know it looks ugly)

> **Tip** 🚩<br>
If you are on a Debian or Ubuntu based system, you can run the `browse` command to open files and URLs.
For ex `browse https://bhupesh.codes` will open my website in your default web-browser.

## Day 6 : Functional Programming

This day I explored & compared functional programming concepts in C++, JS & Python.
In all these 3 languages we have some sort of methods/functions available to do the 3 basic things that generally power functional programming i.e

- _map_: do(map) some operation on a set of items
- _filter_: filter/return some items which match a criteria
- _reduce_: reduce the set of items to a single value.

<img height="200px" src="https://drive.google.com/uc?export=view&id=1oFcYrWGm58pgmgf6ooufpb3n1HZyT8eo">

Here is a brief overview of the 3 concepts in C++ 💙.
```cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

void print(int n){
    std::cout << n << " ";
}
int main(){

    std::vector<int> v{20, 0, -1, 100, 5};
    std::vector<int> v2, v3;

    std::cout << ".....map.....\n";
    std::cout << "for_each() demo\n";

    // map an operation on a set of elements
    for_each(v.begin(), v.end(), print);
    transform(v.begin(), v.end(), back_inserter(v2), [](int n) { return n * 2 ;});
    std::cout << "\ntransform() demo\n";
    for_each(v2.begin(), v2.end(), print);

    std::cout << "\n\n.....reduce.....\n";
    std::cout << "accumulate() demo\n";

    // reduce the elements to a single value, by default accumulate() sums all elemets, if no other operation is specified
    int sum_vector_v2 = accumulate(v2.begin(), v2.end(), 0);
    std::cout << sum_vector_v2 << "\n";

    std::cout << "\n.....filter.....\n";
    std::cout << "copy_if() demo\n";

    // filter elements which are divisible by 5
    copy_if(v2.begin(), v2.end(), back_inserter(v3), [](int a) { return a % 5 == 0; });
    for_each(v3.begin(), v3.end(), print);

    return 0;
}
```

## 3 Takeaways

This offline time strengthen my views on few things, I summarized some of them below.

### 1. **Be offline for a day atleast 🔌**

I am sure we all have important things to do, and developers per say are always connected to the web, its time to take a break.
I have seen people taking a break from Social Media, that's great but you know what, cut-off the internet entirely & don't do any Internet related work for a day (includes no binge watching).

> Relax, Meditate, Play with your pet, Practice things that you can do offline

### 2. **Just Read 📚**

You by now have already seen a ton of posts telling you that reading is a good habit, everyone should do it.

> They are 100% ✅

I know not everyone likes to read but you can atleast read a chapter in 2 days, hell our ancestors used to read to impart & share knowledge.
There is also one strong reason why you should read as an aspiring dev.<br>For e.g. there are professional people who have clubbed their advice, suggestions & best practices into 1 big piece of thing called a "book". This book contains valuable info. that you would probably never find on Internet. 

<!-- insert link to some post about books -->

### 3. **Keep a small journal/blog 📔**

Its upto you what you want to keep in this journal, you could go ahead and create a **til**(today i learned) repo just like me 🙃

[![Bhupesh-V/til - GitHub](https://gh-card.dev/repos/Bhupesh-V/til.svg?fullname=)](https://github.com/Bhupesh-V/til)

This also means that you should start your own blog (if you are reading this on DEV, then you are halfway there).

There are no restrictions on your blog, it doesn't needs to be 1000 words, nobody is going to bother you in any way on what you write or share, its your personal space on internet.
No problem if you are writing once a month (unless you want to earn 🤑 from it), as i said your blog, your choice.

> **Insight** 💡 <br>
Over the past year my writing has improved (I started Aug 2019) & I have gain a lot just by writing for instance I am no longer confused with my project ideas and slowly I have started enjoying this.

If you have no idea what to write here are some example scenarios that might help.
- Something you learned today.
- Something you made (literally anything).
- You got a job/internship & how did you got it & what helped.
- You solved an interesting problem.
- You helped someone.
- Tricky bug you fixed.
- Contributed to FOSS (how, what & why)
- That feature that took days to implement & how did you do it.
- List of things/tools that make your life easier (as a dev).
- Read/Watched an interesting thing on internet (Your reaction, views, takeaways from it)

> **Tip** 🚩<br>
If you steal or copy something from internet, _try_ to cite the original source.

Your blog will eventually become Journal of things you learned and wanted to share with the world.

<!-- add devto #til tag -->

I hope you enjoyed or probably learned something. If you guys have any feedback or want to talk feel free to comment below 💚.<br>
You can reach me directly on [Twitter](https://twitter.com/bhupeshimself) | [Telegram](https://t.me/bhupeshimself) | [Email](mailto:varshneybhupesh@gmail.com?body=Hello Bhupesh,)