Skip to content

Instantly share code, notes, and snippets.

View chiihuang's full-sized avatar

Chi-I Huang chiihuang

  • MongoDB
  • Greater Seattle Area, WA
View GitHub Profile
@chiihuang
chiihuang / node-folder-structure-options.md
Last active August 29, 2015 14:25 — forked from lancejpollard/node-folder-structure-options.md
What is your folder-structure preference for a large-scale Node.js project?

What is your folder-structure preference for a large-scale Node.js project?

0: Starting from Rails

This is the reference point. All the other options are based off this.

|-- app
|   |-- controllers
|   |   |-- admin
@chiihuang
chiihuang / Kill Multiple Op in MongoDB 3.2
Created June 13, 2016 14:47
Kill Multiple Op in MongoDB 3.2 when opid sometimes negative
// Change mydb.mycollection to your target ns
var result = db.currentOp();
result.inprog.filter(function(p){return p.ns === 'mydb.mycollection';}).map(function(p){return p.opid >= 0 ? p.opid : Math.pow(2,32) + p.opid;}).forEach(function(pid){ db.killOp(pid);});
nc -zv my.nfs.server.ip 111 2049
@chiihuang
chiihuang / cpp_split.cpp
Created May 6, 2017 05:13
How to split a string in C++
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
std::stringstream ss;
ss.str(s);
std::string item;
@chiihuang
chiihuang / cpp_trim
Created May 6, 2017 05:14
How to trim a string in C++
#include <iostream>
#include <string>
using namespace std;
string trim(string& str)
{
size_t first = str.find_first_not_of(' ');
size_t last = str.find_last_not_of(' ');
return str.substr(first, (last-first+1));
@chiihuang
chiihuang / lc-261.cpp
Created May 7, 2017 00:01
leetcode 261 solution
class Solution {
public:
bool validTree(int n, vector<pair<int, int>>& edges) {
vector<int> group(n + 1, -1);
for(auto e : edges){
int x = find(group, e.first);
int y = find(group, e.second);
if (x == y) return false;
group[x] = y;