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 / app.js
Last active August 29, 2015 14:24
Todolist API endpoints with database code
var express = require("express");
var path = require("path");
var bodyParser = require("body-parser");
var mongodb = require("mongodb");
var ObjectId = require("mongodb").ObjectID;
var app = express();
app.use(express.static(__dirname + "/public"));
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
@chrisckchang
chrisckchang / server.js
Last active September 25, 2015 22:54
Contact list API endpoints skeleton
// ****************************** CONTACTS API ROUTES ******************************************
// Generic error handler used by all endpoints.
function handleError(code, e, res, message) {
res.status(500).json({"error": message, "reason": e.message || "unknown"});
}
/* "/contacts"
* GET: grabs all contacts
* POST: creates a new contact
@chrisckchang
chrisckchang / rs-connect.js
Created April 23, 2015 05:21
replica set connection with nodejs native
/**
* MongoDB NodeJS Driver Production Connection Example
*
* Copyright (c) 2015 ObjectLabs Corporation
* Distributed under the MIT license - http://opensource.org/licenses/MIT
*/
var MongoClient = require('mongodb').MongoClient;
/**
@chrisckchang
chrisckchang / www.js
Created February 25, 2015 00:25
Node.js on GAE tutorial - www file
#!/usr/bin/env node
var debug = require('debug')('gcpNode');
var app = require('../app');
var mongodb = require('mongodb');
app.set('port', process.env.PORT || 3000);
mongodb.MongoClient.connect(MONGODB_URI, function(err, db) {
// do error handling here
if(err) throw err;
@chrisckchang
chrisckchang / app.yaml
Created February 24, 2015 01:08
Node.js on GAE tutorial - app.yaml
# Options are documented here: https://cloud.google.com/appengine/docs/managed-vms/config.
module: default
version: 1
runtime: custom
vm: true
api_version: 1
manual_scaling:
instances: 1
@chrisckchang
chrisckchang / dynamic.py
Last active August 29, 2015 14:15
dynamic pymongo database creation with auth
import pymongo
client = pymongo.MongoClient("MONGODB_ADMINDB_URI") #admin database URI
# Create a new database "dynamic"
db = client.dynamic
# Save doc to collection "test"
db.test.save({"foo":"bar"})
# Create a new database "dynamic2"
@chrisckchang
chrisckchang / connect-mongo.js
Last active August 29, 2015 14:15
connect-mongo replica set
var express = require('express');
var mongodb = require('mongodb');
var app = express();
var MONGODB_URI = 'mongodb-uri';
var db; //gives you a global db variable you can pass around
mongodb.MongoClient.connect(MONGODB_URI, function(err, database) {
if(err) throw err;
var MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
Db = require('mongodb').Db,
ReplSetServers = require('mongodb').ReplSetServers;
var url = 'MONGODB_URI';
// You can connect to any database here. Likely whichever connection you want to be persistent
MongoClient.connect(url, function(err, uriDb) {
if(err) console.log(err);
@chrisckchang
chrisckchang / edit.cs
Created January 24, 2015 01:38
changes we made to the C# driver
catch (MongoConnectionException e)
{
Console.WriteLine(e.ToString());
}
@chrisckchang
chrisckchang / ping.cs
Last active August 29, 2015 14:13
ssl ping test
using System;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
namespace Tester
{
class Test
{