Skip to content

Instantly share code, notes, and snippets.

@andrewaylett
Forked from 0atman/blaze.md
Last active September 12, 2017 10:34
Show Gist options
  • Save andrewaylett/984aec8fc171cb6429b4290535eccfdf to your computer and use it in GitHub Desktop.
Save andrewaylett/984aec8fc171cb6429b4290535eccfdf to your computer and use it in GitHub Desktop.
Blaze is lit. It allows language-agnostic literate-style programming
#!/usr/bin/env sh
in=$1
script=`mktemp -p .`
awk '{ if (/^```/) { i++; next } if ( i % 2 == 1) { print } }' < $in > $script
chmod a+x $script
./$script
rm $script

#!blaze

Execution

This is a python script, executed with pex

#!pex flask flask_restful --

Imports

First the imports, this demo requires the flask_restful package. Then we set up the Flask wsgi application object, app and the api wrapper, api.

from flask import Flask
from flask_restful import Resource, Api

app = Flask(__name__)
api = Api(app)

Flask Restful resources

We define a single HelloWorld resource, that responds with a simple json object on a GET request.

class HelloWorld(Resource):
    def get(self):
        return {'hello': 'world'}

Routing

api.add_resource() wires the Resource class HelloWorld into the flask router at /.

api.add_resource(HelloWorld, '/')

Run Server

After we have created everything, we run the flask werkzeug server.

if __name__ == '__main__':
    app.run()

#!blaze

Execution

This is a basic python script

#!python

Pure Python Example

Simple shebang for simple python (or whatever) scripts

print("hi")

#!blaze

Execution

This is a python script, executed with pex

#!pex hy -c hy --

CORRECT

Blaze supports any interpreter, including pex-installed interpreters

(print "hi")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment