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
// save the newAstro to the database | |
newAstro.save(function(err){ | |
if (err) { | |
console.error("Error on saving new astronaut"); | |
console.error(err); // log out to Terminal all errors | |
// rebuild the templateData page | |
var templateData = { | |
page_title : 'Enlist a new astronaut', | |
errors : err.errors, // include the error msg objects keys = fieldnames |
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 mongoose = require('mongoose'); | |
var Schema = mongoose.Schema; | |
// validation function | |
var nameValidation = function(val) { | |
console.log("inside name validation"); | |
console.log(val); | |
if (val.length >= 5) { | |
return true; |
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
exports.note = function(req, res) { | |
// get the hidden value: video.id | |
var videoId = req.body.videoId; | |
// Query for video with the matching videoId | |
Video.findOne({videoId:videoId}, function(err, result) { | |
console.log('videoId: ' + videoId); | |
// Prepare new note for video with the form data | |
var noteData = { |
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
// Create a HTTP server on port 8000 | |
// Send plain text headers and 'Hello World' to each client | |
var http = require('http'); | |
var port = process.env.PORT || 8000; | |
var counter = 0; | |
http.createServer(function (req, res) { | |
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
/* | |
-------------------------------- | |
USAGE | |
Start Server, navigate to code directory in Terminal: | |
> node tcp_echo.js | |
In another new Terminal window, connect to TCP Echo server | |
> telnet localhost 5000 |
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
# -*- coding: utf-8 -*- | |
""" | |
A real simple app for using webapp2 with auth and session. | |
It just covers the basics. Creating a user, login, logout | |
and a decorator for protecting certain handlers. | |
Routes are setup in routes.py and added in main.py | |
""" |
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
""" | |
Run this script from terminal, be sure to have one image in the same directory as the script. Update the sourceFilename variable to the filename of the image. | |
I ran this with http://cdn.theatlanticwire.com/img/upload/2012/10/03/AP226995126585/large.jpg saved as 'running-teddy.jpg' | |
""" | |
import os | |
import Image | |
import ImageOps |
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 flask import jsonify | |
@app.route('/data/ideas') | |
def data_ideas(): | |
# query for the ideas - return oldest first, limit 10 | |
ideas = models.Idea.objects().order_by('+timestamp').limit(10) | |
if ideas: |
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
import os | |
from flask import Flask, request, render_template # Retrieve Flask, our framework | |
import requests | |
app = Flask(__name__) # create our flask app | |
# this is our main page | |
@app.route("/") | |
def index(): |
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
# -*- coding: utf-8 -*- | |
from mongoengine import * | |
from flask.ext.mongoengine.wtf import model_form | |
from datetime import datetime | |
class Comment(EmbeddedDocument): | |
name = StringField(required=False) | |
comment = StringField() |