Skip to content

Instantly share code, notes, and snippets.

@johnschimmel
johnschimmel / sample_route.py
Created October 25, 2012 13:53
Sample of Flask receiving JSON
# If /json route receives header "application/json"
@app.route("/json", methods=['GET','POST'])
def json():
app.logger.debug("JSON received...")
app.logger.debug(request.json)
if request.json:
mydata = request.json # will be
@johnschimmel
johnschimmel / sample_route.py
Created October 21, 2012 19:48
Dictionary in dictionary to Jinja2 example
# put this in your app.py
@app.route("/nuts")
def nutbutter():
# nuts and review
nuttbutterReviews = {
'almond' : 'great',
'peanut' : 'okay',
'walnut' : 'what is this stuff?'
@johnschimmel
johnschimmel / getFavorites.py
Last active January 8, 2019 15:20
Download flickr favorites
import flickrapi
import urllib.request
import os.path
import json
# Make it work for Python 2+3 and with Unicode
import io
try:
to_unicode = unicode
except NameError:
@johnschimmel
johnschimmel / googleDocsAPI
Created December 22, 2011 16:40
Google Docs API + PHP + ClientLogin example
<?php
// Example of how to log into Google API with ClientLogin, good to use when you're not making a webapp.
// code taken and minimally updated from http://kovshenin.com/2009/10/google-docs-api-client-login-with-php-and-curl-1494/
// Construct an HTTP POST request
$clientlogin_url = "https://www.google.com/accounts/ClientLogin";
$clientlogin_post = array(
"accountType" => "HOSTED_OR_GOOGLE",
"Email" => "your@gmail.com",
@johnschimmel
johnschimmel / chrome_app_js.js
Last active October 18, 2018 19:09
Chrome App to Webpage communication
// be sure to update manifest to allow external connections,
// https://developer.chrome.com/extensions/messaging#external-webpage
/*
"externally_connectable" : {
"matches": ["*://diyability-capacita.appspot.com/*"]
}
*/
// Listen for incoming long lasting PORT connection from Webpage or extension
@johnschimmel
johnschimmel / index.html
Created October 13, 2014 21:24
angular draggable buttons
<html ng-app="dragTest">
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js" type="text/javascript"></script>
<script src="http://code.angularjs.org/1.2.1/angular.min.js" type="text/javascript"></script>
<script src="http://code.angularjs.org/1.2.1/angular-sanitize.min.js"></script>
</head>
<body class="container">
<div ng-controller="dragCtrlr">
@johnschimmel
johnschimmel / BGEventBus.js
Last active September 17, 2018 09:06
Pub Sub for Handling BG Messages
/******************************/
/* Bluegrass Event Bus PubSub */
/* from https://davidwalsh.name/pubsub-javascript */
/******************************/
var BGEventBus = (function(){
var topics = {};
var hOP = topics.hasOwnProperty;
return {
subscribe: function(topic, listener) {
@johnschimmel
johnschimmel / app.py
Last active September 6, 2018 00:27
Get remote JSON - sample flask route
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():
@johnschimmel
johnschimmel / sample_route.py
Created October 9, 2012 14:32
Sample flask route for form display and form validation
# this is our main page
@app.route("/", methods=['GET','POST'])
def index():
# get Idea form from models.py
idea_form = models.IdeaForm(request.form)
# if form was submitted and it is valid...
if request.method == "POST" and idea_form.validate():
@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