Pulsing sequence generator

GeneratorNumbersSequence

Imagine you need to generate a “pulsing” sequence of numbers which continuously repeats, going up and down between the given values, like this: 5-6-7-8-9-10-9-8-7-6-5-6-7…

Such a sequence may serve different purposes, but in any case, we want a universal solution even for this simple problem. The algorithm is simple too…

Read more →

Composite Iterator. Java

CollectionsIterableIteratorJava

Imagine you have two collections with different types of data. Both of them are sorted by some rule. You need to iterate over both collections, preserving their sort order. Like this:

We want to share a simple but effective technique using the Iterator and Iterable interfaces.

Read more →

How to move an object along a sine curve in Unity?

mathematicsunity

Today we solved a small task of moving objects along a given trajectory. In our case it was a sine curve.

Read more →

Binary search tricks

BinarySearchJavaTipsAndTricks

The array is probably the most popular data collection. Everyone has used, is using and will use it. If an array is sorted, you can simplify your life while processing it. We want to share a simple but effective trick with the binary search algorithm.

Imagine you have a sequence of N numbers which splits the space into N + 1 segments. The two segments on the edges are infinite. For instance, here is a fuzzy thermometer:

Read more →

Android. Support library. Nested fragments and startActivityForResult()

ActivityAndroidFragmentNestedFragmentStartActivityForResultSupportLibrary

This post is dedicated to nested Fragments from the support library and to their big issue.

Fragment has the following methods: startActivityForResult() and onActivityResult(). The first one just delegates the call to FragmentActivity.startActivityFromFragment(), and the second one is called from FragmentActivity.onActivityResult().

If this behavior is just a wrapper around Activity, then how is the result delivered to the Fragment instance?

Read more →