Skip to content

Instantly share code, notes, and snippets.

{
"name": "node-mongo-lab",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@types/bluebird": "^3.0.36",
"@types/mongodb": "^2.1.36",
"@types/node": "^6.0.54",
"typescript": "^2.1.4"
/usr/lib/gnome-terminal/gnome-terminal-server
import * as path from 'path';
import * as fs from 'fs';
import * as Promise from 'bluebird';
import { CWD } from './config';
// global variables
const LIB_PATH = path.resolve(CWD, 'lib');
@TonyPythoneer
TonyPythoneer / bluebird_lab.ts
Last active August 31, 2016 08:57
Pratice how to use promise module
var Promise = require('bluebird');
// You can input any argument in this function to test workflow of promise
function testPromise(input) {
let promise = Promise.resolve(input);
promise
.then(makeTask('Task1'))
.then(makeTask('Task2'))
.then(makeTask('Task3'))
.catch(makeErrorPredicate('Task1'), taskLog('Task1'))
@TonyPythoneer
TonyPythoneer / test_hasattr.py
Created March 4, 2016 02:56
hasattr vs dir
from datetime import datetime
from timeit import timeit
un = datetime.utcnow
timeit("hasattr(un, '__call__')", 'from __main__ import un') # 0.12641560214373812
timeit("'__call__' in dir(un)", 'from __main__ import un') # 5.613213103966963
@TonyPythoneer
TonyPythoneer / timestamp.js
Created February 13, 2016 16:03
mongoose 自动生成数据的创建时间和跟新时间
/**
* Timestamps 用于自动产生数据的创建时间和更新时间
*
* 使用方法:
*
* schema.plugin(require('./timestamp'));
*
*/
var timestampsPlugin = function (schema) {
if (schema.path('_id')) {
@TonyPythoneer
TonyPythoneer / api.js
Created February 11, 2016 01:20 — forked from fwielstra/api.js
An example NodeJS / Mongoose / Express application based on their respective tutorials
/* The API controller
Exports 3 methods:
* post - Creates a new thread
* list - Returns a list of threads
* show - Displays a thread and its posts
*/
var Thread = require('../models/thread.js');
var Post = require('../models/post.js');
upstream $repo_name {
server unix://$service_deployment_filename/websock.sock;
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name localhost;
import Queue
import threading
import urllib2
# called by each thread
def get_url(q, url):
q.put(urllib2.urlopen(url).read())
theurls = ["http://google.com", "http://yahoo.com"]
class SignUpSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('username', 'email', 'password', 'first_name', 'last_name')
def save(self, *args, **kwargs):
"""create user
"""
User.objects.create_user(**self.validated_data)
'''