Pages

Friday, October 25, 2019

Encode or decode date in 3 characters

I have developed a new way to encode/decode dates within 3 characters by using base-36 format.

What is a base 36 format?
Base 36 or hexatridecimal is a positional numeral system using 36 as the radix. The choice of 36 is convenient in that the digits can be represented using the Arabic numerals 0-9 and the Latin letters A-Z.

In simple language, base-36 format refers to series of 0-9 followed by A-Z characters, i.e., 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ; where each character refers to the position index in series.

The concept can also be represents as shown in the below table

Series
Character
Series
Character
Series
Character
Series
Character
0
0
10
A
20
K
30
U
1
1
11
B
21
L
31
V
2
2
12
C
22
M
32
W
3
3
13
D
23
N
33
X
4
4
14
E
24
O
34
Y
5
5
15
F
25
P
35
Z
6
6
16
G
26
Q


7
7
17
H
27
R


8
8
18
I
28
S


9
9
19
J
29
T



e.g., 12 → C, 19 → J, 34 → Y

Now here is a way to use the same logic for date, so to do that let us take a date and encode it as

25-Oct-2019 → 25-10-2019 → 25.10.19 → P.A.J → paj

Similarly, decode it back as

paj → P.A.J → 25.10.19 → 2019-10-25 → 25-Oct-2019

Note, here P.A.J is converted to lowercase as paj to make it more compact.


Friday, October 18, 2019

How to create mirrored repositories and keep it synced?


To mirror the existing git repository (i.e, src-repo) into another git repository (i.e., dest-repo), follow the steps given below:
  1. Create a bash file and name it as mirror-sync-repo.sh
  2. Copy the below code and paste it in your bash file

  3. #!/usr/bin/bash
    SourceRepositoryURL=http://src-repo.gitserver1.domain
    DestinationRepositoryURL=http://dest-repo.gitserver2.domain
    SourceRepositoryDir=src-repo.git
    if [ ! -d $SourceRepositoryDir ] 
    then
    	git clone --mirror $SourceRepositoryURL
    	cd $SourceRepositoryDir
    	git remote add --mirror=fetch secondary $DestinationRepositoryURL
    	cd ..
    fi
    cd $SourceRepositoryDir
    git fetch origin
    git push secondary --all
    

  4. Modify the code by replacing pseudocode with the actual repository names and links
  5. Save the bash file
  6. Open the Terminal app and go to that folder where this bash file is present
  7. Execute the bash file on Terminal using sh mirror-sync-repo.sh command, you'll be asked to enter the username and password for both the repositories; just enter that and let it proceed
  8. One the execution is finished, both the repositories are mirrored and synced

Monday, September 16, 2019

How to located the installed & cache directory path for Deno?


Recently, I had installed the Deno v0.18.0 using brew on macOS. Then tried couple of samples given there. I was amazed to see, how closely it behaves like Golang. When we run the script for the first time, Deno downloads all the dependencies provided in the import statement that is required to run the script. When I ran the same script next time then it doesn't download any dependency. So that means it caches all those dependencies and uses the same next time.

Now I was eager to see the cache, but can't find it at the usual locations but after some time with the help of Google, I was able to find the correct location. So I thought it would be pretty useful to put it in blog for ready reckoner.

So here is the sample path on all major platforms

Platform / Location
Binary
Cache
Windows
C:\Users\me\AppData\Roaming\deno\
C:\Users\me\AppData\Local\deno\
macOS
/Users/me/.local/bin/
/Users/me/Library/Caches/deno/
Linux
/home/me/.local/bin/
/home/me/.cache/deno/

Here is the same path using the bat / bash syntax

Platform / Location
Binary
Cache
Windows
%appdata%\deno\
%localappdata%\deno\
macOS
$HOME/.local/bin/
$HOME/Library/Caches/deno/
Linux
$HOME/.local/bin/
${XDG_CACHE_HOME-$HOME/.cache}/deno/

That's it!

Wednesday, September 4, 2019

Protect your Android app from reverse engineering & plagiarism

Few years back, we faced a hard technical problem while working in IoT project. We were having a mobile app to control smart electronic appliances that consumes our web-service. A third party somehow managed to use our mobile app with their service. We assume that they had reverse engineered to crack the services. So we had to protect our mobile app which was cordova based cross platform app

