Java binary search implementation

Java binary search implementation.

Java stream distinct by property

Java 8 stream has a distinct() method which could be used to filter out a list of distinct objects, but the distinctness of that method is based on Object.equals(Object). What if you want to filter a list of objects based on any property (field) of the object? The StreamEx library comes as an elegant solution.

Python decorator with class

Python decorators are usually created with function, see another related post, but this post also shows an example on how to create decorators with class.

Spring resttemplate post json with utf-8

In Spring framework RestTemplate is very useful in terms of sending various http requests to RESTful resources and this post shows simple examples on how to set Content-Type, Accept headers, as well as the content encoding, which is especially important when requesting with non-ascii (e.g. CJK languages) data.

Async task with celery

A quick guide on how to use celery to accomplish async task in application.

Simple web stack with flask nginx gunicorn supervisor

A simple web stack using flask, nginx, gunicorn and supervisor in python with minimum configuration. This is useful if you want to QUICKLY setup a simple but production ready web service.

Redis db migration

A list of commands to do a quick migration for redis.

Flask based app consolidated logging

Flask has an “app.logger” which you can use for webapp related logging, and for other libraries or packages that flask app is using usually python standard logging is used. There are issues reported that logs from various sources in flask based app sometimes get missed out or get messy. See the references section at the bottom for details about the issues. A workaround is to set global root logging config and override that from flask.

Docker commands and files

Frequently used docker commands and examples of Dockerfile.

Huey as crontab alternative in python

Huey is a little task queue that supports:

  • multi-process, multi-thread or greenlet task execution models
  • schedule tasks to execute at a given time, or after a given delay
  • schedule recurring tasks, like a crontab
  • automatically retry tasks that fail
  • task result storage
  • consumer publishes event stream, allowing high-fidelity monitoring