Saturday, December 14, 2024

SD Card Partitioning in Windows

The handy dandy tool for disk partitioning is Disk Management and it works like a charm for Hard Disks. But, when a similar thing is tried on SD cards, it becomes tricky. This is because it won't let you work on SD cards or flash disks. For that you need the low level tool named diskpart.

Follow the following steps for SD card (steps are same for External Drives as well):

  1. Open the command prompt in Administrator mode, type diskpart and press Enter (You may have to confirm UAC prompt).
    open diskpart


  2. Type list disk and press Enter (Take note of card's disk number).

  3. Type select disk <number> (<number> is disk number from previous command).

  4. Type clean and press Enter (This will overwrite partition table with zeros - all data will be lost).

  5. Type create partition primary and press Enter (This will create a partition.)

  6. Now if you go to Disk Partition utility, you will see a drive letter is assigned to the SD drive.

  7. Open Windows Explorer.

  8. Right click on the SD Card drive letter and select Format (you can select any suitable to you).

  9. After formatting the card, you are good to go.

Wednesday, February 9, 2022

How to install node using Brew

This article talks about some simple steps to follow to install node using Brew. Though there are many other ways to do it but the method described below uses nvm to install it and is one of the best method available till date.

Note: Before you proceed, ensure that Brew is installed. To install it follow the link above.

Step 1: Install NVM by running this command

brew install nvm

Step 2: Create a directory for NVM

mkdir ~/.nvm

Steps 3: Create an export in .zshrc to execute nvm command directly, add it to PATH and restart shell

export NVM_HOME="$HOME/.nvm"
    [ -s "$(brew --prefix)/opt/nvm/nvm.sh" ] && . "$(brew --prefix)/opt/nvm/nvm.sh" # This loads nvm
    [ -s "$(brew --prefix)/opt/nvm/etc/bash_completion.d/nvm" ] && . "$(brew --prefix)/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
export PATH=$NVM_HOME:$PATH

Step 4: Install node

Use this command for specific version

nvm install <version>

User this command to install the latest version

nvm install node

Step 5: Check the version of node installed

node -v
npm -v

Note: Whenever you install any version of node through nvm command it automatically makes it the default version.

Steps to change the version used by nvm

  1. List all versions which nvm has
    nvm list
  2. Change the version
    nvm use <version>

Thursday, December 2, 2021

Enable WiFi on a headless Raspberry Pi

Enabling WiFi on a headless Raspberry Pi is really simple. Here are the steps:
  1. Take out the SD card from Raspberry Pi and insert into a computer/laptop using a SD card reader in write mode.
  2. SD card will be named as "boot" on a drive on your computer.
  3. Open a text editor and create a file named "wpa_suppplicant.conf" on the root of "boot" or directly on the SD card.
  4. Add the below contents into the file and save it.
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="NETWORK-NAME"
    psk="NETWORK-PASSWORD"
}

Remember:

  • country should have a two character country code of your country.
  • ssid should be your Wifi Network Name in double quotes
  • psk should be the your Wifi Password in double quotes.
  • After saving the file check that the extension of the file is .conf and not .conf.txt. If so, then change it to .conf.
Now, eject the SD card and insert it in Raspberry Pi and it will automatically connect to the Wifi.


Thursday, October 21, 2021

How to enable SSH on Raspberry Pi in five super easy and quick steps

 Following are the easy steps to enable SSH on Raspberry PI without any complications:

Step 1: Shutdown Raspberry Pi

Step 2: Take out the memory card and plug it in any computer using the card reader.

Step 3: Open /boot partition of the card

Step 4: Create an empty file named "ssh" on the boot partition without any extension.

Step 5: Unmount memory card and insert into Raspberry Pi and start it.

That's it !!

To connect to the raspberry pi using SSH, just use this command

 ssh <user>@<IP address of Raspberry pi>

Saturday, August 21, 2021

How to enable Safemode for search engines on your home network using PiHole

