Code Optimization

Interesting things about software development and code optimization

The Kotlin Language Client server crashed 5 times in the last 3 minutes. The server will not be restarted.

Hello friends,


seems like you have faced the same issue like me ;)


What I can say is that I was not able to fully solve this issue but I solved it partially at least.

So if you see this error in the Visual Studio Code:

The Kotlin Language Client server crashed 5 times in the last 3 minutes. The server will not be restarted.

then you have Kotlin extension installed and while updating it you hit this issue.


To be able to work, build and debug my app i did the following:

- uninstall the Kotlin extension


yes - not just disable but uninstall it and now you can continue working with Flutter & Dart


please note, even you have Kotlin Language extension that is more similar to the error the real problem is in the Kotlin extension itself.


If I will find out further steps to resolve it completely I will update this post.


Thank you and see you soon! :)



1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y



Gmail G Suite as SMTP server for your website

Hello friends!


Its time to share so non obviouse case as using G Suite Gmail account and SMTP server to send emails from your website.

(it seems different than using private Gmail account)


Check restrictions and rules google uses for such sending emails scheme


First step and the most time consuming is to Enable less secure applications!

Go to the G Suite Admin > Security > Less secure apps 

and enable "Allow users to manage their access to less secure apps"

Pay attention - it really may take up to 24 hours before you see this "Less secure" option available 


While you are waiting you can do some other steps.

Go to the gmail account you are going to use and click on the top-right settings icon:



and select "Settings". Go to the POP/IMAP tab and enable POP and IMAP Access options.


Next step - add an SMTP Relay rule to allow your email accounts be accessible from outside:

G Suite Admin > Apps > G Suite > Gmail > Advanced Settings > SMTP relay service

Hover over this section and click the Add button. 

Add the following rule:



Wait some time until this option is available under the G Suite Gmail (email) account and turn it on:
https://myaccount.google.com/u/2/lesssecureapps?pageId=none


Final step - use the following mail configuration in your website:

  <system.net>
    <mailSettings>
      <smtp from="no-reply@mygsuitedomain.com">
        <network host="smtp-relay.gmail.com" port="587" enableSsl="true" userName="no-reply@mygsuitedomain.com" password="pppaaassswwwooorrrddd" />
</smtp> </mailSettings> </system.net>



That's it! Now you can send emails :)


Thank you and see you soon!


1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y



Dropbox and Drive C - Clean disk on Windows and Windows Server

Hello friends,


You are trying to free up a few GBs on drive C? You tried to clean WinSxS folder, you have tried Disk cleanup util and even the Dism.exe but still need a few GBs of free space? ;)


You got to the right place - your problem is Dropbox.

- Go to the Program Files (x86) > Dropbox folder
- Delete all Client XX.XX folders except the latest one


You will be amaized that it will free up to 2-4 GB of space! :)


Thank you and see you ;)


1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y



Split by comma but not inside of any parentheses or brackets

Hello friends,


If you are here then you in need of the same as me - split string by comma that is not inside of any brackets or parentheses.

So to do that you need the following piece of code (C# code):

string oval = "Home, Edit, HDMI (4K, ARC), Test, Double 2.0 x1, Multi (F1, (f2-f5, f6, 58), FF, o2), ARG";
string roval = "";
int isOpen = 0;
for (int i = 0i < oval.Lengthi++)
{
    if (isOpen <= 0 && oval[i] == ',')
    {
        roval += ",,";
    }
    else if (isOpen > 0 && (oval[i] == ')' || oval[i] == ']' || oval[i] == '}'))
    {
        isOpen--;
        roval += oval[i];
    }
    else if ((oval[i] == '(' || oval[i] == '[' || oval[i] == '{'))
    {
        isOpen++;
        roval += oval[i];
    }
    else
    {
        roval += oval[i];
    }
}

string[] split = roval.Split(",,"StringSplitOptions.RemoveEmptyEntries);


String you get to split looks like this: 

Home,, Edit,, HDMI (4K, ARC),, Test,, Double 2.0 x1,, Multi (F1, (f2-f5, f6, 58), FF, o2),, ARG

so you need just split it by double comma now.

This is fast, short and clear code that can be easily translated into any other language


Thank you and see you :)


1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y



AWS Windows Server - Restore RDP access blocked by Friewall

Hello friends,


today I'm going to share my experience on how we did restore RDP access blocked by Firewall after we blocked 3389 port by accident.

So first thing we tried was the standard steps suggested by AWS support, here they are:

1.Stop the instance i-xxyyzzaabb
Please note: it is recommended you take a snapshot or AMI of the instance prior to performing modifications for backup purposes.

I would note that if you have any data on any temporary drive attached to your instance then you will loose that data unless you will figure out how to backup it (I'm not sure if creating snapshot is backing them up but I guess - no)

2. Launch a temporary Windows EC2 Instance (20yy) in the same Availability Zone us-west-2a)






Be Sure to select exactly the same Availability Zone!



3. Detach the root volume vol-aabbccdd from the problem instance.


4. Attach the root volume to the new temporary instance (xvdf mapping is fine)
5. Login to the helper instance.
6. Download EC2Rescue on the temporary/helper instance from the following location: https://s3.amazonaws.com/ec2rescue/windows/EC2Rescue_latest.zip
7. Run EC2Rescue and select Next -> Offline Instance
8. Select the root volume vol-aabbccdd from the list of disks and select Next
9. Select Diagnose and Rescue which will provide suggestions to restore connectivity to the instance.
10. In the list of Detected Possible Issues, select all the checkboxes under windows firewall.
11. Select Next, then Rescue, and OK for the volume to be offline
12. Once EC2Rescue has completed, detach the volume from the temporary instance and re-attach the volume back to the original instance i-xxyyzzaabb as /dev/sda1. It is important to attach it back as /dev/sda1 .
13. Start the instance i-xxyyzzaabb and attempt to RDP


After two tries we were not able to get ride the Firewall and were not able to connect to Server via RDP.

So we decide to edit Register file of that problematic instance and yes we were right and managed to solve it.

Here are steps to do it:

1. Attach the volume to the temporary instance if not yet
2. Right-click the Windows toolbar button and open the Disk Management system tool



3. Find the offline disk (volume) and bring/make it online

4. Open RegEdit tool: Win+R > RegEdit > ENTER

5. Select HKEY_LOCAL_MACHINE node then File > Load Hive ...



6. go to Windows > System32 > Config  and find SYSTEM file on the new drive you just made online and available (the problematic instance drive)

7. in the prompt dialog gives it any user friendly name for example "RDP Lost Instance" or whatever you want

8. Under the name you set go to the node: 

      SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules

if you added rule and want to disable it like we did.