I have been allocated to analyse this issue and propose a solution. So during my initial analysis I found that first we should secure the mobile application installer because Android's .apk installation file usually packaged together all the resource files used in the hybrid project. Crackers could reverse engineer it to get those files. I know that we can ensure protection only by increasing the level of security.

So I minified all the files, bundled together and applied obfuscation over it; which made hybrid portion bit more secure. After this I used Arxan to protect the mobile app at binary level.

The next step was to ensure the service authenticity; for which I'd used session based synchronous incremental token validation system on app level and get it implemented on a web-service layer to support it.

The outcome was that our app become much more secure & protected. It took few releases till all the users updated the app. Now the third party has stopped supporting our app as we don't see any cross origin requests in our logs.

From this incident we learned that usually we think that the project is at startup level, so they don't worry much about security and protection of the project initially. But with time project grows, it becomes more vulnerable. So we should always keep in mind the basic things like security; during the startup phases.

Now I use this app protection technique in all other enterprise level apps and try to get it implemented during the startup phase.

Friday, August 30, 2019

Remotely accessing macOS through Windows using VNC

Open System Preferences on your macOS.

Go to Sharing section, mark Screen Sharing and Remote Login as checked.



Click on Computer Settings... button.

Mark VNC viewers may control screen with password: as checked.

Fill in your unique password in the input box and click on OK button to save it.



Now note down the URL to access this system which is actually an internet IP.

Later on whenever you connect the device to internet, you can find it or lookup from your WiFi router's admin portal.

Open the https://www.tightvnc.com/download.php on your Windows.

Download the relevant installer based on 64-bit / 32-bit processor.



Install it on your Windows system in Typical settings. You may refer this short video tutorial for this.



Open TightVNC Viewer app, enter just IP of the VNC URL of macOS to access the system.


Now click on Connect button to start accessing remote system via screen-sharing.

Finally, you just need to make sure that both the systems are over same LAN otherwise their IP's can be universally accessible.


Tuesday, April 23, 2019

GitHub repository workflow using gitflow mechanism

This workflow will describe all the necessary steps that you need to follow to release a project.

It is targeted for those projects where more than one members are contributing in the project because that will require a standard workflow that will keep the quality in check at each level.

So try to follow the steps as mentioned below, where a repository have been taken for sample.
  1. First you need to setup the codebase on your local machine
    1. Create a clone of the repository
      • git clone "project-repository-git-url"
    2. Get inside the repository folder
      • cd "project-repository-path"
    3. Refer this article https://gist.github.com/ribbon-abku/10d3fc1cff5c35a2df401196678e258a to learn more about the gitflow mechanism of handling a project
    4. Enable git flow mechanism on the current repository
      • git flow init -d
      • It is required to be done by each contributor on their respective clones
    5. Check out develop branch
      • git checkout develop
    6. Copy & paste all the code in this folder from previous repo
    7. Update .gitignore file by adding file/folder name that you don't want to add in repo
    8. Stage all the relevant & required files
      • git add .
    9. Commit the code with relevant message
      • git commit -m "your-commit-message"
    10. If you add issue number in you commit message like #1 Added initial codebase, then the commit would reflect under issue from which it is associated 
      • git commit -m "#issue-number your-commit-message"
    11. Push the committed code
      • git push
  2. Once you have made a stable code base in develop branch then raise pull request to merge it in master branch.
  3. When your pull request will get approved, then either you or approver can merge the pull request to the master branch.
  4. Using gitflow you need to create release branch as
    • git flow release start release-1.0.0
    • Test this code base to make sure everything is stable and releasable
    • git flow release finish 'release-1.0.0'
  5. Then, go to releases section of the repository
  6. Create new release
    1. Mention Tag version, e.g., v1.0.0
    2. Choose the Target branch as release-1.0.0
    3. Mention the Release title as Release v1.0.0
    4. Add the release notes in the Describe section that should contain all the relevant text in points like
      1. New features added
      2. Bugs fixed
      3. Limitations if any
    5. Attach the binary files like installer exe, apk, app, etc.
    6. Click on Publish release button to make it release it publicly

Note: Although I have mentioned all the steps using command line but I'll recommend you to use Sourcetree app instead because it will provide a lot of ease while following the workflow.

Sunday, January 20, 2019