If you are using Pi hole it is piece of cake to restrict any unsuitable content on your home network. In this blog, I will show how easy it is to restrict search engines search to Safe Content/Restricted Mode.

Following are the steps:

  • Open Pihole admin console on the browser by opening https://<IP>/admin/index.php.
  • Login into the console.
  • Go to Local DNS -> CNAME Records
  • Add server address for the search engine in Domain and its corresponding safe search server in Target Domain
  • Click on Add

  • You can see that the server and the corresponding safe search server is mapped in the list.
  • Similarly do for all the search engines you want to add.



Names of the search engine domains and their corresponding safe servers:

Google: 

Domain: www.google.com
Target Domain: forcesafesearch.google.com

Bing:

Domain: www.bing.com
Target Domain: strict.bing.com

DuckDuckGo:

Domain: www.duckduckgo.com
Target Domain: safe.duckduckgo.com

How to backup and restore Raspberry Pi MicroSD card on Mac and Windows

 

In order to take a backup following are the basic steps:

  1. Connect the Micro SD card.
  2. Create an Micro SD card image which will act as a backup image.
In order to restore a backup following are the basic steps:
  1. Connect the Micro SD card.
  2. Format the Micro SD card.
  3. Write the Micro SD card image on the Micro SD card.


On Windows


To take backup

  • Connect your Micro SD card

    • Ensure that your computer have an SD card slot.
    • Insert Micro SD card in the SD card adapter which comes with the Micro SD card.
    • Insert the SD card adapter in the SD card slot.
    • Check if Windows is able to detect the card. SD card will have a boot as name.

  • Install Win32 Disk Imager (One of best softwares to use for this purpose but feel free to use other software. Though the steps for other software will be similar.)


  • Open Win32 Disk Imager




  • Select the location for the file where back is required to be created and the file name by either selecting the folder icon (blue icon) or by typing the path. Ensure that the file name should end with .img.


  • Select the SD card from Device dropdown.



  • Click on "Read" button and relax as this is going to take some time to create the backup file.


To restore a backup

  • Connect SD card 


  • Format the SD card

  • Open Win32 Disk Imager


  • Select the file from which the backup is required to be restored.


  • Select the SD card from Device dropdown


  • Select Write and relax. This will take more time as compared to the time it took for backup.




On Mac


To take a backup

  • Connect the SD card. Note: the SD card will not be detected as a card to read the contents and you may see an error popup. Ignore the error popup.

  • Open the Terminal and run this command
$ diskutil list

This command will display all the connected storage devices

 


  • Identify the Name, Size and Volume of your SD card by looking at the output


  • Type this command to create a backup file for the SD card (ensure the file extension is .dmg)
$ sudo dd if=<Volume> of=<Location>/<filename>.dmg 
e.g. sudo dd if=/dev/disk1 of=~/Desktop/pi-backup.dmg


To restore a backup

  • Connect the SD card (Ensure that the card is a blank card or is pre-formatted)


  • List the disk volumes using the following command (refer output above)

$ diskutil list


  • Run the following command to restore the backup

$ sudo dd if=<Location of file>/<filename>.dmg of=<Volume>

e.g. sudo dd if=~/Desktop/pi-backup.dmg of=/dev/disk1


How to get rid of crazy "remote identification changed" error

 In your life if you ever used SSH to access a machine from two different computers or laptops then you might have encountered this error:

[user@hostname ~]$ ssh pi@bestpi.in.universe @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that a host key has just been changed. The fingerprint for the RSA key sent by the remote host is 5e:45:f9:a8:af:38:3d:b1:a5:c3:76:1d:02:f5:77:00. Please contact your system administrator. Add correct host key in /home/hostname /.ssh/known_hosts to get rid of this message. Offending RSA key in /var/lib/sss/pubconf/known_hosts:4 RSA host key for pong has changed and you have requested strict checking. Host key verification failed.


You might be wondering what in the world did you do wrong. Well....nothing actually. How to get rid of this error (and remove yourself from guilt), just use this command on the terminal:

