Tag Archives: application

Rant : Covid-19 vs Me(The software developer)

Long time, no See folks!

Writing after a long time, a discussion with @SoftwareGod, triggered this blog post!

(I am in self induced inertia!)

So the discussion was about we(s/w devs) contributing to the drug discovery hackathon for Covid-19.

Why I choose not to join:

1/Hackathon is open sourced, everything else is IPR‘ed.

2/No “Getting started with biological virus” guide I could find?

3/What are our R&D scientists doing in virus labs?

4/IMO, get a super computer in place for running simulations, although the mobiles and laptops are a lot powerful today, I am sure super computers run on petaBytes/milliseconds speeds!

So, that done, I recalled, hey! I had once developed an anti-virus programme, in Visual Basic(I had super-less love for M$ at that time).

Going back in that time….

I was forced to learn VB, and I was making faces inside of me, like why??

Coincidentally during that time, my system was hit by HTML RedLof.A virus, it was the era of floppy exchanges, usb drives were not so common.

So, this novel idea sprung up in me, why not cure poison with poison (Hu Ha Ha Ha…. Hu Ha Ha Ha….) 😀

So my next task was writing a cure for the virus(not vaccine) in my least liked languages M$ VB.

Looking back, this was the algo, which may/maynot be mapped to biological virus.

1/The first thing, I noticed in my system was , the free hard disc space started reducing.

{identify unique or distinguishing symptoms}

2/I could not understand the reason first why. but on closer analysis, I saw my recently modified files being htm,html where the size increased by a fixed amount.

{check inflammatory markers, or the first response body gives when attacked by virus}

3/On opening those files, at the end of the source code, I saw alien code of the virus and its replication.

{Once infected area found, extract and analyze; this is very domain specific}

4/The virus was replicating and affecting html,htm files, other infected extensions were: jsp and vbs.

{understand how virus entered the system, stop that first}

So most probably an infected html or vbs file kept in an already-infected floppy, affected my system.

5/Now that the pattern was identified, I simply wrote VB program, to

a)Scan whole computer for defined extensions files

{in covid-19: various proteins}

b)For each such file, reg-ex the starting of the alien code and end

{find a way to delink the alien protein}

c)Delete that piece of the code

{Kill Kill Kill}

d)Save the file.

{replenish that part, shower with newer safe proteins}

I confirmed the same via anti-virus programmes as:

1/Ran the 3rd party anti-virus : Infection NOT found

2/Infected my system with the virus

3/Ran the 3rd party anti-virus : Infection found

4/Executed my VB program

5/Ran the 3rd party anti-virus : Infection NOT found

This ways my system got rid of the virus completely.

Coming back to biological viruses, I think we can take help from Symantec,F-Secure and such “anti-virus” software making companies, because they have studied so much more patterns of viruses, and that can be employed to faster Drug Discovery!

Thanks for reading! 🙂

Things everyone should know about responsive images and srcset

The aim of responsive images is to deliver the same image in mobile and desktop view without disturbing the viewport size that is the image should look alike in every device .

Therefore this problem of responsive images can be solved by using srcset attribute in image tag or using media queries.

Both are suitable to deal with this situation but prefer to use srcset instead of media queries because media queries will take time to write but srcset does the same thing in small time and space .
The information below will explain all about srcset .

srcset
The srcset attribute is listing different resolutions of the same image from which the browser chooses the best fitting image source before loading it.
Example: srcset="ninja-1000w.jpg 1000w, ninja-500w.jpg 500w, ..."
To calculate this, the browser assumes the image fills up the full viewport width (100vw) by default, which means it uses the full width of the browser.

In short, Srcset is a new attribute which allows you to specify different kind of images for different screen-sizes/orientation/display-types.
The usage is really simple, you just provide a lot of different images separating them with a comma like this:

<img src="image.jpg" alt="image" srcset="<img> <descriptor>, ..., <img_n> <descriptor_n>">.

Here is an example:

srcset="image.jpg 160w, image2.jpg 320w, image3.jpg 2x"

Descriptors are just a way to show what kind of image is coming from the resource. There are various kinds of descriptors:

  1. density descriptor–> srcset=”image.jpg, image-2X.jpg 2x” The display density values—the 1x, 2x, etc. are referred to as display density descriptors. If a display density descriptor isn’t provided, it is assumed to be 1x.
  2. width descriptor –> srcset=”image-240.jpg 240w, image-640.jpg 640w”.
    When using the w-descriptor we have to specify the default explicitly by adding a second srcset image option, with its own w-descriptor, and separating them with a comma.
  3. size descriptor–> It only makes sense if you use width descriptor.
    srcset=”image-160.jpg 160w, image-320.jpg 320w, image-640.jpg 640w, image-1280.jpg 1280w” sizes=”(max-width: 480px) 100vw, (max-width: 900px) 33vw, 254px”>.
    The instructions for the browser would look like this: (max-width: 480px) 100vw — if the viewport is 480 pixels wide or smaller, the image will be 100% of the viewport width.So it is like using media queries in html which looks a lot easier as compared to media queries written in css .

