Thursday, April 23, 2020

Thou shall pay thy taxes

Hi, recently(writing on 24th April 2020) government introduced some new tax schema called Advanced Personal Income Tax (APIT). Don't ask me what it is, I also have no idea.
But one thing I know is we have to pay that.
Paying taxes is not a bad thing, country needs money too, not just you.

Image soure
So I'm sharing my journey of becoming a good tax payer of Sri Lanka. Hope this would help you too.
Following are the steps I followed, I also have a lot of questions in my mind. Let's see what we can figure out.

The first step would be to create an account. You may already have given consent to your employee to pay PAYEE and APIT taxes on behalf of you, but still you need an account.
Annually you can submit a tax return and if you are lucky you can get a refund 🤗

Create a new account if you don't have one


  • Go to this link.
  • Then from that drop of Registration type select INDIVIDUAL LOCAL
  • You'll get a huge form to fill. Fill it carefully.
  • You will be requested to upload an image of your NIC
  • For the field of Purpose of registration what I select was TAX PURPOSE
  • Once you submit you will be navigated to the the confirmation page
  • Check all the details again.
  • Fill the declaration and submit.

They say they will mail a notification within 5 days( previously I selected email as my preferred communication medium, save paper -> save trees 🌲 )

That's it for now folks. Happy paying taxes :)

PS: I am making this a living document, I will update more info when I receive the confirmation and other data.I am not a financial person, so everything will be on laymen's terms and this is an alien subject for me, therefore please correct me if something is wrong

Wednesday, February 19, 2020

How to delete a conflicting document in CouchDB 1.6.1

Retrieve the list of conflicting revisions

User the following curl to retrieve the list of conflicting revisions

curl -u userName:password http://<IP>:5984/<DB_NAME>/<DOC_NAME>\?conflicts\=true

The output would be something like following