ssh-keygen -R <host>

for e.g. ssh-keygen -R 192.168.0.19

 

 

Monday, April 27, 2020

Setting up Pi-Hole with OpenDNS (Stop Ads and Get Content Filtering) at home



Below is described how to setup pi-hole and OpenDNS at home. I used Raspberry Pi 3 for it and the below tutorial will describe all the steps pertaining to it only. Refer to the end of the blog for additional help.

Prerequisite:

  • Raspberry Pi (3 or above) with Raspbian installed and SSH ready. (Refer References section below for help with it. I will call Raspberry Pi as the pi machine henceforth).
  • A router supporting custom DHCP configuration (I am going to explain for Netgear Router).
  • Computer to SSH the pi machine (Mac or PC) (I used Mac in this tutorial. You can skip this and do it directly on the pi machine if you have set it up with keyboard and monitor).
  • Internet
  • Lots of spare time. (This is very important)

 Step1: Install pi-hole on Raspberry Pi

 * Before you begin, ensure that the pi machine is connected to the internet.

  • Open Terminal and SSH to the raspberry pi using the command below:

ssh user@pihostname.local
Replace user and pihostname with the user and hostname you have configured for your pi machine.

  • On the terminal, type the below commands to install pi-hole. 

          * Before you begin: 
    • Use all the default configurations as shown by the installer do not change it (We will change it later using the pi-hole console).
    • The installer will ask you to install a webserver to install the pi-hole console. This is an optional step but go ahead with installing it as we need this console later for changing settings of pi-hole.
    • Ensure that you do not have another web server on your pi machine. If you have it then the pi-hole console will not come up. So, it is better to stop the server before starting. 
    • After the installation note the following:
      • IPv4 address of the pi machine.
      • IPv6 address of the pi machine.
      • The password of the pi-hole console given.

git clone --depth 1 https://github.com/pi-hole/pi-hole.git Pi-hole
cd "Pi-hole/automated install/"
sudo bash basic-install.sh
For other ways to install pi-hole refer to this documentation: https://github.com/pi-hole/pi-hole/#alternative-install-methods

Step2: Configure the pi machine as the DHCP server on Router.

