My online tech scrapbook where I keep my notes in case I need to look them up later
Sunday, June 22, 2014
Article on Using Recruiters
Interesting article, could use for future reference: http://firstround.com/article/Ive-Worked-with-Hundreds-of-Recruiters-Heres-What-I-Learned
Tuesday, June 10, 2014
Git Checkout to a Specific Commit
In Git, to get your workspace code to that of a specific commit:
To go back to HEAD e.g. in the "master" branch:
References:
git checkout 0fe3207
|
To go back to HEAD e.g. in the "master" branch:
git checkout master
|
References:
Saturday, May 31, 2014
Android ArrayAdapter getView's "convertView" Parameter
The ListView and ArrayAdapter doesn't create a new View for every item in the list. Instead, view items are pooled and recycled as the user scrolls through the list. So what "getView" does is that sometimes it requires you to create a new View (when "convertView" is null) or to re-use an existing view (when "convertView" is not null).
Therefore, in getView, you should do a null check for convertView. If it is null, create a new View, otherwise, just reuse it.
Therefore, in getView, you should do a null check for convertView. If it is null, create a new View, otherwise, just reuse it.
Monday, May 26, 2014
Android Setting Layout Parameters Programmatically
This is how it's done:
But the catch is, if you are adding these views programmatically in the first place, you will need to ensure that the above code runs only after the views have been added to the parent.
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)view.getLayoutParams();
params.setMargins(10, 0, 0, 0);
|
But the catch is, if you are adding these views programmatically in the first place, you will need to ensure that the above code runs only after the views have been added to the parent.
Android Design Resolution
If using "dp" i.e. density independent pixels, dp values specified in the app should be based on a 320x480 design resolution.
Sunday, May 25, 2014
Android Center Vertically in Parent
Instinctively, it's to use this, but sometimes it works, and sometimes it doesn't work:
When it doesn't work, try this:
Not sure why but that's just how it is.
android:layout_centerVertical="true"
|
When it doesn't work, try this:
android:layout_gravity="center_vertical"
|
Not sure why but that's just how it is.
Monday, May 12, 2014
AngularJS Two Way Data Binding Only Works One Way Error
There is a problem with two way data binding in AngularJS where the data binding only works one way. This happens when the HTML element bound to the data is inside an automatically created child scope (e.g. inside an ng-include or ng-repeat block).
Let's say the following code is within an ng-include block:
If $scope.valueX is set as "100" in the controller, it will show "100" in the input box above. However, if the user updates the value, this value won't be reflected in "$scope.valueX", because in this case the child scope will create a copy of that, different from the parent scope value. This results in two way data binding only working one way.
One solution is to use objects rather than primitives e.g.
But it does not work all the time. In the case it doesn't work, another option is to explicitly reference the $parent scope:
Reference: https://github.com/angular/angular.js/wiki/Understanding-Scopes
Let's say the following code is within an ng-include block:
<input ng-model="valueX" />
|
If $scope.valueX is set as "100" in the controller, it will show "100" in the input box above. However, if the user updates the value, this value won't be reflected in "$scope.valueX", because in this case the child scope will create a copy of that, different from the parent scope value. This results in two way data binding only working one way.
One solution is to use objects rather than primitives e.g.
<input ng-model="anObject.valueX" />
|
But it does not work all the time. In the case it doesn't work, another option is to explicitly reference the $parent scope:
<input ng-model="$parent.anObject.valueX" />
|
Reference: https://github.com/angular/angular.js/wiki/Understanding-Scopes
Tuesday, April 22, 2014
MongoDB MapReduce Notes
A few things that stumped me for a while and took me some time to figure out:
- 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.
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
Subscribe to:
Posts (Atom)