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
command = { | |
'group' : { //mongodb group command | |
'ns' : 'pings', //the collection to query | |
'cond' : {'active.end' : { $gt: new Date() }}, //active.end must be in the future | |
'initial': {'count': 0}, //initialize any count object properties | |
'$reduce' : 'function(doc, out){ out.count++ }', | |
'key' : {'url': 1} //fields to group by | |
} | |
} | |
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
var APIeasy = require('api-easy'), | |
assert = require('assert'); | |
var suite = APIeasy.describe('/api'); | |
var urlRedir; | |
suite.discuss('Test Redirection API') | |
.use('localhost', 3000) | |
.setHeader('Content-Type', 'application/json') | |
.followRedirect(false) |
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
mongoose = require('mongoose'); | |
var GridStore = mongoose.mongo.GridStore, | |
Grid = mongoose.mongo.Grid, | |
ObjectID = mongoose.mongo.BSONPure.ObjectID; | |
exports.getGridFile = function(id, fn) { | |
var db = mongoose.connection.db, | |
id = new ObjectID(id), |
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 binary tree, each node is positive or negative integer, how to find a sub-tree, all the nodes sum is largest. | |
#include <iostream> | |
#include <limits> | |
using namespace std; | |
struct Node { | |
long data; | |
Node *lchild; |
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
// | |
//from 'introduce to algorithm' | |
//Precondition: the length of seq1 is equal to seq2, both of them are n. | |
7 int findMed(int seq1[], int seq2[], int n, int low, int high){ | |
8 if (low > high) | |
9 return -1; | |
10 int k = (high + low)/2; | |
11 if (k == n-1 && seq1[n-1]<=seq2[0]) | |
12 return seq1[n-1]; |
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
5 /** | |
6 * @func: the binary search fur descending order array. | |
7 */ | |
8 int binary_search(int arr[], int left, int right, int val){ | |
9 int ret = -1; | |
10 if (NULL == arr || left >= right) | |
11 return ret; | |
12 | |
13 while(left <= right){ | |
14 int middle = (left & right) + ((left ^ right) >> 1); |
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
8 const int LEN = 3; | |
9 struct node{ | |
10 int val; | |
11 int seq; | |
12 }monoto_Q[LEN]; | |
13 | |
14 void findAscend_MonotonousQueue(int arr[], int len, int qSize){ | |
15 if (arr == NULL || len <= LEN) | |
16 return; | |
17 int index = 0, tail = 0, head = 1; |
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
//build an Kth min heap, time k*lgk + (n-k)lgk | |
1 #include <iostream> | |
2 #include <iterator> | |
3 #include <algorithm> | |
4 using namespace std; | |
5 | |
6 void shiftdown(int arr[], int root, int right){ | |
7 int child = 2*root + 1; | |
8 |
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
给定一个整数N,比如N=100,有如下的初始有序序列位于[0,N-1]之间 [0 1] [4 5 6] [9 10 11] [20] [98 99]。设计一个数据结构保存这个初始序列,然后写一个函数,接受一个参数x,满足0<=x<=N-1,1)若x在该结构中不存在,出错;2)若x存在,返回x之后第一个不存在的数,并把该数写入结构中 |
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
9 /* | |
10 * binary search | |
11 */ | |
12 int findMin_binary(int arr[], int left, int right){ | |
13 if (NULL == arr) | |
14 return 0; | |
15 | |
16 while(left < right){ | |
17 if (arr[left] > 0) | |
18 return arr[left]; |
OlderNewer