*Before you start, note:

  1. The configuration below is only for Netgear routers. For other routers, refer to the router manual.
  2. Ensure Parental Settings are turned off. (Don't worry as after OpenDNS configuration those will get auto applied)

  • Go to router admin settings. On Netgear routers, it can be opened in a browser by typing the following URL and entering the admin user password you used while setting up your router. If you did not configure the new admin password then it can be found on your router or in the user manual.
          http://routerlogin.net (Ensure that you are connected to your home wifi before opening the URL)
  • Change Domain Name Server (DNS) Address settings
    • Go to Advanced -> Setup -> Internet Setup
    • On the right pane, enter the IPv4 address of the pi machine you noted in Step 1 as Primary DNS after selecting the "Use These DNS Servers" option.
    • Apply the settings (This will restart the router)


  • Change IPv6 settings
    • After router is restarted, go to Advanced -> Advanced Setup -> IPv6
    • Select "Use DHCP Server"
    • Enter the IPv6 address of the pi machine in "Start Address" field
    • Select "Use These DNS Servers" option.
    • Enter the IPv6 address of the pi machine in "Primary DNS" fields.
    • Apply the settings (This will restart the router)



Step3: Open the pi-hole console and configure OpenDNS

          Pi-console will be shown as below:

  • Enter the password noted in Step 1 and go to Dashboard. The screen will look as shown below

  • Go to Settings -> DNS and do the following:
    • Uncheck any checkbox under settings "Upstream DNS Servers" on the left side.
    • Under "Upstream DNS Servers" on the right side check all the checkboxes and enter the following information:
      • Under Custom 1 (IPv4) enter: 208.67.222.123
      • Under Custom 2 (IPv4) enter: 208.67.220.123
    • After entering the information scroll to the bottom of the page and press the "SAVE" button.
  • After you save the information, the screen will look as shown below.


If you have done everything as described above then you are all set. This not only removes ads from all the apps (on phones) but from all the sites your surf. Plus, you get content filtering from OpenDNS (restricted access to porn, malware, unfriendly sites, etc).


References:

Saturday, September 3, 2016

Cohesion and Coupling and their types

Stumbled upon an article: http://www.infoworld.com/article/2949579/application-architecture/design-for-change-coupling-and-cohesion-in-object-oriented-systems.html

Following are the details from the article which are most important:

 

Coupling

Coupling may be defined as the degree of interdependence that exists between software modules and how closely they are connected to each other. In essence, coupling indicates the strength of interconnectedness between software modules. When this coupling is high, we may assume that the software modules are interdependent, i.e., they cannot function without the other. There are several dimensions of coupling:
  • Content coupling -- this is a type of coupling in which a particular module can access or modify the content of any other module. In essence, when a component passes parameters to control the activity of some other component, there is a control coupling amongst the two components.
  • Common coupling -- this is a type of coupling in which you have multiple modules having access to a shared global data
  • Stamp coupling -- this is a type of coupling in which data structure is used to pass information from one component in the system to another
  • Control coupling -- this is a type of coupling in which one module can change the flow of execution of another module
  • Data coupling -- in this type of coupling, two modules interact by exchanging or passing data as a parameter

Cohesion

Cohesion denotes the level of intra-dependency amongst the elements of a software module. In other words, Cohesion is a measure of the degree to which the responsibilities of a single module or a component form a meaningful unit. Cohesion is of the following types:
  • Co-incidental cohesion -- this is an unplanned random cohesion that might be a result of breaking a module into smaller modules.
  • Logical cohesion -- this is a type of cohesion in which multiple logically related functions or data elements are placed in the same component
  • Temporal cohesion -- this is a type of cohesion in which elements of a module are grouped in a manner in which they are processed at the same point of time. An example could be a component that is used to initialize a set of objects.
  • Procedural cohesion -- this is a type of cohesion in which the functions in a component are grouped in a way to enable them to be executed sequentially and make them procedurally cohesive
  • Communicational cohesion -- in this type of cohesion the elements of a module are logically grouped together in a way that they execute sequentially and they work on the same data
  • Sequential cohesion -- in this type of cohesion the elements of a module are grouped in such a manner that the output of one of them becomes the input of the next -- they all execute sequentially. In essence, if the output of one part of a component is the input of another, we say that the component has sequential cohesion.
  • Functional cohesion -- this is the best and the most preferred type of cohesion in which the degree of cohesion is the highest. In this type of cohesion, the elements of a module are functionally grouped into a logical unit and they work together as a logical unit -- this also promotes flexibility and reusability.

The best practices

Tight coupling increases the maintenance cost as it is difficult and changes to one component would affect all other components that are connected to it. So, code refactoring becomes difficult as you would need to refactor all other components in the connected-chain so that the functionality doesn't break. This process is cumbersome and takes a lot of tedious effort and time.

You should design classes that contain the less number of instance variables, i.e., your class design is "good" if it contains a small number of instance variables. Ideally, each of the methods in your class should manipulate one or more of these instance variables. Theoretically, a class is maximally cohesive if each of the instance variables of the class is used or manipulated by each of the methods of that class. When cohesion in class is high the methods and the data members of the class are co-dependent and work together as a single logical unit. However, in reality it isn't possible to design such classes or I would rather say, it is not advisable to design classes that are maximally cohesive.

Tuesday, December 31, 2013

Puzzle Time

Its amazing that in day to day life in office and discussion with colleges churn out some really interesting knowledge bits and these bits sometimes vibrate quite a bit of threads in your head. Here are some of those bits.
  
** River crossing: she-goat, wolf and cabbage 

Description:

A farmer is returning from market, where he bought a she-goat, a wolf and cabbage. On the way home he must cross a river. His boat is little, allowing him to take only one of the three things. He can’t keep the she-goat and the cabbage together (because the she-goat would eat it), nor the she-goat with the wolf (because the she-goat would be eaten). How shall the farmer get everything on the other side (without any harm)?

Solution:

farmer crosses with goat
farmer returns alone
farmer crosses with cabbage or wolf
farmer returns with goat
farmer crosses with whichever (cabbage or wolf) he didn’t take the first time
farmer returns alone
farmer crosses with goat
they are all on the other side

** Four glasses puzzle/ blind bartender's problem (
http://en.wikipedia.org/wiki/Four_glasses_puzzle)

Description: 

Four glasses or tumblers are placed on the corners of a square rotatable table. Some of the glasses are upright (up) and some upside-down (down). A blindfolded person is seated next to the rotatable table and is required to re-arrange the glasses so that they are all up or all down, either arrangement being acceptable, which will be signalled by the ringing of a bell.

The glasses may be re-arranged in turns subject to the following rules:
1. Any two glasses may be inspected in one turn and after feeling their orientation the person may reverse the orientation of either, neither or both glasses.
2. After each turn the table is rotated through a random angle.

The puzzle is to devise an algorithm which allows the blindfolded person to ensure that all glasses have the same orientation (either up or down) in a finite number of turns. The algorithm must be non-stochastic i.e. it must not depend on luck.
 

Solution:

An algorithm that guarantees the bell will ring in at most five turns is as follows:
  1. On the first turn choose a diagonally opposite pair of glasses and turn both glasses up.
  2. On the second turn choose two adjacent glasses. At least one will be up as a result of the previous step. If the other is down, turn it up as well. If the bell does not ring, then there are now three glasses up and one down.
  3. On the third turn choose a diagonally opposite pair of glasses. If one is down, turn it up and the bell will ring. If both are up, turn one down. There are now two glasses down, and they must be adjacent.
  4. On the fourth turn choose two adjacent glasses and reverse both. If both were in the same orientation then the bell will ring. Otherwise there are now two glasses down and they must be diagonally opposite.
  5. On the fifth turn choose a diagonally opposite pair of glasses and reverse both. The bell will ring.


Thursday, December 26, 2013

Enabling x86 Android Emulation


We all have experienced slow emulator on Mac, Linux and Windows (especially windows) because of which we use virtualization images of Android i.e. Genymotion, etc. So, if you are running your OS on Intel processor then you can use Intel HAXM (Hardware Acclerated Execution Manager) to speedup your emulator.

Following are the links which discuss as to how to implement HAXM:

For Windows and Linux: http://software.intel.com/en-us/articles/speeding-up-the-android-emulator-on-intel-architecture

For Mac: http://simonguest.com/2013/04/16/enabling-x86-android-emulation/

Sunday, November 17, 2013

Does Google Nexus 4 Orange Blinking Light creating lots of tension in your head ???

Hey guys...is Google Nexus 4 blinking orange light giving you jitters and cramps in your head and you have charged it for lots and lots of hours but it is still being the dumb ass and keep doing the same...well then here is the bumper for it to solve its idiotic nature. Here is the 3 steps procedure:

  • Step 1: Unplug it if you are still being positive and charging it.
  • Step 2: Press and hold Power button.
  • Step 3: Plug it by still keeping power button pressed and after 60 seconds leave the button, after 20 min or so you will see the white charging icon and its done...your phone is back from being a dumb ass.
Why this happens ?
There is no one answer but some blogs suggests which i believe is that there is a Deep Hibernation mode for battery in Nexus 4 which leads it to show this dumb behavior and this behavior is triggered if your phone battery goes off and you don't charge it for couple of hours. For me this happens if i leave it for more than 6-8 hours on a discharged battery.

I hope this helps someone who is feeling to suicide because of this behavior of his Nexus 4....but cheers and no need of that. Keep smiling.

Friday, November 8, 2013

Semantic Versioning

Semantic versioning is a simple versioning scheme suggested by OSGi Alliance where it conveys much more meaning about what’s changing than normal versioning schemes do.

Following are the key points:
  • Every version consists of four parts: major, minor, micro, and qualifier (Major.Minor.Micro.Qualifier).
  • A change to the major part of a version number (for example, changing 2.0.0.0 to 3.0.0.0) indicates that the code change isn’t backwards compatible. Removing a method or changing its argument types is an example of this kind of breaking change.
  • A change to the minor part (for e.g., changing 2.0.0.0 to 2.1.0.0) indicates a change that is backwards compatible for consumers of an API, but not for implementation providers. For example, the minor version should be incremented if a method is added to an interface in the API, because this will require changes to implementations.
  • If a change doesn’t affect the externals at all, it should be indicated by a change to the micro version (for e.g., changing 2.0.0.0 to 2.0.1.0). Such a change could be a bug fix, or a performance improvement, or even some internal changes that remove a private method from an API class. Having a strong division between bundle internals and bundle externals means the internals can be changed dramatically without anything other than the micro version of the bundle needing to change.
  • Finally, the qualifier is used to add extra information, such as a build date (for e.g. changing 2.0.0.0 to 2.0.0.110813, 110813 represents 08-Nov-2013) .

Among the version sections defined above, many of the product/component writers prefer Major, Minor and Micro and in some cases even Micro is left back and just add to your general knowledge Google does not follow any (WTH!!). So, its up to you as how you take it. For me, i love it.

Friday, November 1, 2013

JDK 8 Striking Features - Part 1

Finally, i got some good free time and thought to utilize it looking into the progress Java achieved. So, when looking into tutorial pages i saw a good thing to have in JDK 8.0 which will be launched soon and that is Aggregate Operations on Collections.

Here are the details:--

In JDK 8 a new and preferred method of iterating over a collection will be introduced and that is to obtain a stream and perform aggregate operations on it. Aggregate operations are often used in conjunction with lambda expressions to make programming more expressive, using less lines of code. The following code sequentially iterates through a collection of shapes and prints out the red objects:
myShapesCollection.stream()
.filter(e -> e.getColor() == Color.RED)
.forEach(e -> System.out.println(e.getName()));
Likewise, you could easily request a parallel stream, which might make sense if the collection is large enough and your computer has enough cores:
myShapesCollection.parallelStream()
.filter(e -> e.getColor() == Color.RED)
.forEach(e -> System.out.println(e.getName()));
There are many different ways to collect data with this API. For example, you might want to convert the elements of a Collection to String objects, then join them, separated by commas:
    String joined = elements.stream()
    .map(Object::toString)
    .collect(Collectors.joining(", "));
Or perhaps sum the salaries of all employees:
int total = employees.stream()
.collect(Collectors.summingInt(Employee::getSalary)));
These are but a few examples of what you can do with streams and aggregate operations. For more information and examples, you can go to Java Site

The Collections framework has always provided a number of so-called "bulk operations" as part of its API. These include methods that operate on entire collections, such as containsAll, addAll, removeAll, etc. Do not confuse those methods with the aggregate operations that were introduced in JDK 8. The key difference between the new aggregate operations and the existing bulk operations (containsAll, addAll, etc.) is that the old versions are all mutative, meaning that they all modify the underlying collection. In contrast, the new aggregate operations do not modify the underlying collection. When using the new aggregate operations and lambda expressions, you must take care to avoid mutation so as not to introduce problems in the future, should your code be run later from a parallel stream.

In my next post i will introduce Lambda Expressions in Java which is again a super striking feature to be introduced in JDK 8.

Friday, May 17, 2013

Hacking Google Glass



I was reading a blog to Hack Google Glass , below is the contents for it to accumulate the knowledge.

The entire process seems to take about 10-15 minutes, giving you warning messages along the way:


After you’ve run through all of that, bam, you get access to the entire data partition. You’re rooted and your device is worth nothing:



SD Card Partitioning in Windows

The handy dandy tool for disk partitioning is Disk Management  and it works like a charm for Hard Disks. But, when a similar thing is tried ...