Tuesday, August 13, 2019

FizzBuzz

FizzBuzz is a pretty basic problem yet interesting for different purposes. It has been used in a variety of situations :

1) As a kids game as pointed out by wikipedia article, FizzBuzz

2) As a job interview question for programming related posts as pointed out in a 2007 article on by Mr Imran on Using FizzBuzz to Find Developers who Grok Coding.

3) For online judge contests and challenges like HackerRank

The question may be used in coding interview for good reasons as discussed by CodingHorror article, Why Can't Programmers.. Program?

Some of us might be wondering why a ~ 2007 problem is still relevant in 2019! This question has been answered already by a hackernoon article, Why I’m still using “Fizz Buzz” to hire Software-Developers

Many more approaches along with their variations have been discussed at
a) FizzBuzz Solution Dumping Ground
b) FizzBuzz JavaScript solution
c) HackerNews: What's the shortest FizzBuzz you can write? What language?    (discussion on Anarchy Golf : FizzBuzz)
d) Twenty Ways to FizzBuzz, An exercise in Javascript
e) FizzBuzz In Too Much Detail

The hackerrank challenge specially asks for the shortest code. The ability to write a short code depends on the minimum requirement of boilerplate code. In Java we can reduce length of the codef based on identifier(s), parentheses, ternary operator, line breaks, pre/post increment, re-writing n%3==0 conditions with greater-than (or less-than operators) as follows.
class S{public static void main(String[]a){for(int i=0;++i<101 i="" ystem.out.println="">0?i%5>0?i:"Buzz":i%5>0?"Fizz":"FizzBuzz");}}

Using javascript, we make it even shorter. We may need to remind ourselves that writing unreadable, difficult to maintain, is not recommended. Java, C, C++, C#, Python, Ruby, R, none of the submissions in these languages reached the top score yet which is 16.0. It leads us to the question, which submission led to the top score? The answer is bash script (proof). How? The hint has been kindly provided by the author of the top submission, Byron Formwalt at here.

If we are new to bash scripting, we may wish to get started with few resources mentioned here, here, and here. The Advanced Bash-Scripting (ABS) Guide (HTML, PDF) from The Linux Documentation Project (LDP) may be a good starting point.

Disclaimer: Even though this may be suitable for the purpose of the getting higher score in hackerrank or just for exercise, it may not be a part of best coding practices. There are many scopes for improvement in this post. Suggestions are welcome. .

Java Code Convention or Style Guide

Almost all organizations either adopt the coding style from someone else or develop their own one. Newly recruited employees as well as interns may be expected to following the existing code convention or style guide of the company. If you are starting your own company, you may wish to adopt or develop your own one based on one of the available ones. Some examples are:


Java Code Convention / Style Guide

Oracle/Sun
1999:
https://www.oracle.com/technetwork/java/codeconvtoc-136057.html

1997:
https://www.oracle.com/technetwork/java/codeconventions-150003.pdf


OpenJDK:
http://cr.openjdk.java.net/~alundblad/styleguide/index-v6.html


Google:
https://google.github.io/styleguide/javaguide.html


Android:
https://source.android.com/setup/contribute/code-style


Facebook:
https://github.com/facebook/jcommon/wiki/Coding-Standards


Twitter:
https://github.com/twitter/commons/blob/master/src/java/com/twitter/common/styleguide.md


Mozilla:
https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Coding_Style#Java_practices


Spring Framework:
https://github.com/spring-projects/spring-framework/wiki/Code-Style



CMU SEI:
https://wiki.sei.cmu.edu/confluence/display/java/Java+Coding+Guidelines
https://wiki.sei.cmu.edu/confluence/display/java



See also:
Python Style Guide or Code Convention

Wednesday, October 24, 2018

Sharing PC/Laptop Internet via WiFI or creating WiFi hotspot

The following steps discusses about sharing LAN Internet connectivity from laptop or desktop with wifi/wlan card. to other laptops / phones



  1. open cmd in administrative mode
  2. To start the network, copy paste the following two lines

netsh wlan set hostednetwork mode=allow ssid=MyWiFi key=MyPasswordHere

netsh wlan start hostednetwork



To stop the network, copy paste the following line

netsh wlan stop hostednetwork



to connect to it, use the following from phone or other laptops
Wifi name (SSID):
MyWiFi

password:
MyPasswordHere

Monday, October 22, 2018

How to choose a research or thesis topic

As-salamu Alaikum,

Often we struggle to choose a thesis topic or research area. The following links might help as a starter:

TOPIC
 
Computers are used to solve problems in many domains: Computational Sciences
 
Computer Science hot research topics
 
 
Computer Science Graduate Theses
 
How to select a thesis topic?

Saturday, October 6, 2018

Mathematics in Computer

What Every Computer Scientist Should Know About Floating-Point Arithmetic
https://docs.oracle.com/cd/E19060-01/stud8.compiler/817-0932/ncg_goldberg.html


SUN Numerical Computation Guide


https://en.wikipedia.org/wiki/IEEE_754

https://steve.hollasch.net/cgindex/coding/ieeefloat.html

Friday, August 31, 2018

Workaround for malfunctioning battery level detection

No action / do nothing when battery reaches ctricital level as a workaround for malfunctioning battery level detection

Windows:
powercfg -setdcvalueindex SCHEME_CURRENT SUB_BATTERY BATACTIONCRIT 0
powercfg -setacvalueindex SCHEME_CURRENT SUB_BATTERY BATACTIONCRIT 0

or,
POWERCFG /SETDCVALUEINDEX SCHEME_CURRENT SUB_BATTERY BATACTIONCRIT 0
POWERCFG /SETACVALUEINDEX SCHEME_CURRENT SUB_BATTERY BATACTIONCRIT 0

source:
https://superuser.com/a/1175864/500845


Linux:
https://askubuntu.com/questions/378440/how-to-avoid-shutdown-on-critical-battery
https://forums.linuxmint.com/viewtopic.php?t=201336
https://askubuntu.com/questions/210623/modify-actions-when-battery-is-critically-low