Thursday, January 30, 2020

Bulb and Switch Puzzle

Statement: There is one bulb in a room with its door closed. There are 3 switches (A,B,C) outside. You can open the door only once. You have to figure out which switch belongs to the bulb.


Solution:
1) Turn on the first switch and keep it on for a few minutes.

2) Switch off the first switch and turn on second switch.

3) Immediately enter the room
      a) If bulb is on, second switch it is.
      b) If bulb is off and warm, then first switch.
      c) If bulb is off and cold, then third switch.

Saturday, December 21, 2019

Basic Unix commands of Frequent use


Following are some commands which you will use very often->

Suppose you are not able to deploy your ear successfully ,or your application is running very slowly; then most definitely you are short on space.

1) Use the following 2 commands to see the available space and memory->
$ df -h (Space)
$ free -m (Memory)

2) Check "class file" exists in which jar file.
$ find -name "*.jar" | xargs grep CitiNotesDataUtility.class

3) Find all instances of the specified process currently running.
$ ps -ef | grep processName
$ ps -ef | grep processName | grep java (java processes)

4) Kill Process : kill
$ kill -9 processId

5) List Directory Contents : ls
$ ls -a

6) Display Manual pages : man <command>
Linux has as extensive set of online documentation. They are referred to as manual pages.
$ man ls

7) Concatenate files: cat
$ cat file1 file2 > newFile

8) Current working directory
$ pwd

9) List all the current running processes
$ ps

10) Change Directory
$ cd /usr/bin
$ cd.. (go back)

11) Make Directory : mkdir
$ mkdir newDirName

12) Remove files and directories: rm
$ rm file.txt

$ rm dirName


Anti-Patterns in Software Development

Anti-patterns are certain patterns in software development that are considered bad programming practices.

Anti-patterns are the opposite of design patterns and are undesirable.

Some Anti-Patterns:

1) Bleeding Edge : Use cutting-edge(latest) technologies that are still untested or unstable leading
to cost overruns, under-performance or delayed delivery.

2) Cash Cow : A profitable legacy product that often leads to complacency about new products.

3) Micromanagement : Many times a team is rendered ineffective due to excessive observation,
supervision and hands-on involvement (lack of trust).

4) Mushroom management : Keeping employees in the dark and feed manure.

5) Seagull management : Management in which managers only interact with employees when a problem arises - they fly in, make a lot of noise, dump on everyone, do not solve the problem,
then fly out.

6) Smoke and Mirrors : Demonstrating unimplemented functions as if they were already implemented.

7) Brooks Law : Adding more resources to a project to increase velocity, when the project is already
slowed down by co-ordination overhead.

8) Big ball of mud: A system with no recognizable structure.

9) Interface bloat: Making an interface so powerful that it is extremely difficult to implement.

10) Database-as-IPC: Using a database as the message queue for routine inter-process communication where a much more lightweight mechanism would be suitable.

11) Circular dependency: Introducing unnecessary direct or indirect mutual dependencies between objects or software modules.

12) God object: Concentrating too many functions in a single part of the design (class).

13) Busy waiting: Consuming CPU while waiting for something to happen, usually by repeated checking instead of messaging.

14) Caching failure: Forgetting to clear a cache that holds a negative result (error) after the error condition has been corrected.

15) Cargo cult programming: Using patterns and methods without understanding why.

16) Hard code: Embedding assumptions about the environment of a system in its implementation.

17) Lava flow: Retaining undesirable (redundant or low-quality) code because removing it is too expensive or has unpredictable consequences.

18) Repeating yourself: Writing code which contains repetitive patterns and sub-strings (duplicate code); avoid with once and only once (abstraction principle)

19) Spaghetti code: Programs whose structure is barely understandable, especially because of
misuse of code structures.

20) Copy and paste programming: Copying (and modifying) existing code rather than creating generic solutions.

21) JAR hell: Over-utilization of multiple JAR files, usually causing versioning and location
problems because of misunderstanding of the Java class loading model.

Thursday, March 9, 2017

Erase everything - Database schema

If you wish to format your schema, then follow these steps->

1) Run the following query->

SELECT 'DROP '||object_type||' '|| object_name||  DECODE(object_type,'TABLE',' CASCADE CONSTRAINTS;',';') FROM user_objects ORDER BY object_id DESC;

2) Copy and paste the output from above query and execute it.

3) Execute this -> PURGE RECYCLEBIN;

Tuesday, December 27, 2016

Count no of String occurences in single pass

package com.prac;

import java.util.*;

public class CountStringOccurences 
{
public static void main(String[] args) {

String[] str = {"A","B","C","A","A","B","B","B","B","B","C","A","D","E","E","F","D","D"};

Map<String, Integer> hm = new HashMap<String, Integer>();

int cnt=1;

for(String ans : str)
{
if(hm.containsKey(ans))  //check if the key is already present
{
 cnt=hm.get(ans); // if present then fetch its count and increment it
 cnt++;
}
else
{
   cnt=1; //else set count to 1
}

     hm.put(ans, cnt);  // add the data in map
}


System.out.println("hm="+hm);
}
}


Output:
hm={D=3, E=2, F=1, A=4, B=6, C=2}
Home