Pros–>
1.much easier than media query
2.saves time

Cons–>
1.Browser should be updated to see the effect
2.Not all browsers support this.
At present, Edge, Safari, and iOS Safari only support a subset of the srcset specification. Firefox, Chrome, Opera, Android Browser, and the forthcoming versions of Safari and iOS Safari fully support it.

Demo can be seen on my github link

pershantgoel.github.io/imgsrcset

Test Driven Development with SpringBoot+Junit

 

Test-driven development(TDD) in the Spring framework.

TDD  helps me speed up my software release cycles, and ensure that I end up with a high-quality product. Spring makes Java enterprise development much easy.  Spring Boot, which we will use in this blog, is a project that does this task with excellence.

Follows are the steps to configure your spring boot framework with the Junit and Maven.

Step-1)Set up Spring boot with J-Unit testing Approach

After Set your maven dependencies , for spring-boot add following dependency for testing Approach.

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>

Step-2)Create test Package and in that ,create DemoApplicationTests Class.

Step-3)Inject controller using @InjectMocks, Inject repository using @Mock Annotations.

Let us take some J-Unit Annotations used in java class :

@Before:@Before annotation are executed before each test.

@After:It executes after each test.

@BeforeClass: It executes common operation before each test,So it executes  only once before running all tests.

@AfterClass: It executes common operation after each test, So it executes only once after running all tests.

@Test:The Test annotation tells JUnit that the public void method to which it is attached can be run as a test case.

In JUnit 5, the tags @BeforeEach and @BeforeAll are the equivalents of @Before and @BeforeClass in JUnit 4.

Configure Java File and Select Run as Junit and Test the file.

 

Congratulations!!!you are done with your TDD approach.

Eclipse not auto-configuring/auto-importing a Git mavenized project

I was trying to setup a maven project in eclipse via GIT. I had hoped, it will auto import the project into eclipse, but for some reason that did not happen.

 

This is what was done as a workaround:

Step:1 Checkout your repository in your system

File->import->Git->Project from Git->Clone URI->Enter Git Repository Details

Select Destination where you wanted to store your Git Repository

Step:2 Import your Project into Eclipse

File->import->maven->install or deploy an artifact to a Maven Repository

Once these steps are done, The project is browsable in eclipse!

Some Helpful Git Commands for the commandline:

git init — Initialize your directory with git.

git add FILE and git checkout — FILE To stage/unstage a file

git commit— To save your changes. This commit will be local

git stash and git stash pop — Stashes are back

git reset HEAD –hard Revert all your local changes

git log— Access all the history in the repository

git rebase –You can squash all the commits! (one should be carefull with this one)

git branch –You can create local branches,But keep the history linear

Hope this workaround and the commands are useful to a new user.

Creating a new git project on xp-dev.com with IntelliJ!

Meta Steps, YMMV…

1/Select what you need from Spring INITIALIZR :: https://start.spring.io/
2/Download/Extract the zip && cd into it.
3/Create a git repo on xp-dev.com
4/Initialize Git repo:
a)git init
b)git add .
c)create .gitignore
d)git commit .
e)git remote add origin https://xp-dev.com/git/
f)git push -u origin master
5/Open IntelliJ
a) checkout https://xp-dev.com/git/
b) Goto Maven Projects and add the pom.xml(if not picked automagically by IntelliJ
c)Do deploy, I got a failing unit test, as I added spring-tests.

What Elon Musk can learn from Java App/Cloud Deployments!

I had an unproductive day yesterday!

I did nothing, but slept through most of the day. And then late night this next challenge of deploying the hush-hush java app over the cloud started to bother me.(afterall it was not a totally unproductive day, thinking wise!)

And then, flash back to a few days, where comparisons were made, what I am doing (javascript ehew!) and what one of the current top living inspiration in the current world Elon Musk is doing, and then I went into sad slumber!

Then yesterday happened, and then it clicked:: we Java devs(web ones, not hard core jdk ones) are orchestrating everything in lifecycle of what Elon Musk is trying to do!

