- Each iteration of the Map step applies only to one document. However, there is a lot of flexibility in terms of what gets emitted in iteration. It can either emit multiple items, or none if certain conditions are not met.
- It is also completely up to the user to create the appropriate key in the Map step. The key thing is that all items with the same key (regardless of which document it originated from) all funnels into the same Reduce iteration eventually (it is possible for e.g. 200 values to be reduce to 1 value in multiple steps, with the reduce output from previous steps appearing in the list as one of the items).
- The Reduce function will not be called for keys that have single values. This means that the same object structure should be used throughout the process.
- There is a "scope" attribute which can be used for global parameters.
My online tech scrapbook where I keep my notes in case I need to look them up later
Tuesday, April 22, 2014
MongoDB MapReduce Notes
A few things that stumped me for a while and took me some time to figure out:
Saturday, April 19, 2014
MongoDB Collection Counting
This is done via the method "count()"
This can be extended to perform conditional counting:
e.g. number of users in New York city
More examples and references: http://docs.mongodb.org/manual/reference/method/db.collection.count/
db.userAccount.count()
|
This can be extended to perform conditional counting:
e.g. number of users in New York city
db.userAccount.count({"city":"New York"})
|
More examples and references: http://docs.mongodb.org/manual/reference/method/db.collection.count/
MongoDB Limit Fields to Return
This is done using the projection feature. Some examples:
To find all entries in userAccount but only have the email returned:
To find all entries in userAccount from city "New York" and only have the email returned:
0 can be used to exclude the field
More examples and references: http://docs.mongodb.org/manual/tutorial/project-fields-from-query-results/
To find all entries in userAccount but only have the email returned:
db.userAccount.find({},{"email":"1"});
|
To find all entries in userAccount from city "New York" and only have the email returned:
db.userAccount.find({"city","New York"},{"email":"1"});
|
0 can be used to exclude the field
More examples and references: http://docs.mongodb.org/manual/tutorial/project-fields-from-query-results/
Tuesday, March 25, 2014
Custom Font on Cocos2d-x
This example show how it's done: http://www.cocos2d-x.org/wiki/How_to_Use_Custom_TTF_Font_on_iOS
However it seems that only TTF fonts are supported.
However it seems that only TTF fonts are supported.
Monday, March 3, 2014
MacOS Finder Remove Folder on Toolbar
In MacOS, it is possible to add a folder to a toolbar. I don't find this feature useful but sometimes it can happen by accident when trying to click and drag a window. To remove it, CMD-Click and drag the folder out.
Thursday, February 27, 2014
C++ Avoid Circular Header File Dependencies
In C++, you will get compile errors when header files have a circular dependence on each other. Therefore, it is best to use forward declarations in the header files, and include the header files only in the "cpp" definition files.
However, there are 2 exceptions to this, where you will need to include another header file in the header file:
However, there are 2 exceptions to this, where you will need to include another header file in the header file:
- When you are inheriting from another class, you will need the header class for that class in the header file
- When you are using a class as a stack variable rather than dynamically allocated heap variable, you will also need the header file for that class in the header file
Saturday, February 22, 2014
Article on Coordinate Unit Movement
This article provides an in-depth writeup on the various issues, solutions and options relating to multiple units moving in a coordinated way in a game: http://www.gamasutra.com/view/feature/131721/implementing_coordinated_movement.php?print=1
Issues covered include formation movement, and difficult problems such as the "stacked canyon" problem.
Issues covered include formation movement, and difficult problems such as the "stacked canyon" problem.
Friday, February 21, 2014
SSL Certificate Types
After some changes in 2007, there are now 2 classes of SSL certs:
- Domain Verification: only domain ownership verification based on email and/or phone and WHOIS record
- Extended Verification: verification of both domain ownership and business entity
DV is cheaper and most CAs issue them within hours. EV requires a few working days and costs more.
In terms of user experience if it's EV, there's a nice looking green bar in some browsers like Chrome. But there's no warning whatsoever for DV. So DV looks to be enough in most cases.
Resources:
Thursday, February 6, 2014
MongoDB Commands for Updating Values Inside Document
This page provides a good compilation: http://jonathanhui.com/mongodb-data-update
MongoDB Updating Entry in Array Within Document
This is done via the "$pop" operation but most examples out there operate on simple objects. Here's how it's done for an array that's deeper within the document.
So e.g. if we have a document like this in the "workshop" collection:
We could remove the entry at the bottom of the array with the command:
Note that if you use the dot notation for accessing attributes deeper into the document, you'll need to surround the expression with quotes.
More documentation on $pop here: http://docs.mongodb.org/manual/reference/operator/update/pop/#up._S_pop
So e.g. if we have a document like this in the "workshop" collection:
{
"_id" : ObjectId("51e216e55cf2ff1231dee123"),
"info" : {
"name" : “Workshop X”,
"city" : “Sacramento”
}
"inventory" : {
"cars" : [
{
"licensePlate" : "XXXX01",
"make" : “Toyota”
},
{
"licensePlate" : "XXXX02",
"make" : “Kia”
},
{
"licensePlate" : "XXXX03",
"make" : “Hyundai”
},
{
"licensePlate" : "XXXX04",
"make" : “Nissan”
},
{
"licensePlate" : "XXXX05",
"make" : “Honda”
}
]
}
}
|
We could remove the entry at the bottom of the array with the command:
db.workshop.update({"info.name":"Workshop X"} ,{$pop:{"inventory.cars" : 1}});
|
Note that if you use the dot notation for accessing attributes deeper into the document, you'll need to surround the expression with quotes.
More documentation on $pop here: http://docs.mongodb.org/manual/reference/operator/update/pop/#up._S_pop
Friday, January 17, 2014
Eclipse Ant JRE
Changing the JRE settings in Eclipse preferences won't affect the JRE version used by Ant. To change it, you need to right click the build file in the Ant view, click "Run As" and then click "External Tools Configurations", and then change the JRE from there.
Monday, January 13, 2014
AWS SES Regions/Endpoints
Apparently for the AWS Simple Email Service, there is only one region and one endpoint for SMTP / HTTPS: http://docs.aws.amazon.com/general/latest/gr/rande.html#ses_region
Saturday, January 4, 2014
Email Max Length
The max length of an email, apparently, is 254.
Reference here: http://stackoverflow.com/questions/386294/what-is-the-maximum-length-of-a-valid-email-address
Reference here: http://stackoverflow.com/questions/386294/what-is-the-maximum-length-of-a-valid-email-address
Friday, January 3, 2014
Designing Validation Rules for Names
Seems like there's no hope of ever getting it right: http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/
But still, I'm sure for the sanity of the app and where applicable, other users, certain rules can/should be applied on a case-by-case basis:
But still, I'm sure for the sanity of the app and where applicable, other users, certain rules can/should be applied on a case-by-case basis:
- Length limits because you simply can't design a website with any length of name possible
- Character limits in situations where names have to be readable by majority of users (e.g. restrict to ASCII or extended ASCII)
Monday, December 30, 2013
Changing Default Wordpress URL in Bitnami Wordpress AMI
Bitnami provides an AMI that can be used in the EC2 for quickly setting up a Wordpress server.
Steps described here: http://wiki.bitnami.com/Applications/BitNami_Wordpress_Stack#How_to_change_the_default_URL_to_root.3f
Steps described here: http://wiki.bitnami.com/Applications/BitNami_Wordpress_Stack#How_to_change_the_default_URL_to_root.3f
Saturday, December 21, 2013
Modal Window Not Displaying With AngularJS and Bootstrap
This will probably be fixed pretty soon but for now (i.e. Angular UI for Bootstrap version 0.7 and Bootstrap 3), the modal window will not display (only the backdrop will).
To make the modal window display, change "display: none" to "display: block" in the ".modal" class in the CSS. However, it will be very badly formatted. To fix the formatting issues, the markup for the modal needs to be put inside the following 2 div blocks:
References:
To make the modal window display, change "display: none" to "display: block" in the ".modal" class in the CSS. However, it will be very badly formatted. To fix the formatting issues, the markup for the modal needs to be put inside the following 2 div blocks:
<div class="modal-dialog">
<div class="modal-content">
<!-- modal content here→
</div>
</div>
|
References:
AngularJS Logging
AngularJS has a logging service $log that can be used to log information for e.g. debugging purpose. The main advantage of using this instead of the usual "console.log" is that you can control whether debug level messages are filtered out. Additionally, you can also add decorators to add additional behaviours.
To use it, just inject "$log" as you would $scope, $location etc.
Example here: http://docs.angularjs.org/api/ng.$log
Configure the $logProvider when defining the module to enable/disable debug.
Example: http://plnkr.co/edit/HZCAoS?p=preview
Example of decorator to add additional behaviour: https://coderwall.com/p/_zporq
To use it, just inject "$log" as you would $scope, $location etc.
Example here: http://docs.angularjs.org/api/ng.$log
Configure the $logProvider when defining the module to enable/disable debug.
Example: http://plnkr.co/edit/HZCAoS?p=preview
Example of decorator to add additional behaviour: https://coderwall.com/p/_zporq
Downloading File using curl
When you issue a "curl <url>" command, the output will be shown on stdout. This is great when trying to read a text response but most of the time, what you're doing is downloading a file.
The easiest way to do it is "curl -O <url>". This downloads the file with the same filename as the remote file.
The easiest way to do it is "curl -O <url>". This downloads the file with the same filename as the remote file.
Wednesday, December 18, 2013
CIDR Block Cheat Sheet
This page has a cheat sheet for coming up with CIDR blocks using the "a.b.c.d/x" notation: http://whatismyipaddress.com/cidr
Subscribe to:
Posts (Atom)