{"_id":"my_doc","_rev":"10007-41ad08f6c152a9da8458bc5b1a7d86a7", "documentObject":{"index":{...........}),"_conflicts":["10003-d109ea0ea25918a83bbde4de6753f173","10001-1b618568334a43b2f61fc2f710efaac8","9992-
..........
6433482dd8f753c41d67949c1d11b296","563-5cc0de9756e78a004b68c054260c60a8","277-0e5c2632c940a6973b21ff0ef7c32f6a"]}

Then copy the conflicting revisions to an array to and enter it to the terminal

array="10003-d109ea0ea25918a83bbde4de6753f173","10001-1b618568334a43b2f61fc2f710efaac8","9992-
..........
6433482dd8f753c41d67949c1d11b296","563-5cc0de9756e78a004b68c054260c60a8","277-0e5c2632c940a6973b21ff0ef7c32f6a"

Delete the corresponding revisions

Write the script to execute the delete call

for i in $(echo $array | sed "s/,/ /g")
do
    curl -u userName:password -X DELETE http://<IP>:<DB_NAME>/<DOC_NAME>\?rev\=$i
done

You will see output like follows

{"ok":true,"id":"settings","rev":"10004-73a7da6d7551759cbecbd4a14bfbe213"}
{"ok":true,"id":"settings","rev":"10002-df955439c468e65aab946be7db63be80"}
{"ok":true,"id":"settings","rev":"9993-8966c9010602c8a053cb734792ff0f00"}
{"ok":true,"id":"settings","rev":"9992-5c8032bc4d2798fbade3324335f1f393"}

{"ok":true,"id":"settings","rev":"9973-d5b8a7a15fbe3197e09e71b42c82d14f"}
.....

Sunday, December 29, 2019

Free up disk space on Mac

Have you ever run out to disk space in your mac? You might need to figure out which files and folders eat most of your disc space.

Option 1: Finding the largest Files
One option is to open the Finder and search the files using 'This Mac' and sort the files by size.


Option 2: Finding the largest Folders
Open the terminal and go to your user folder by typing 'cd ~/' then enter the following command. It will list the largest folders in the sorting order. It may take a while to list. Don't worry about the warning messages.

du -a * | sort -r -n | head -10

Then you can proceed to delete the unnecessary folders

One of the culprits of eating disk space is the XCode app and its related files


Friday, December 27, 2019

Software Security Summary


Image result for software security

the goal of software security is to maintain the confidentiality, integrity, and availability of information resources in order to enable successful business operations. This goal is accomplished through the implementation of security controls.

Risk is a combination of factors that threaten the success of the business. This can be described conceptually as follows: a threat agent interacts with a system, which may have a vulnerability that can be exploited in order to cause an impact.

Eg: a car burglar (threat agent) goes through a parking lot checking cars (the system) for unlocked doors (the vulnerability) and when they find one, they open the door (the exploit) and take whatever is inside (the impact).

A dev team: Approaches the system based on the intended functionalities
An attacker: What operations can be done on the system(nothing avoided is possible)

security holes can be introduced in

  1. Requirement gaps
  2. System logic error
  3. Poor coding practices
  4. Improper deployments
  5. Security holes introduced during maintenance and updating phases
Reference: https://www.owasp.org/images/0/08/OWASP_SCP_Quick_Reference_Guide_v2.pdf


Thursday, December 12, 2019

Threads Vs Processes


You might come across situations where you need to decide whether to use a thread or a process to achieve a certain task. Here I am sharing my experience on selecting what's best depending on your requirements

First, let's what is a process?
  • A process is an executing instance of an application/program
  • Process control block holds information about the process.
  • Process priority, process id, process state, CPU register, program counter, stack pointer, the status of opened files, scheduling algorithms, etc. 
  • A process can create other processes which are known as Child Processes.
  • The process takes more time to terminate and it is isolated means it does not share the memory with any other process.

Then what is a thread?
  • A thread is a path of execution within a process. 
  • A process can contain multiple threads
  • A thread takes less time to terminate as compared to a process
Let's see how does a process work
  • Process creation using fork system call
    • fork() creates a replica of the parent process 
    • Page Table and Kernal Stack are duplicated, new PCB is created
    • Child process state is set to NEW -> READY
    • Process is moved to the ready queue of the Kernal
    • Copy On Write (COW) is used by the child process
  • The first process of Unix system is known as the Super parent.
    • Location: /sbin/init
    • Created by the kernel during boot
    • Typically starts several scripts present in /etc/init.d
  • Process termination
    • Voluntary termination: exit(0)
    • Involuntary termination: kill(pid, signal) 
    • Pid: process Id
    • Signal: asynchronous message send by the OS/another process (eg: SIGTERM, SIGQUIT)
  • Process communication(IPC)
    • Shared memory: shmget, shmat, shmdt 
    • Message passing:
    • Shared memory is created in kernel
    • Slow
    • Pipes
    • Signals
How does a thread work?
  • Threads are very inexpensive to create and destroy, and they are inexpensive to represent
  • When a new thread is created it shares its code section, data section and operating system resources like open files with other threads.
  • But it allocates its own stack, register set and a program counter.
  • With so little context, it is much faster to switch between threads
  • Creating a thread, switching between threads and synchronization between threads can all be done without the intervention of the kernel

Processes are good when you have a task, where the task

  • Has sufficient work to do for a long period of time continuously
  • Does not require much communication between tasks
  • Has less context switching
  • Can independently work from other tasks
  • Does not require to be controlled

Threads are good when you have a task, where the task

  • Has less heavy work to do
  • Has a small life span
  • Requires communication between other tasks
  • Requires context switching
  • Depends on other tasks
  • Requires synchronization
  • Depends on shared data/resources
  • Requires control and coordination

You may consider the following factors when selecting between threads and processes

  • Type of work (IO-bound, computation, etc.)
  • Lifetime (Short vs Long)
  • Scheduling
  • Resource Sharing
  • Data Sharing
  • Communication
  • Thread/Process security and safety
  • Control and Synchronization
  • Environment and technology stack

Tuesday, November 11, 2014

Coding Good Practices : Constants

We'll discuss a good practice in coding which is using Constants.

A constant in Java is used to map an exact and unchanging value to a unique variable name.

Those constants make the code a bit more robust and more human readable. As those constant values can be used in multiple places, it gives you a single point to change the value of the constant if requires.

(public/private) static final TYPE NAME = VALUE;

Where TYPE is the type, NAME is the name in all caps with underscores for spaces, and VALUE is the constant value;
Lets see an example

public final class Consts  {
      public static final int SECONDS_IN_HOUR = 60 * 60 // sure, this will never change, but it will make the code where you use it a lot more readable
      public static final String DEFAULT_USERNAME = "Fernando" // this can be used in several places
      public static final double AVOGADROS_NUMBER   = 6.02214199e23;

      private Consts  () {
      // a private constructor prevents from instantiating the class
      }
}

The static Keyword
The static keyword makes that variable to the class instead of a specific instance (Object).

The final Keyword
When we declare a variable to be final we are telling Java that we will NOT allow the variable’s “pointer” to the value to be changed. In other words the final keyword means that once the value has been assigned, it cannot be re-assigned. So if we tried to put in some code later that tries to change a a final variable we would get a compilation error.

The naming convention
A constant is defined by an UPPER_CASE_LETTERS_WITH_UNDERSCORES_INDICATING_SPACES.
Again, it’s not mandatory to use upper case letters with underscores to indicate spaces, but it’s a convention that programmers use and are familiar with in Java.

private vs public Constants
If a constant is private no other classes can see or use that constant. You may use private constants if those constants are only used in that class. Public constants can be used over multiple classes. It is recommended and practiced to keep the constants in a separate class.

Bad practices
It is bad practice to replace every literal by a constant. For example
private static final int SMALLEST_POSSIBLE_INCREMENTOR = 1 // don't do this; please!
private static final int FIVE = 5 // oh please please don't do this

SO happy coding folks..