Here is the analogy(it can be extended wonderfully!):

  1. The WAR(Web ARchieve)(sorry, I am old fashioned) is like the unmanned space ship.
  2. The dev JVM is like simulated Mars environment.
  3. The cloud is the SPACE where the bits travel to-and-fro in form of data/packets.
  4. The machine IP Address is like the lat/long of where you want to deploy.

So my current app is in its final integraton phase(hush-hush…) and I am trying to accomplish Slide Driven Development.(nice term!).

Slice Driven Development :: A development approach where a feature/flow is shipped to staging environment as soon as it becomes usable.

Currently I(with @explorer) are trying to integrate all features/flow of the hush-hush app, While I am totally unsure/unaware how it will behave when deployed on staging/production environment. Therefore, I had come up with this approach :: The momemt a feature becomes bug-discoverable, it ought be shipped so that:

  1. Move to the next flow..
  2. Bugs can be quashed..
  3. (most imp)Our path of going from dev–>staging–>production for any feature should be seamless and smooth like  skating on butter!

And then, a Eureka moment happened!! And this blog post came about!

Your Takeaway: If you are on a team working with Elon Musk(or anyone trying to transport stuff from place X to place Y, in an unsure environment), you can leverage from the experience of thousand if not millions of deployments of web java developers trying to deploy WAR file formats from local dev JVM to production JVM.

We know the nuances of this lifecycle!

It might save you some time! 🙂

The Slow Moving Manifesto!

If you are being tailgated, we recommend you follow this approach to come out of that situation!

Go Absolutely Slow!

YES, surprisingly it works out just fine!

Purpose: To know who is tail-gating you AND Why?

How it works?

  • If the vehicle following you sees you slowing down, they will have no choice to speed up (which means they were not following you) or look-you-in-the-eye. (either ways, the problem is solved!)

Benefits of slowing down

  1. By slowing down, you opened an opportunity to talk.. Human Connect!
  2. By slowing down, maybe you can have a running conversation, you are driving + talking(giving direction who knows). Saves time!
  3. By slowing down, you saved lifes! No stats but still true!
  4. By slowing down, You enjoy the road-side scenary. (remember enjoy the journey not just the destination!)
  5. By slowing down, You literally look the problem in the eye than running away from it.

There goes, we have the Slow Moving Manifesto!

Credits: Smita, Rachit + (KennyG played in our neighbouring park @ 1000 hrs) 🙂

Java Lookout — Java Language and Platform Futures @Devoxx, Belgium.

Feedback on watching the Java lookout!

1/Bad humour. Meh!

2/If you cannot commit anything to the language, why broadcast it? Are you scared of a features popularity? Rant on a similar thing in JavaEE

3/Spineless Humour!  https://youtu.be/oGll155-vuQ?t=564

4/Listen carefully :: “You may have to use type args more with lambda’s” https://youtu.be/oGll155-vuQ?t=721 So your principle of bringing least disruptive change FAILED!

5/Freeze the screen :: Which code is still less readable? https://youtu.be/oGll155-vuQ?t=830 Come on! Stop pushing #JEP286 #DieJEP286 IT DOES NOT MAKE SENSE. Simple!

6/Sadly the current Java architects are trying to add features to reduce developers time to build a feature. There are already players to do this: Spring et al. You should be focused to create the playground, and not the rules. Why can’t they understand this simple fact? Look at the earlier Java architects… Did they focus delivering a CS concept or ease of developer writing the code? Don’t outsmart Spring, Don’t outsmart IDE’s outsmart CS concepts and implement them in Java.

7/Improved Switch design is being talked about, this is a brainstorming topic, it does not make sense to show-off it *conceptually* here!

8/Value Types — Only needed if you are pixel developer or probably a compiler writer. A lot of people writing Java are Enterprise users. We have custom wrappers, and would *not* need Value Types. But nonetheless its a welcome feature!

9/Project Valhalla — Get a basic version out, build on it later. Do not try to deliver a 5 story building in one go. Deliver one layer per version.

10/The decision for priority of a feature should have been *complexity* and if some feature is wanted and do-able, IT SHOULD BE DONE AND NOT POSTPONED.

I have gone a lot rusty with Java! :-/

 

 

Talking to mysql on Bitnami google-cloud Tomcat instance

The Java deployment world is plagued with infra issues! Things we need to take care of:

  • Apache
  • Tomcat
  • RDBMS
  • Firewall/Ports
  • Shell accesses
  • Security/Encryption/Keys
  • File System Storage
  • Indexes corrupting and the list goes on…

