Tutorial by Examples: n

This example shows a helper class that contains methods useful, when executing the queries for data. Every method here uses Java Generic's in order to be very flexible. public <T> List<T> selectElements(AbstractDao<T, ?> dao) { if (dao == null) { return null; } ...
For some reasons you may want to ignore your build variants. For example: you have 'mock' product flavour and you use it only for debug purposes, such as unit/instrumentation tests. Let's ignore mockRelease variant from our project. Open build.gradle file and write: // Remove mockRelease as it...
@Singleton @Component(modules = AppModule.class) public interface AppComponent { void inject(App app); Context provideContext(); Gson provideGson(); MainActivityComponent mainActivityComponent(ActivityModule activityModule); } @ActivityScope @Subcomponent(modules = Act...
Add the following dependencies to your application. compile 'com.facebook.stetho:stetho:1.5.0' compile 'com.facebook.stetho:stetho-okhttp3:1.5.0' In your Application class' onCreate method, call the following. Stetho.initializeWithDefaults(this); When creating your Retrofit instance, crea...
This technique details how to ensure that your .apk has been signed with your developer certificate, and leverages the fact that the certificate remains consistent and that only you have access to it. We can break this technique into 3 simple steps: Find your developer certificate signature. Em...
The following are some of the more common/useful shortcuts. These are based on the default IntelliJ shortcut map. You can switch to other common IDE shortcut maps via File -> Settings -> Keymap -> <Choose Eclipse/Visual Studio/etc from Keymaps dropdown> ActionShortcutFormat codeCTRL...
Enable Offline Work: Click File -> Settings. Search for "gradle" and click in Offline work box. Go to Compiler (in same settings dialog just below Gradle) and add --offline to Command-line Options text box. Improve Gradle Performance Add following two line of code in your gradle...
System Requirements Microsoft® Windows® 8/7/Vista/2003 (32 or 64-bit). Mac® OS X® 10.8.5 or higher, up to 10.9 (Mavericks) GNOME or KDE desktop Installation Window Download and install JDK (Java Development Kit) version 8 Download Android Studio Launch Android Studio.exe then mention J...
We want to gather data created by multiple Workers. First we create a Queue: sink = Queue.new Then 16 workers all generating a random number and pushing it into sink: (1..16).to_a.map do Thread.new do sink << rand(1..100) end end.map(&:join) And to get the data, conver...
We want to process data in parallel. Let's populate source with some data: source = Queue.new data = (1..100) data.each { |e| source << e } Then create some workers to process data: (1..16).to_a.map do Thread.new do until source.empty? item = source.pop sleep 0.5 ...
We want to process data in parallel and push it down the line to be processed by other workers. Since Workers both consume and produce data we have to create two queues: first_input_source = Queue.new first_output_sink = Queue.new 100.times { |i| first_input_source << i } First wave of...
q = Queue.new q << "any object including another queue" # or q.push :data There is no high water mark, queues can infinitely grow. #push never blocks
q = Queue.new q << :data q.pop #=> :data #pop will block until there is some data available. #pop can be used for synchronization.
syncer = Queue.new a = Thread.new do syncer.pop puts "this happens at end" end b = Thread.new do puts "this happens first" STDOUT.flush syncer << :ok end [a, b].map(&:join)
q = Queue.new q << 1 q << 2 a = Array.new a << q.pop until q.empty? Or a one liner: [].tap { |array| array < queue.pop until queue.empty? }
To avoid infinitely blocking, reading from queues shouldn't happen on the thread merge is happening on. To avoid synchronization or infinitely waiting for one of queues while other has data, reading from queues shouldn't happen on same thread. Let's start by defining and populating two queues:...
Values passed as enum constructor arguments can be captured into variables by use of pattern matching. Assume the following enum: enum Color { RGB(r : Int, g : Int, b : Int); HSV(h : Int, s : Float, v : Float); } The red channel value can be captured as follows: var color = Color.RG...
Enum constructors can be matched using pattern matching. Assume the following enum: enum Color { Red; Green; Blue; RGB(r : Int, g : Int, b : Int); } Colours with only a green channel value can be matched as follows: var color = Color.RGB(0, 127, 0); var isGreenOnly = swit...
Operator overloading is only possible with abstract types. The following abstract defines a Vec2i type based on the Array<Int> type. This is a two-component vector with integer values. Operator overloading is made possible my the @:op compiler metadata. Only the available numeric operators ca...
BackAndroid.addEventListener('hardwareBackPress', function() { if (!this.onMainScreen()) { this.goBack(); return true; } return false; }); Note: this.onMainScreen() and this.goBack() are not built in functions, you also need to implement those. (https://github.c...

Page 517 of 1088