The recursive main()

I didn’t think that way, but it turns out that main() function can be used recursively in C. So, for instance, the given code is completely valid and runs on any GCC compiler.

#include
int a = 10;
main()
{
while(a)
{   
    a–;
    printf(“%d\n”,a);
    main();  // Here it is
}
}
I don’t know how useful this maybe, but it can be handy for some real nice MCQs related to code obfuscation.  
Advertisements

Add linux like shortcuts to Windows Run

After using Linux for a while, it’s difficult to transition back to windows. One big reason is the absence of command line shortcuts for all programs.

While Linux (Ubuntu in my case) adds a path to all new applications installed from the terminal via sudo apt-get install, Windows doesn’t do it for every program.

You have two options-

1. Add the path of that program manually to the PATH variable of your Environment Variables settings.
Goto Computer->Properties->Advanced System Settings->Advanced->Environment Variables->Path for your Username. You can edit that to add the directory where your program is installed.

2. You can create a shortcut for that program and copy that in any existing folder with a path in the Windows Environment Variables (for e.g. System32).

I found the second one to be easier, since copy+paste is much easier for me.

Using regex to split Java string for multiple whitespaces

Let’s say you have a string –

String s = “Must     have  some         room.”

As you see, the whitespaces are not constant.

We can split this up using a regex string:

String delim = “\\s{1,}”;
String[] arr = s.split(delim);
for (int i=0;i<arr.length;i++)
System.out.println(arr[i]);

Where “\\s” is regex for whitespace, and adding “{1,}” tells that it can range from 1 to any greater value.
Thus all splits are taken care of.

Github down? Fixed.

Past few days, my internet was sort of down (ping was 2600ms!!!). Today, while it got fixed, I found out that I couldn’t access Github.
A simple fix did the trick. What I did was just changed my DNS servers to Google’s DNS servers, and everything was back to normal again.

Steps (on linux)-

1. Open a terminal & type –

sudo gedit /etc/resolvconf/resolv.conf.d/head  

I use gedit. You can replace it with the editor of your choice. For example, a nano user may write –
sudo nano /etc/resolvconf/resolv.conf.d/head

2. put your nameserver list in –

nameserver 8.8.8.8
nameserver 8.8.4.4

3. Then run-

resolvconf -u

4. Try github.com and confirm if it works.

There is a similar setup in Windows.

1. Just goto Network Places

2. Change Adapter Settings (left sidebar)

3. select your Internet network and right click and select Properties

4. select IPv4 and click Properties

5. Change the fields for DNS server #1 and #2 to “8.8.8.8” and “8.8.4.4” respectively.

I am not sure if it is region related or ISP (MTNL in my case), but changing your DNS to Google’s is anyway a good option.

Make an ISO backup of your Linux distro

Me and Linux have had an on & off relationship for quite a while. Like all penniless people, my broadband bandwidth is small, and thus, updating the distro becomes a pain.

Luckily, I found this –

https://github.com/Distroshare/distroshare-ubuntu-imager

What’s that?

Simply put, its a bash script to copy your current Linux installation into an iso. While that may sound boring, believe me, it’s a godsend. Just run the script after you are satisfied with your current Ubuntu installation (that includes all recent updates, third party apps and settings).

Why?

– No more updates after each new fresh install. Update your distro and save it as an iso and save the time later on.

– Have a ready .iso backup. That’s useful if you wish to make a bootable pen drive or install in a virtual machine.

Steps-

1. Download the ‘.sh’ and ‘.config’ files.

2. Mark the .sh as executable (Properties->Permissions->Execute check)

3. Run the .sh script in root (sudo).

Congratulations! You just saved yourself a shit-ton of configuration and after-installation hassles in the future.