Friday, November 18, 2016

Some attempts in game dev :-)

I and colleague of mine Alexander Zhak, we've decided to create a game in honor of ending of project we'v participated in.
This project was related to IOT: gateways, devices, mobiles and so on. Besides that we've added comic description of the team who worked on this project.
Game is based on phaser.io framework. That's what we've got in the end: we.katim-build.com 

Tuesday, February 2, 2016

Pagination and filtering with Backbone.Marionette

  Recently I've got a task to show grid data with pagination using Backbone.Marionette. Moreover we were needed to filter data by some flag(active/finished).I am not a guru of UI :-) I am mostly backend developer, but had some experience in UI and it was funny and interesting for me to resolve this issue.
  I've a little bit simplified the final code of pagination/filtering module in demo purposes and prepared real running sample on my Amazon ec2 instance, so you can analyse js source and networks calls under F12/firebug or whatever you like to use. Try (Demo)Pagination/filtering (http://52.32.134.99:3000)
  I've decided to use Backbone.PageableCollection to configure paging with its server-side mode. See backbone-pageable for more details. Below is how events collection looks like:

  Pay attention to parseState and parseRecords methods. They allowed us to recognize totalCount and items fields get passed from server. From ui side we will send pageSize, showActiveEventsOnly and offset to server side and then use them to fetch appropriate subset of data.
  On server side(Java) I've used simple grizzly server and method which returns paging data as follows:

  So as you can see we use parameters get passed as query params from ui side to determine which part of data we need to return as per given offset/filtering flag. I made screenshot describing what happened under the hood, when you, for example, click second page  on paging control:


  It depends on you how to implement server side related logic to get paged data. The one this I should mention the final set of data we will return to ui is wrapped with custom object that contains two key fields: result items and totalCount. I described those fields above.
  They are used by ui to build corresponding ui(remember parseState/parseRecords methods ? :-))

The most efficient way to get subset of data is to resolve it on database level, but I repeat it depends on your decision and details of your project. Okay, now we have all the data from the server and we are ready to show it on ui side. Let's see how our filter and paging controls are defined. I've used RequireJS as module loader, so the module looks like as follows:

and the corresponding templates:

 I've used materializecss so paging controls looks in Material Design style.
 Model and View are linked using CompositeView for grid data and simple ItemView for pagination/filtering logic:

And the final screen where everything is together:


P.S. I hope my solution will be helpful to someone :-)

Sunday, October 25, 2015

#тыжпрограммист

I broke the screen in my old iphone 4
No time to suffer ;-)
Thanks to https://www.youtube.com/watch?v=k_S7O7ZtQcM
Follow the instructions above I've replaced a broken display  with new one :-)



Sunday, December 7, 2014

Custom ThreadPoolExecutor based on spinlock approach.

      In one project we used ActiveMQ(JMS API) to communicate between business services and custom engine that worked asynchronously behind the scene to process financial data.
The flow to add/remove entity from ui was done as it usually organized in context of three-tier architecture: call to ui controller, route appropriate method, use service and then DAO to add/delete entity and then notify active mq corresponding consumers to process add/delete actions.

     But the issue was in the following: entity might be created in database, but not fully processed by engine while user tries to delete it from web interface.
It's not the issue on the  database side, this is multithreading synchronization question.

    I decided to use spin lock approach to sync two add/delete threads that did their work when the corresponding messages came to ActiveMQ queue.

    This is how JMS handler looks like. When message comes to queue it's then appropriate handled by  tickerEngineRequestProcessor, that is simply container for ThreadPoolExecutor performing tasks execution(add or delete one).

     Below is definition for tickerEngineRequestProcessor:
Let's now describe TickerTask, it just implemented Runnable interface to be processed within custom spin lock thread pool which I will describe further.

   The main idea in TickerEngineAddRemoveSyncThreadPoolExecutor is to perform spin iterations on thread that performs removing ticker while thread which adds ticker is not finished yet. This logic is placed in beforeExecute action. In afterExecute we just remove corresponding tickerId key from tickerIdsToAddInProgressState set.
   One more word about tickerIdsToAddInProgressState. This is ConcurrentHashSet that I choosed for storing state as per given tickerId, because we need to maintain sync add/remove operations based on the given tickerId and don't affect other tickers that might be processed at the same time. Thread.yield() is signal for threads scheduler to switch its work to other threads but the yielding thread can be scheduled back in one interrupt period later.






Tuesday, December 2, 2014

[mobile] How to overcome 'adb devices empty list' issue on Linux Mint 17

Recently I needed to install small  phonegap application with custom oauth2 authentication to my old htc desire.
It's not so big deal to run such applications on emulator devices via
phonegap run android,
But when I switched to the real device this caused some difficulties.
I work in Linux mint 17 and as it turned out adb devices is empty on this case.
After a little bit hacking and digging through internet I've found working solution.

1) type lsusb in shell and know vendor id: 
Device 007: ID 0bb4:0cb0 HTC (High Tech Computer Corp.)

So I see my old htc)
2) create 51-android.rules in /etc/udev/rules.d folder:
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"
3) Edited the adb_usb.ini file, added the 0x0bb4 
4) Enabled debugging on htc device(settings->developers)
And now list of devices is not empty!
List of devices attached HT15XTR04859 device
So we can run app on htc after that:

phonegap run android --device=HT15XTR04859






Monday, December 1, 2014

How To Fix NTFS Mount Issue In Linux Mint And Windows 8

After installing new Linux mint cinanmon 17 in dual bot with Windows 8 I'have faced with boring issue when mint could not mount disks belonging to Windows 8. The answer is this is because of Fast boot feature and it's might be simply resolved with turning off it from within Win 8. How?
Just follow this link for example :
http://itsfoss.com/solve-ntfs-mount-problem-ubuntu-windows-8-dual-boot/

Wednesday, October 29, 2014

Wednesday, July 9, 2014

Real world Java examples of GoF design patterns

http://balusc.blogspot.com/2010/04/examples-of-gof-design-patterns.html

Tuesday, June 10, 2014

How to download file using netty

https://github.com/Atmosphere/nettosphere/blob/master/server/src/main/java/org/atmosphere/nettosphere/HttpStaticFileServerHandler.java

Tuesday, March 25, 2014

How to shutdown 'play' programmaticly based on the corresponding conditions.

      I have got the task to stop 'play'(controller and the whole server) according to some requirements. To be more clear I need to check whether the сurrent request to the given method of the given controller is the last allowed one and then shutdown play.

     The main point that Calling System.exit() is enough to shut down the JVM I have read here: https://groups.google.com/forum/#!searchin/play-framework/system.exit/play-framework/xWAi7tPIEhY/2Ainrixfp8IJ

Cause even  Play.stop(); does not work as expected as per link above from
the 'play-framework' user group.

    But then I faced with the issue on how to return answer with JSON data and only then stopping the 'play' server. ScheduledExecutorService сame to help me). I've read a lot of documentation/articles about built-in play's approaches like async jobs, await and etc, but no one of them can guarantee me then play server will be stopped after returning of JSON answer.

   With ScheduledExecutorService I wait 5 sec after the short json answer and then shut down the 'play' server. Moreover if we assume that the json result will not be back to time of shutdown (which is very very unlikely) then my logic inside deviceConfigurationLocator service kills play server at the next request.

   I've tested this logic with the different scenarios and it works! Play server dies when I want this :-) Below is the my implementation of this task:


P.S. If you have any other ideas on how to stop/shutdown play server in context of my task feel free to tell about this in the comments.