Skip to content

Instantly share code, notes, and snippets.

View chrisckchang's full-sized avatar
🎯
Focusing

Christopher Chang chrisckchang

🎯
Focusing
View GitHub Profile
@chrisckchang
chrisckchang / twitter-harvest-example
Last active December 20, 2015 18:29
twitter-harvest example execution
python twitter-harvest.py --db mongodb-uri --consumer-key consumer-key --consumer-secret consumer-secret --access-token access-token --access-secret access-secret -r --numtweets 100
@chrisckchang
chrisckchang / help contents
Last active December 20, 2015 18:29
twitter-harvest help contents
% python twitter-harvest.py -h
optional arguments:
-h, --help help
-r, --retweet include native retweets
-v, --verbose print harvested tweets in shell
--numtweets NUMTWEETS set harvest number
--user USER choose twitter user timeline
--db DB MongoDB URI
@chrisckchang
chrisckchang / test
Last active December 20, 2015 18:29
shell
python twitter-harvest.py -h
usage: twitter-harvest.py [-h] [-r] [-v] [--numtweets NUMTWEETS][--user USER]
--db DB --consumer-key CONSUMER_KEY
--consumer-secret CONSUMER_SECRET
--access-token ACCESS_TOKEN
--access-secret ACCESS_SECRET
optional arguments:
@chrisckchang
chrisckchang / quick-demo
Last active December 20, 2015 18:39
twitter cred provided
python setup.py install
python twitter-harvest.py --consumer-key CONSUMER_KEY --consumer-secret CONSUMER_SECRET --access-token ACCESS_TOKEN --access-secret ACCESS_SECRET
@chrisckchang
chrisckchang / JavaSimpleExample.java
Created September 9, 2013 08:18
Java Driver MongoClient using URI
/*
* Copyright (c) 2013 ObjectLabs Corporation
* Distributed under the MIT license - http://opensource.org/licenses/MIT
*
* Written with mongo-2.11.2.jar
* A Java class connecting to a MongoDB database given a MongoDB Connection URI.
*/
import java.net.UnknownHostException;
import com.mongodb.*;
@chrisckchang
chrisckchang / bad.js
Last active December 24, 2015 06:29
example express app without connection pooling (calls mongoclient in each function)
var express = require('express');
var mongodb = require('mongodb');
var app = express();
var MONGODB_URI = 'mongo-uri';
app.get('/', function(req, res) {
// BAD! Creates a new connection pool for every request
@chrisckchang
chrisckchang / good.js
Last active April 16, 2018 19:33
example express app that uses connection pooling (reuse db/coll object)
var express = require('express');
var mongodb = require('mongodb');
var app = express();
var MONGODB_URI = 'mongodb-uri';
var db;
var coll;
// Initialize connection once
@chrisckchang
chrisckchang / no
Created October 8, 2013 00:46
no pooling logs
Mon Oct 7 17:44:25.121 [initandlisten] connection accepted from 127.0.0.1:59002 #2 (1 connection now open)
Mon Oct 7 17:44:25.121 [initandlisten] connection accepted from 127.0.0.1:59003 #3 (2 connections now open)
Mon Oct 7 17:44:25.122 [initandlisten] connection accepted from 127.0.0.1:59004 #4 (3 connections now open)
Mon Oct 7 17:44:25.123 [initandlisten] connection accepted from 127.0.0.1:59005 #5 (4 connections now open)
Mon Oct 7 17:44:25.123 [initandlisten] connection accepted from 127.0.0.1:59006 #6 (5 connections now open)
Mon Oct 7 17:44:25.591 [initandlisten] connection accepted from 127.0.0.1:59007 #7 (6 connections now open)
Mon Oct 7 17:44:25.592 [conn7] end connection 127.0.0.1:59007 (5 connections now open)
Mon Oct 7 17:44:25.593 [initandlisten] connection accepted from 127.0.0.1:59008 #8 (6 connections now open)
Mon Oct 7 17:44:25.594 [initandlisten] connection accepted from 127.0.0.1:59009 #9 (7 connections now open)
Mon Oct 7 17:44:25.595 [initandlisten] connection accepted from
@chrisckchang
chrisckchang / mongoose-options.js
Last active August 13, 2019 13:31
mongoose connection options
/* Mongoose 3.8.x configuration settings
*
* As discussed in: www.blogpost.com
*/
var mongoose = require('mongoose');
var uriUtil = require('mongodb-uri');
/*
* Mongoose by default sets the auto_reconnect option to true.
@chrisckchang
chrisckchang / poolSize-5.js
Last active December 25, 2015 13:29
poolsize 5 example
var MongoClient = require('mongodb').MongoClient;
var URI = 'mongodb://localhost/test';
var options = { server : { poolSize : 5 } };
MongoClient.connect(URI, options,
function(err, db) {
//Create arbitrary long operation
db.eval('function (x) { while(x<10000000000){x++;} }',[0], { nolock: true }, function(err, result){