Aryabhatta didn't invented zero but propagated

A frustrated student asked his Maths teacher, "if Zero was invented by Aryabhatt and he was born in the Kalyug, then in the past in Satyug, who counted 100 Kauravas and Ravana's 10 heads and how?"

Teacher resigned and went back to Vedic education but is still not able to find the answer.

Joke apart but the point needs to noted.

P.S. Got the above message as joke but any reply for that?

An expert's answer:

Let me start with just 1 reference from Vedas and 1 from Puranas (to keep this answer short - we will not have enough space if we want to document all such references).

1. Vedic Reference (Yajur veda)

The Rishi Medhātithi, after preparing bricks for a Vedic ritual, prays to the Lord of fire, Agni.

Imā me Agna istakā dhenava Santvekā ća desa ća satam ća
Sahasram ćāyutam ća niyutam ća Prayutam ćārbudam ća nyarbudam ća
Samudrasća madhyam ćāntasća Parārdhasćaita me agna ishtakā
Dhenavasantvamutrāmushmimlloke .

The mantra recited is in vogue for srivaikhanasa Archakas in Agniprathishta till now, "Ima me agna ishtaka"

Meaning:

Oh Agni! Let these bricks be milk giving cows to me. Please give me one and ten and hundred and thousand. Ten thousand and lakh and ten lakh and One crore and ten crore and hundred crore, A thousand crore and one lakh crore in this world and other worlds too.

For starters, here is the meaning of some of the key words in that sloka:

Sanskrit
Number Figure
Power Notation
Hindi
English
eka
1
100
Ek
One
dasa
10
101
Das
Ten
satam
100
102
Saw
Hundred
sahasram
1000
103
Hazar
Thousand
ayutam
10000
104
Das Hazar
Ten thousand
niyutam
100000
105
Lakh
Hundred thousand
prayutam
1000000
106
Das Lakh
Million
arbudam
10000000
107
Crore
Ten million
nyarbudam
100000000
108
Das Crore
Hundred million
samudram
1000000000
109
Arab
Billion
madhyam
10000000000
1010
Das Arab
Ten billion
antam
100000000000
1011
Kharab
Hundred billion
parardham
1000000000000
1012
Das Kharab
Trillion

2. Reference from Bhagavata Purana

Chapter 3.11 of Srimad Bhagavatam explains the concept of time. It starts from what is now called nano seconds and goes up to trillions of years.

I have just given couple of references (which is just the tip of iceberg). If we read with an open mind we can find many more such references. This clearly shows that ancient Indians knew a lot of mathematics, counting, decimal systems etc. Why are we getting such "Intelligent" questions, when the truth is actually the opposite?
  1. This question arises due to our ignorance. One of the biggest atrocity done by Britishers to India was to eradicate the Guru-Sishya tradition of educating our ancient knowledge and values. We are repeatedly fed nonsense after nonsense about our past, to the extent that we all either feel ashamed to talk about it. Even those who talk, do so with a sense of guilt.
  2. We also blindly vomit (reproduce) the Macaulay based education system that Britishers left us with. One of such nonsense is that Aryabhatta "invented" zero. This is an ambiguous statement, which doesn't give the right perspective to Aryabhatta's contribution. Another such nonsense is that there is Classical Sanskrit (whose grammar was codified by Panini) and then there is Vedic Sanskrit, which is somehow a different language. Absolute nonsense - Panini composed a treatise summarizing the Sanskrit grammar from days of yore - till his time. This doesn't mean that the language itself didn't exist or it existed as a different language.
  3. We also have a screwed up version of "Secularism" and it has become a fad among our generation to post such questions and jokes, which makes us look "cool" (in reality it does make us look stupid).

Summary

Rather than saying that Aryabhatta "Invented zero", I would say that he was the first person to formally define the place value system using Zero. He also elaborated on its mathematical usage. The alternative available was Roman numerals, which is not scalable (to the levels that our Vedas went). Why we refer Aryabhatta and not our Vedic and Puranic texts: Aryabhatta's work was intended to be a Mathematical treatise. His work summarizes the knowledge that was available with us until that time. Our Puranas and Itihasas on other hand, though had several references to larger and smaller numbers, were not Mathematical texts - Maths in them were incidental.

I feel we really have to get our history corrected to become proud of our heritage & culture.