Skip to content

Instantly share code, notes, and snippets.

View danmaispace's full-sized avatar
🎯
Focusing

Danmai danmaispace

🎯
Focusing
  • www.danmai.com.cn
  • Shenzhen,China
View GitHub Profile
@danmaispace
danmaispace / gist:3863005
Created October 10, 2012 03:27
MongoDB: find by MongoDB ID
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);
@danmaispace
danmaispace / gist:3856368
Created October 9, 2012 03:16 — forked from padolsey/gist:527683
Javascript: detect ie
// ----------------------------------------------------------
// 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) {}
@danmaispace
danmaispace / APOD-app-tap-listener.js
Created February 28, 2012 08:02 — forked from edspencer/APOD-app-tap-listener.js
The app.js file for a simple Sencha Touch 2 APOD app
/**
* 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');
@danmaispace
danmaispace / snippet.txt
Created July 2, 2010 05:21
Ruby: Basecodec
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
#!/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
#