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
#!/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
#
@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
@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 / 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 / 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 / writeup.md
Created October 12, 2012 02:10 — forked from cespare/writeup.md
A Simple Webserver Comparison

This is a very simple benchmark comparing the response times of a few different webservers for an extremely simple response: just reply with a snippet of static json. It came up in discussion of a real-life service: in the actual server, a long-running thread/process periodically updates the state from a database, but requests will be served with the data directly from memory. It is imperative, though, that the latencies be extremely low for this service.

This comparison was partly inspired by this blog post.

Method

{
"color_scheme": "Packages/RailsCasts Colour Scheme/RailsCastsColorScheme.tmTheme",
"detect_slow_plugins": false,
"file_exclude_patterns":
[
".DS_Store",
".tags*",
"*.pyc",
"*.pyo",
"*.exe",
[
{ "keys": ["ctrl+s"], "command": "toggle_side_bar" },
{ "keys": ["ctrl+shift+."], "command": "erb", "context":
[
{ "key": "selector", "operator": "equal", "operand": "text.html.ruby, text.haml, source.yaml, source.css, source.scss, source.js, source.coffee" }
]
},
{ "keys": ["ctrl+shift+t"], "command": "todo"},
{ "keys": ["ctrl+shift+i"], "command": "reindent"}
]
#unbind C-b
#set -g prefix C-a
setw -g mode-keys vi
# split window like vim
# vim's defination of a horizontal/vertical split is revised from tumx's
bind s split-window -h
bind v split-window -v
# move arount panes wiht hjkl, as one would in vim after C-w
bind h select-pane -L
@danmaispace
danmaispace / gist:5640898
Created May 24, 2013 02:31
search replace on regular expressions in Sublime Text 2
search replace on regular expressions in Sublime Text 2
Find: /images/(\w+).gif
Replace: /assets/\1.gif
Will replace "/images/logo.gif" to "/assets/logo.gif".