So after my failed attempt to understand/decipher CORS issues on the AWS platform, I fortunately stumbled on google-cloud! And it is one hell of a bouquet of services for us petty and dev-ops-complaining Java folks!

So churn out a bitnami tomcat instance and you get the feel of the aws thing. For over a month now my google cloud app was(still is) talking to the mysql instance on aws, before that starts to drain my mini wallet, time to configure a mysql instance on google-cloud. And here are the steps:

  1. Have access to the SSH into your google cloud instance working
  2. Create following script (/home/bitnami/mysql-init):
  3.  UPDATE mysql.user SET Password=PASSWORD('NEW_PASSWORD') WHERE User='root';
     FLUSH PRIVILEGES;
    
  4. sudo /opt/bitnami/ctlscript.sh stop mysql
    
  5. sudo /opt/bitnami/mysql/bin/mysqld_safe --defaults-file=/opt/bitnami/mysql/my.cnf --pid-file=/opt/bitnami/mysql/data/mysqld.pid --init-file=/home/bitnami/mysql-init 2> /dev/null &
    
  6. sudo /opt/bitnami/ctlscript.sh restart mysql
  7. Remove the script in step 2.

So it turns out to get mysql talking on your bitnami instance you only need to reset the password.

Further to enable remote access do this in

/opt/bitnami/mysql/my.cnf:

  •  #bind-address=127.0.0.1
    

Next to enable remote mysql access via workbench you need to enable firewall ports to allow connections for tcp 3306 for a specific ip on your google cloud instance.

And there you go, you have a lot powerful config, much like aws ready to be used, backed by google!!

 

 

Bots – BOring Tasks Systematized!

We are surrounded and supported by a bots ecosystem. I will try to bring that into perspective to evaluate the current rate of explosion of bots and newer solutions coming around it — and how to stay human still!

Connected with the Bot Ecosystem!
  • When we wake up,with help from an external alarm clock , we are taking help of a Bot.
  • When we are parking our car and when reversing it, there is a smart system that warns us for the exact safe-distance to keep going. That’s a smarter Bot!
  • Notice the cool soap dispenser that spits soap when we put our hand under it? That’s a Bot!
  • Recall the automated vacation response you configured in your favorite email client? Well, you have guessed, that’s also a …Bot!

We have never thanked these systems for their existence, for we know they are physics concepts glued together mechanically. A Thank-You comes and goes via a heart! 🙂

Coming back to the topic, now imagine all of those Bots, fusing into a single system with a human structure!

SuperBot
Hey, I am SuperBot and can do everything that was listed above & much more!
  • What was your reaction when the last time, your car backing system told you incorrectly that you were 1 meter from an obstacle while there was a gap of roughly 5 meters!
  • When was the last time your alarm clock did not wake you up?(battery out or way too low?)
  • Isn’t it way irritating when the mechanical soap dispenser does not spit the soap, instead only throws out the air?
  • Haven’t we all misfired a wrongly configured vacation response and feeling way embarrassed and apologizing for it for all day long to colleagues and co-workers!?

As for the premise, these bots *independently* do their job perfectly. But when they break, nothing else is affected around it. Well I am yet to hear about misconstruing a vacation response due to a non working soap dispenser!(all right that’s way too much exaggeration — but we get the point!).

The fact that they are disconnected, allows us, the user of that system to fallback/switch to another means. Say the car backing system is down, well ask a passerby to help you. Your alarm clock is out, well start working on your body’s alarm clock(no excuse here!).

I will construct two hypothetical views that are actually happening in the bots eco-system and obviously I am opposed to such developments. Hence suggesting a way out, as I cannot stop these movements.

  1. Once these systems are connected, and one of its components starts acting strange(see I elevated it to a human), the whole behavior might be eccentric to say the least. If your SuperBot is out of battery, it might just get you to wake you up but might not be able to help you with and send the vacation responses.
  2. Add the internet to the mix!

    I’m out of order but controlled via the internet.

The take away from the whole story:

  1. Let us as individuals, not try to fuse all our bot dependency into a single system. It makes it highly probable to fail and although it gives us lot of convenience, but at a high cost of dependence. This whole connected thing is a convenience at the cost of our freedom.
  2. The most secure sites are still subject to theft/fraud ( I am only referring to financial losses). When a fused bot with the thinking of the whole internet is there, and one small error/condition unchecked/unnoticed will be not safe, to say the least.

As for the bots ecosystem, I would love to see

  • a centralized parking bot, letting a big relief to all humans from this petty job
  • an aerial bot that delivers newspapers

But then again, I won’t allow either of them talk to each other, A single Bot good for One Task. 🙂