Tutorial by Examples

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.
my @data_array = (123, 456, 789, 'poi', 'uyt', "rew", "qas"); print Dumper @data_array; Using Data::Dumper gives an easy access to fetch list values. The Dumper returns the list values serialized in a way that looks like Perl code. Output: $VAR1 = 123; $VAR2 = 456; $VAR3 ...
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('...
Geospatial collections generally involve storing GeoJSON in the Mongo database, streaming that data to the client, accessing the browser's window.navigator.geolocation, loading up a Map API, converting GeoJSON to LatLngs, and plotting on the map. Preferably all in realtime. Here are a list of reso...
The following example will log all of your collection queries to the server console in realtime. Meteor.startup( function () { var wrappedFind = Meteor.Collection.prototype.find; // console.log('[startup] wrapping Collection.find') Meteor.Collection.prot...
If the Node event loop acts like a bicycle chain, the server-side collection observer is like a derailleur. It's a gearing mechanism that is going to sit on the data collection as the data comes in. It can be very performant, as all race bicycles have derailleurs. But it's also a source for breaking...
Texttastic Code Editor - Code editor with syntax highlighting for iOS devices. Working Copy - Clone Github repositories to your iPad and code on the go. CodeHub - Browse and maintain your GitHub repositories. Management tool. iOctocat - Social utility for following Github projects. iMockups fo...
Inspecting an Object You can find the public methods an object can respond to using either the methods or public_methods methods, which return an array of symbols: class Foo def bar; 42; end end f = Foo.new def f.yay; 17; end p f.methods.sort #=> [:!, :!=, :!~, :<=>, :==, :===, :=...

Page 704 of 1336