This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How to find a document by using MongoDB ID | |
published by chao on Thu, 01/05/2012 - 22:48 | |
Categories: | |
TechnologyDatabase | |
MongoDBObjectID | |
When obtain the ID from request parameter: 4eec06b12dacbe7275000005, it is string, however, the format of _id is ObjectID. String and ObjectID are different types. MongoDB driver provides a function to serialize the 12 character string into a ObjectID type. | |
var ObjectId = collection.db.original.bson_serializer.ObjectID; | |
collection.findOne({'_id': ObjectId(idString)}, console.log); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------------------------------------- | |
// A short snippet for detecting versions of IE in JavaScript | |
// without resorting to user-agent sniffing | |
// ---------------------------------------------------------- | |
// If you're not in IE (or IE version is less than 5) then: | |
// ie === undefined | |
// If you're in IE (>=5) then you can determine which version: | |
// ie === 7; // IE7 | |
// Thus, to detect IE: | |
// if (ie) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* The final thing is to add a tap listener that is called whenever the user taps on the screen. | |
* We do a quick check to make sure they're not tapping on the carousel indicators (tapping on | |
* those indicators moves you between items so we don't want to override that), then either hide | |
* or show the info Component. | |
*/ | |
Ext.Viewport.element.on('tap', function(e) { | |
if (!e.getTarget('.x-carousel-indicator')) { | |
if (titleVisible) { | |
info.element.removeCls('apod-title-visible'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseCodec | |
def self.base_n_decode(s, alphabets) | |
n = alphabets.length | |
rv = pos = 0 | |
charlist = s.split("").reverse | |
charlist.each do |char| | |
rv += alphabets.index(char) * n ** pos | |
pos += 1 | |
end | |
return rv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# = gist(1) | |
# | |
# == USAGE | |
# gist < file.txt | |
# echo secret | gist -p # or --private | |
# echo "puts :hi" | gist -t rb | |
# gist script.py | |
# |
NewerOlder