Skip to content

Instantly share code, notes, and snippets.

View edwardfung123's full-sized avatar

Edward FUNG edwardfung123

  • Hong Kong
  • 13:28 (UTC +08:00)
View GitHub Profile
@edwardfung123
edwardfung123 / README.md
Last active April 23, 2018 09:28
Creating a square image in Google AppEngine Python Standard Environment

Note for running this in local development server. You need to use install a older version of Pillow or PIL in order to use the image library. I tested this with Pillow 2.9 as suggested in here

runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /
script: main.app
- url: /(.*)
script: main.app
@edwardfung123
edwardfung123 / index.js
Last active August 4, 2017 05:13
Firebase cloud functions
const functions = require('firebase-functions');
// Create a function that trigger by HTTP
exports.helloWorld = functions.https.onRequest((request, response) => {
// console.log/info/warn/error will send the message to Cloud Logging
console.log('In helloworld!');
response.send("Hello from Firebase!");
});
@edwardfung123
edwardfung123 / jinja2_6_tojson_backport.py
Last active July 13, 2017 11:09
Backporting tojson filter from jinja2.9 to jinja2.6
def htmlsafe_json_dumps(obj, dumper=None, **kwargs):
"""Works exactly like :func:`dumps` but is safe for use in ``<script>``
tags. It accepts the same arguments and returns a JSON string. Note that
this is available in templates through the ``|tojson`` filter which will
also mark the result as safe. Due to how this function escapes certain
characters this is safe even if used outside of ``<script>`` tags.
The following characters are escaped in strings:
- ``<``
- ``>``
- ``&``
@edwardfung123
edwardfung123 / main.py
Created March 7, 2017 04:51
GAE Concurrency Test2 (With transaction)
import webapp2
import logging
from google.appengine.ext import ndb
@ndb.transactional(retries=10)
def update_bank_account(key, by=1):
account = BankAccount.get_by_id(key)
if account:
account.amount += by
account.put()
@edwardfung123
edwardfung123 / main.py
Last active March 7, 2017 04:49
GAE Concurrency Test1
import webapp2
from google.appengine.ext import ndb
class BankAccount(ndb.Model):
amount = ndb.IntegerProperty(default=0)
redirect_html = '''<html>
<head>