@PathVariable in Spring Boot

    @RequestMapping("/news/{year}/{month}/{day}/{title}")
    public ModelAndView news(HttpServletRequest request, HttpServletResponse response,
                             @PathVariable int year, @PathVariable int month, @PathVariable int day,
                             @PathVariable String title) {

        SessionBL sessionManager = new SessionBL(request, response);

        String postUrl = String.format("/%d/%d/%d/%s", year, month, day, title);

        ModelAndView modelAndView = new ModelAndView("index");
        modelAndView.addObject("version", new Statics().getVersion());
        return modelAndView;
    }

References
http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-uri-templates-regex
https://www.mkyong.com/spring-mvc/spring-rest-requestmapping-extract-incorrectly-if-value-contains/

Install and Manage RabbitMQ on Ubuntu

echo 'deb http://www.rabbitmq.com/debian/ testing main' | sudo tee /etc/apt/sources.list.d/rabbitmq.list
wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install rabbitmq-server

Enabling the Management Console

sudo rabbitmq-plugins enable rabbitmq_management
http://[your droplet's IP]:15672/

The default username and password are both set “guest” for the log in.

RabbitMQ MQTT Adapter

sudo rabbitmq-plugins enable rabbitmq_mqtt

Managing on Ubuntu

# To start the service:
service rabbitmq-server start

# To stop the service:
service rabbitmq-server stop

# To restart the service:
service rabbitmq-server restart

# To check the status:
service rabbitmq-server status

add new user

rabbitmqctl add_user test test
rabbitmqctl set_user_tags test administrator
rabbitmqctl set_permissions -p / test ".*" ".*" ".*"

delete guest

rabbitmqctl delete_user guest

References
https://www.rabbitmq.com/install-debian.html
https://www.digitalocean.com/community/tutorials/how-to-install-and-manage-rabbitmq
https://www.rabbitmq.com/plugins.html
https://www.rabbitmq.com/man/rabbitmqctl.1.man.html#add_user
https://stackoverflow.com/questions/22850546/cant-access-rabbitmq-web-management-interface-after-fresh-install

Create a Modal Bottom Sheet

build.gradle

compile 'com.android.support:design:<latest-library-version>'

Create a class that extends BottomSheetDialogFragment , inflated with the layout that will be used as the content of the modal dialog.

public class BottomSheetFragment extends BottomSheetDialogFragment {


    public BottomSheetFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_bottom_sheet, container, false);
    }

}

Create an instance of the modal bottom sheet and show it with the show method, passing the FragmentManager and a string tag as parameters.

CustomBottomSheetDialog bottomSheetDialog = CustomBottomSheetDialog.getInstance();
bottomSheetDialog.show(getSupportFragmentManager(), "Custom Bottom Sheet");

References
https://github.com/mhdr/AndroidSamples/tree/master/096
https://mayojava.github.io/android/bottom-sheets-android/

Install Spring Boot applications

Make fully executable applications for Unix systems
A fully executable jar can be executed like any other executable binary or it can be registered with init.d or systemd
Gradle configuration:

bootJar {
  launchScript()
}

Installation as a systemd Service

create a script named myapp.service and place it in /etc/systemd/system directory

[Unit]
Description=myapp
After=syslog.target

[Service]
User=myapp
ExecStart=/var/myapp/myapp.jar
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

Remember to change the DescriptionUser, and ExecStart fields for your application.

To flag the application to start automatically on system boot, use the following command:

systemctl enable myapp.service

References
https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/sect-managing_services_with_systemd-unit_files
https://tecadmin.net/setup-autorun-python-script-using-systemd/
https://www.raspberrypi-spy.co.uk/2015/10/how-to-autorun-a-python-script-on-boot-using-systemd/

Retrieve query string parameters in Spring Boot

Use @RequestParam

@RequestMapping(method = RequestMethod.GET)
public @ResponseBody item getitem(@RequestParam("data") String itemid){

    item i = itemDao.findOne(itemid);              
    String Itemname=i.getItemname();
    String price= i.getPrice();
    return i;
}

Making an Optional Request Parameter

@GetMapping("/api/foos")
@ResponseBody
public String getFoos(@RequestParam(required = false) String id) { 
    return "ID: " + id;
}

References
https://stackoverflow.com/questions/32201441/how-do-i-retrieve-query-parameters-in-spring-boot
https://www.baeldung.com/spring-request-param

Detect DOM changes with Mutation Observers

            let target = document.getElementById(Post.ViewModel.postURLId);
            let observer = new MutationObserver(function (mutations) {
                mutations.forEach(function (mutation) {
                    console.log(mutation);
                });
            });
            let config = {
                attributes: true, childList: true, characterData: true, subtree: true,
                attributeOldValue: true, characterDataOldValue: true
            };
            observer.observe(target, config);
            // later, you can stop observing
            observer.disconnect();
if (target.addEventListener) {
                target.addEventListener('input', function(e) {
                    console.log(e);
                }, false);
            }

So with the help of above two tricks and browser breakpoints and stacktrace we can detect exact source of error.

References
https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver