Tutorial by Examples: e

To preload remote images and ensure that the image is only downloaded once: Glide.with(context) .load(yourUrl) .diskCacheStrategy(DiskCacheStrategy.SOURCE) .preload(); Then: Glide.with(context) .load(yourUrl) .diskCacheStrategy(DiskCacheStrategy.SOURCE) // ALL works her...
The first mistake that nearly every single programmer makes is presuming that this code will work as intended: float total = 0; for(float a = 0; a != 2; a += 0.01f) { total += a; } The novice programmer assumes that this will sum up every single number in the range 0, 0.01, 0.02, 0.03, .....
Groovy's safe navigation operator allows to avoid NullPointerExceptions when accessing to methods or attributes on variables that may assume null values. It is equivalent to nullable_var == null ? null : nullable_var.myMethod() def lst = ['foo', 'bar', 'baz'] def f_value = lst.find { it.startsWi...
class User { String name int age } def users = [ new User(name: "Bob", age: 20), new User(name: "Tom", age: 50), new User(name: "Bill", age: 45) ] def null_value = users.find { it.age > 100 } // no over-100 found. Null null_value?.name?....
for numbers, a zero value evaluates to false, non zero to true int i = 0 ... if (i) print "some ${i}" else print "nothing" will print "nothing"
a string (including GStrings) evaluates to true if not null and not empty, false if null or empty def s = '' ... if (s) println 's is not empty' else println 's is empty' will print: 's is empty'
Collections and Maps evaluates to true if not null and not empty and false if null or empty /* an empty map example*/ def userInfo = [:] if (!userInfo) userInfo << ['user': 'Groot', 'species' : 'unknown' ] will add user: 'Groot' , species : 'unknown' as default userInfo since the u...
a null object reference evaluates to false, a non null reference to true, but for for strings, collections, iterators and enumerations it also takes into account the size. def m = null if (!m) println "empty" else println "${m}" will print "empty" de...
Sometimes it may be useful to have a specific asBoolean definition in your own program for some kind of objects. /** an oversimplified robot controller */ class RunController { def complexCondition int position = 0 def asBoolean() { return complexCondition(this...
Not all type erasure involves virtual inheritance, allocations, placement new, or even function pointers. What makes type erasure type erasure is that it describes a (set of) behavior(s), and takes any type that supports that behavior and wraps it up. All information that isn't in that set of beha...
The population count of a bitstring is often needed in cryptography and other applications and the problem has been widely studied. The naive way requires one iteration per bit: unsigned value = 1234; unsigned bits = 0; // accumulates the total number of bits set in `n` for (bits = 0; value; ...
The n & (n - 1) trick (see Remove rightmost set bit) is also useful to determine if an integer is a power of 2: bool power_of_2 = n && !(n & (n - 1)); Note that without the first part of the check (n &&), 0 is incorrectly considered a power of 2.
Of course, the best way to detect mobile is for the hardware to notify you directly. Cordova PhoneGap exposes a 'deviceready' event, that you can add an event listener to. document.addEventListener('deviceready', function(){ Session.set('deviceready', true); }, false);
Install Iron Router From the terminal: meteor add iron:router Basic configuration Router.configure({ //Any template in your routes will render to the {{> yield}} you put inside your layout template layoutTemplate: 'layout', loadingTemplate: 'loading' }); Render without d...
HTML template files are always loaded before everything else Files beginning with main. are loaded last Files inside any lib/ directory are loaded next Files with deeper paths are loaded next Files are then loaded in alphabetical order of the entire path Reference Link Reference page: Mete...
You can default to the normal Mongo format by defining your collections with the idGeneration field. MyCollection = new Meteor.Collection('mycollection', {idGeneration : 'MONGO'});
Many beginners to Mongo struggle with basics, such as how to insert an array, date, boolean, session variable, and so forth into a document record. This example provides some guidance on basic data inputs. Todos.insert({ text: "foo", // String listId: Session...
You can get it either synchronously: var docId = Todos.insert({text: 'foo'}); console.log(docId); Or asynchronously: Todos.insert({text: 'foo'}, function(error, docId){ console.log(docId); });
Using MongoDB for time series data is a very well document and established use-case, with official whitepapers and presentations. Read and watch the official documentation from MongoDB before trying to invent your own schemas for time series data. MongoDB for Time Series Data In general, you'll w...
Simple pattern for filtering subscriptions on the server, using regexes, reactive session variables, and deps autoruns. // create our collection WordList = new Meteor.Collection("wordlist"); // and a default session variable to hold the value we're searching for Session.setDefault('...

Page 622 of 1191