Skip to content

Instantly share code, notes, and snippets.

# -*- coding: utf-8 -*-
import os, datetime, re
from flask import Flask, request, render_template, redirect, abort
from werkzeug import secure_filename
# import all of mongoengine
from flask.ext.mongoengine import mongoengine
# import data models
import models
@johnschimmel
johnschimmel / datauri_to_s3.js
Created November 14, 2013 15:01
possibly code for saving data uri image to s3
var filename = 'my_data_pic.png';
var photoData = req.body.photoData;
// convert to buffer
var photo_buffer = new Buffer(b64str, 'base64');
// prepare database record
var photoPost = new Photo(); // create Blog object
// pick the Amazon S3 Bucket
@johnschimmel
johnschimmel / idea_update.py
Created October 22, 2013 18:32
Flask route for updating a record
@app.route("/ideas/edit/<idea_id>", methods=['GET','POST'])
def idea_edit(idea_id):
if request.method == 'POST':
try:
idea = models.Idea.objects.get(id=request.form.get('idea_id'))
except:
abort(404)
# populate the IdeaForm with incoming form data
@johnschimmel
johnschimmel / web_w_form.py
Created September 17, 2013 11:28
Flask web server example with form input for DWD week 3 http://itppyweb.herokuapp.com/notes/week_3
# -*- coding: utf-8 -*-
import os
# Retrieve Flask, our framework
# request module gives access to incoming request data
from flask import Flask, request
# create the Flask app
app = Flask(__name__)
@johnschimmel
johnschimmel / web.py
Created September 17, 2013 11:08
Flask simple webserver example #1
# -*- coding: utf-8 -*-
import os
# Retrieve Flask, our framework
from flask import Flask
# create the Flask app
app = Flask(__name__)
# Main Page Route
# Flask related imports
from flask import Flask, render_template, jsonify, abort, request, make_response, session, redirect, url_for
# Flask extensions
from flask.ext.mongoengine import MongoEngine
from flask_debugtoolbar import DebugToolbarExtension
# Flask blueprints
import companies
from companies.views import companies
var friendQuery = models.User.findById(userID);
friendQuery.exec(function(err, currentUser){
// filter Users by _id using .friends id array
// $in operator in Mongo allows you to use an array as search param
// http://docs.mongodb.org/manual/reference/operator/#AdvancedQueries-%24in
// in mongoose http://mongoosejs.com/docs/api.html#query_Query-in
var filter = { _id : { $in : currentUser.friends } };
// select the fields you want
@johnschimmel
johnschimmel / express_s3_aws-sdk-js.js
Created April 19, 2013 16:00
ExpressJS file upload to S3
exports.new_photo = function(req, res){
// Get File upload information
var filename = req.files.image.filename; // actual filename of file
var path = req.files.image.path; //will be put into a temp directory
var mimeType = req.files.image.type; // image/jpeg or actual mime type
// Create a new blog post
var photoPost = new Photo(); // create Blog object
@johnschimmel
johnschimmel / index.html
Last active September 4, 2021 10:35
Demo of loading Google Maps, fetching Markers with AJAX, Geocoding new location and POSTing new location with AJAX. http://dwd-nodejs-remoteapis.herokuapp.com/
<style>
/* IMPORTANT - must give map div height */
#map-canvas {
height:400px;
}
/* IMPORTANT - fixes webkit infoWindow rendering */
#map-canvas img {
max-width: none;
}
@johnschimmel
johnschimmel / create_form.html
Created March 15, 2013 11:29
Redisplaying html form with user input and form validation using MongooseJS
<label for="thenamebox">
{{#errors.name}}
<span class="help-block alert alert-error">{{type}}</span>
{{/errors.name}}
Name <input type="text" name="name" id="thenamebox" value="{{astro.name}}" required>
</label>