By Vasudev Ram
Clock live-coding image attribution
This is cool. I was just reading this HN thread:
Eve: Programming designed for humans (witheve.com)
which, BTW, is at the top of the HN front page at the time of this writing, and is about a new programming language called Eve from Chris Granger (and maybe others).
The Eve web site.
The home page of the Eve site says: [ Eve is a programming language and IDE based on years of research into building a human-first programming platform. From code embedded in documents to a language without order, it presents an alternative take on what programming could be - one that focuses on us instead of the machine. ]
Chris Granger may be known to some as the person behind Light Table, an innovative "open source IDE that lets you modify running programs and embed anything from websites to games", that was also discussed quite a bit on HN some time ago. I'm guessing Eve builds upon Light Table, for the IDE part of it.
[ Update: Chris's HN profile says: Co-founder of Kodowa, the company behind Eve and Light Table. YC alum. Ex-Microsoft Program Manager for C# and VB in Visual Studio. Chris also says in this comment on the HN thread, that the language part of Eve (it has other parts too) is a variant of datalog. ]
I had not checked out Light Table but I had briefly checked out Noir (another project by Chris), a micro-framework that allows you to rapidly develop web sites in Clojure, and had liked what I saw of it.
Anyway, in the HN thread about Eve, someone posted a link to a demo of live-coding a digital clock, using the Red language, which I had also checked out some months ago. I found Red and its goals interesting; reducing the complexity of modern software development is a big goal, another is being cross-platform (to desktop and server and mobile) and being a full-stack language - that last point, a bit like the D language - i.e. from being able to use assembly (Red may not supports that, but D does), all the way up to high levels of modeling power - but Red does have a lower level language, which Red is in fact built upon, called Red/System, which is supposed to be at the conceptual level of C - but with Red-style syntax). Red is at a somewhat early stage of development - v0.6 or so, but usable. I could even compile a simple Red program to an EXE and run the EXE - it was quite small too. Yes, RED has both an interpreter and a compiler - and like REBOL, the whole Red package is astonishingly small in size.
Red is a sort of successor to REBOL, but by a different person / team. I had played around with REBOL some years earlier and liked it too.
Here is the clock live-coding demo in Red - the drawing of the clock actually updates on the screen, live, as the code for the clock is being written. This works due to some language features of Red, including, as they say on that page:
[ Yes, livecoding (using native widgets!) in Red can be that simple. As you can see, there's no built-in "livecode" widget or feature, it's an emergent behavior resulting from the combination of existing Red features, homoiconicity being the most fundamental. ]
Interestingly, as the Wikipedia article (linked in the preceding sentence) says, assembly language (at least for systems using Von Neumann architecture) can also be considered to be homoiconic - because both code and data are just bytes in memory.
The image at the top of the post is a screenshot I took, of when the live-coding, and hence the (iterative and exploratory) drawing of the clock was in progress.
The image below is another screenshot taken after the clock was fully drawn. If you load that page in your browser, you can see the whole thing happening.
- Vasudev Ram - Online Python training and consulting Get updates on my software products / ebooks / courses. Jump to posts: Python DLang xtopdf Subscribe to my blog by email My ActiveState recipes Managed WordPress Hosting by FlyWheel
Showing posts with label web-frameworks. Show all posts
Showing posts with label web-frameworks. Show all posts
Saturday, October 29, 2016
Saturday, May 30, 2015
Moire with Spyre (a Python web framework)
By Vasudev Ram
The image above is of Uppsala Cathedral, Sweden, with its spires.
From the Spyre site:
Spyre is a Web Application Framework for providing a simple user interface for Python data projects. It is by Adam Hajari
I had come across Spyre recently via this post by Ian Oszvald:
Data Science Deployed – Opening Keynote for PyConSE 2015. More about Ian Oszvald here.
So I installed Spyre with the command:
Then I tried it out a little, this time just using one of the simple applications on the Spyre site, without any modifications, like I sometimes do.
Anyway, I ran this app with the command:
python simple_sine_example.py
and then browsed to:
http://127.0.0.1:8080/
where I then gave different values for the input parameter freq, to see what would happen. I found that running it with certain values of freq created interesting Moire patterns in the output; hence the title of this post.
Here are a few screenshots below that show those moire patterns:
With freq = 764:
With freq = 472:
With freq = 475:
With freq = 479:
Notice that in some cases, such as with the values of 472, 475 and 479 for freq, the small changes between those values results in significant changes in the output image. Not only that: for 472 and 479, the images are similar (look sine-wave-y), but for 475 (which is between the other two values), the image looks almost like straight vertical lines. (It isn't, of course; it's still a sine wave, but more compressed along the horizontal axis.) I've not analyzed the reason for this in detail; something to do with the periodicity of the sine function, is my rough guess, but I have seen similar phenomena when drawing other kinds of computer graphics on the screen; those also involved trigonometric functions such as sine and cosine.
Spyre away :)
P.S. In other news, I was recently profiled in PyDev of the Week.
- Vasudev Ram - Online Python training and programming Dancing Bison EnterprisesSignup to hear about new products or services that I create. Posts about Python Posts about xtopdf Contact Page
The image above is of Uppsala Cathedral, Sweden, with its spires.
From the Spyre site:
Spyre is a Web Application Framework for providing a simple user interface for Python data projects. It is by Adam Hajari
I had come across Spyre recently via this post by Ian Oszvald:
Data Science Deployed – Opening Keynote for PyConSE 2015. More about Ian Oszvald here.
So I installed Spyre with the command:
pip install dataspyrewhich in turn installed NumPy, pandas and matplotlib, all of which went through okay, though I saw some compiler / linker error messages scroll by as some compilation of C modules was happening (as part of the installation).
Then I tried it out a little, this time just using one of the simple applications on the Spyre site, without any modifications, like I sometimes do.
from spyre import server import matplotlib.pyplot as plt import numpy as np class SimpleSineApp(server.App): title = "Simple Sine App" inputs = [{ "input_type":"text", "variable_name":"freq", "value":5, "action_id":"sine_wave_plot"}] outputs = [{"output_type":"plot", "output_id":"sine_wave_plot", "on_page_load":True }] def getPlot(self, params): f = float(params['freq']) x = np.arange(0,2*np.pi,np.pi/150) y = np.sin(f*x) fig = plt.figure() splt1 = fig.add_subplot(1,1,1) splt1.plot(x,y) return fig app = SimpleSineApp() app.launch()As you can see, the structure / model of the code for a Spyre app does not seem to be very similar to that of, say, a Flask or a Bottle app. But then, there is no reason that it should be.
Anyway, I ran this app with the command:
python simple_sine_example.py
and then browsed to:
http://127.0.0.1:8080/
where I then gave different values for the input parameter freq, to see what would happen. I found that running it with certain values of freq created interesting Moire patterns in the output; hence the title of this post.
Here are a few screenshots below that show those moire patterns:
With freq = 764:
With freq = 472:
With freq = 475:
With freq = 479:
Notice that in some cases, such as with the values of 472, 475 and 479 for freq, the small changes between those values results in significant changes in the output image. Not only that: for 472 and 479, the images are similar (look sine-wave-y), but for 475 (which is between the other two values), the image looks almost like straight vertical lines. (It isn't, of course; it's still a sine wave, but more compressed along the horizontal axis.) I've not analyzed the reason for this in detail; something to do with the periodicity of the sine function, is my rough guess, but I have seen similar phenomena when drawing other kinds of computer graphics on the screen; those also involved trigonometric functions such as sine and cosine.
Spyre away :)
P.S. In other news, I was recently profiled in PyDev of the Week.
- Vasudev Ram - Online Python training and programming Dancing Bison EnterprisesSignup to hear about new products or services that I create. Posts about Python Posts about xtopdf Contact Page
Labels:
matplotlib,
moire,
NumPy,
pandas,
plotting,
python,
python-frameworks,
Spyre,
web-app-dev,
web-based-plotting,
web-frameworks
Friday, December 12, 2014
Project Enferno: RAD framework with Python / Flask / MongoDB / Redis
By Vasudev Ram

Just saw this via Python Weekly's email newsletter. Enferno seems to be a RAD (Rapid Application Development) framework of sorts, using Python, Flask, some Flask extensions, MongoDB AND MongoEngine, and Redis.
Enferno framework
I've worked on a project or two using Python, Flask and MongoDB (which is a NoSQL database), and found it a useful combination for developing apps relatively quickly. Enferno may be worth checking out, which I will do sometime later and may then blog about it.
Here is an article about NoSQL by Martin Fowler that may be of interest to newcomers to the field. Fowler and Pramod Sadalage have also written a book, NoSQL Distilled, which is linked to from Fowler's NoSQL article page. I've read Fowler's earlier book UML Distilled, a small and useful summary of UML, and it looks from the title that their NoSQL book may be on the same lines.
- Vasudev Ram - Dancing Bison EnterprisesSignup for email about interesting new stuff from me. Contact Page
Other Python posts | Posts about xtopdf
Just saw this via Python Weekly's email newsletter. Enferno seems to be a RAD (Rapid Application Development) framework of sorts, using Python, Flask, some Flask extensions, MongoDB AND MongoEngine, and Redis.
Enferno framework
I've worked on a project or two using Python, Flask and MongoDB (which is a NoSQL database), and found it a useful combination for developing apps relatively quickly. Enferno may be worth checking out, which I will do sometime later and may then blog about it.
Here is an article about NoSQL by Martin Fowler that may be of interest to newcomers to the field. Fowler and Pramod Sadalage have also written a book, NoSQL Distilled, which is linked to from Fowler's NoSQL article page. I've read Fowler's earlier book UML Distilled, a small and useful summary of UML, and it looks from the title that their NoSQL book may be on the same lines.
- Vasudev Ram - Dancing Bison EnterprisesSignup for email about interesting new stuff from me. Contact Page
Other Python posts | Posts about xtopdf
Labels:
databases,
Enferno,
Flask,
MongoDB,
nosql,
python,
python-frameworks,
Redis,
web-dev,
web-frameworks
Monday, November 25, 2013
PDF in a CherryPy
By Vasudev Ram
I've known about CherryPy, a minimalist Python web framework (originally created by Remi Delon), since its early days, and have tried it out some.
Recently I had the idea (*) of using CherryPy and my xtopdf PDF creation toolkit together, to serve PDF via a web app.
(*) I thought of it because of my earlier two posts, PDF in a Flask and PDF in a Bottle.
The difference between the Flask and Bottle apps and this CherryPy app, is that the former two use a form to submit the text to be converted to PDF, whereas this app lets you upload a file to convert to PDF. Here's the code for PDF in a CherryPy (pdf_cherry.py):
# pdf_cherry.py # Author: Vasudev Ram - http://www.dancingbison.com # Program to generate PDF using CherryPy and xtopdf. # Requires Reportlab v1.21 open source version. # Written using CherryPy 3.2.4 and Python 2.7.5. import os from PDFWriter import PDFWriter from file_utils import change_file_ext from textwrap import TextWrapper import os import cherrypy from cherrypy.lib.static import serve_file class Root(object): pass class Upload(object): def index(self): return """ <html><head><title>PDF in a CherryPy</title></head><body> <h3>PDF in a CherryPy</h3> <h4>Upload a text file to convert to PDF.</h4> <form action="text_to_pdf" method="post" enctype="multipart/form-data"> filename: <input type="file" name="uploadFile" /><br/> <input type="submit"/> </form> </body></html> """ index.exposed = True def text_to_pdf(self, uploadFile): txt_filename = uploadFile.filename pdf_filename = change_file_ext(txt_filename, ".txt", ".pdf") pw = PDFWriter(pdf_filename) pw.setFont("Courier", 10) pw.setHeader("Text file: " + txt_filename + \ " PDF file: " + pdf_filename) pw.setFooter("Generated by CherryPy, xtopdf and Reportlab") wrapper = TextWrapper(width = 120, drop_whitespace = True, break_long_words = True) for lin in uploadFile.file.readlines(): lines = wrapper.wrap(lin) for lin2 in lines: pw.writeLine(lin) pw.close() respons = "<html><head><title>PDF in a CherryPy</title></head>" respons += "<body><h3>PDF in a CherryPy</h3>" respons += "Text file: " + txt_filename + "<br/>" respons += 'PDF file: <a href="/https/jugad2.blogspot.com/download/?filepath=' + os.getcwd() + \ "\\" + pdf_filename + '">' + \ pdf_filename + '</a><br/>' respons += "</body></html>" return respons text_to_pdf.exposed = True class Download: def index(self, filepath): return serve_file(filepath, "application/x-download", "attachment") index.exposed = True def main(): root = Root() root.upload = Upload() root.download = Download() cherrypy.quickstart(root) if __name__ == '__main__': main() # EOF
Run it with:
python pdf_cherry.pyThen go to localhost:8080/upload in your browser, select a text file to convert to PDF, and click Submit. If there are no errors, you'll get another page with a link to download the generated PDF.
Here's a screenshot of pdf_cherry.py eating its own dog food, sort of :-)
I'm adding pdf_cherry.py to my xtopdf project on Bitbucket. [Update: Done.]
See other posts about Python, xtopdf, CherryPy, and web servers on my blog.
(The xtopdf posts are a subset of the Python posts, since xtopdf is written in Python.)
Users of CherryPy include Hulu and Netflix.
- Vasudev Ram - Python training and consulting
Labels:
CherryPy,
pdf,
PDF-creation,
PDF-generation,
python,
Python-web-frameworks,
web-frameworks,
xtopdf
Sunday, November 17, 2013
Book review: Instant Flask Web Development
By Vasudev Ram

Flask is a Python micro-framework that is fairly popular.
I had first blogged about it a couple of years ago, here:
Flask, new Python microframework
Recently, I had been working on a commercial Flask project for some time, when Packt Publishing asked me if I would review one of their books, Instant Flask Web Development. I did it. The review is below.
Review of book "Instant Flask Web Development", author Ron DuPlain, publisher Packt Publishing:
The book seems to be meant for people who already have some experience with Python.
Some parts of it that cover using Twitter Bootstrap and CSS in Flask templates, will also need knowledge of those topics.
Starts with a simple Hello World Flask app and explains some of the concepts involved.
Some of the topics covered in the book are:
- making a simple Flask app
- mapping URLs to functions (a.k.a. routing)
- HTTP request and response handling
- using databases, static file handling, and form and file uploads
- database CRUD (Create / Read / Update / Delete) operations
- sessions and authentication
- error handling
- deploying Flask apps using nginx and gunicorn
Uses Flask-Script to create command line tools to manage the Flask apps created.
Flask-Script is a Flask extension that provides support for writing external scripts in Flask.
(Flask has an facility for writing extensions that add to the functionality of the base Flask package, and there are multiple such extensions available.)
The book then starts on a scheduling application, which is used as a tutorial to illustrate various Flask features. This app allows the user to Create, Read, Update, Delete (i.e. CRUD) and List appointment records.
It shows how the use the route decorator of the Flask app object, to map various URLs that the app supports, to functions of the app that implement the actions specified by those URLs.
I noticed what seems to be an error in this section; in the middle of the code that maps the URLs to functions, there is this line:
They do specify URLs (on the Packt site) from where you can download the source code for the program examples in book, though.
The use of the Flask url_for() function is described.
There appears to be an error in this section of code:
Then it moves on to talk about how to handle different HTTP methods in Flask, as defined by the HTTP protocol, including GET, POST, etc.
It also mentions that instead of using the Flask route decorator, you can use a method, app.add_url_rule, as an alternative.
The section on using Jinja templates requires knowledge of CSS and JavaScript, and also Twitter Bootstrap and jQuery. The book gets a bit into Jinja features like macros.
Simple, Intermediate and Advanced sections are interspersed through the book (except for the first few sections, which are all Simple).
The book shows how to use some of Flask's error handling techniques, including how to generate a custom error page.
It ends with describing how to deploy a Flask app to production using nginx and gunicorn.
Other posts about Flask on this blog.
Other posts about Python on this blog.
- Vasudev Ram - Consulting and training on Python, Linux, open source

Flask is a Python micro-framework that is fairly popular.
I had first blogged about it a couple of years ago, here:
Flask, new Python microframework
Recently, I had been working on a commercial Flask project for some time, when Packt Publishing asked me if I would review one of their books, Instant Flask Web Development. I did it. The review is below.
Review of book "Instant Flask Web Development", author Ron DuPlain, publisher Packt Publishing:
The book seems to be meant for people who already have some experience with Python.
Some parts of it that cover using Twitter Bootstrap and CSS in Flask templates, will also need knowledge of those topics.
Starts with a simple Hello World Flask app and explains some of the concepts involved.
Some of the topics covered in the book are:
- making a simple Flask app
- mapping URLs to functions (a.k.a. routing)
- HTTP request and response handling
- using databases, static file handling, and form and file uploads
- database CRUD (Create / Read / Update / Delete) operations
- sessions and authentication
- error handling
- deploying Flask apps using nginx and gunicorn
Uses Flask-Script to create command line tools to manage the Flask apps created.
Flask-Script is a Flask extension that provides support for writing external scripts in Flask.
(Flask has an facility for writing extensions that add to the functionality of the base Flask package, and there are multiple such extensions available.)
The book then starts on a scheduling application, which is used as a tutorial to illustrate various Flask features. This app allows the user to Create, Read, Update, Delete (i.e. CRUD) and List appointment records.
It shows how the use the route decorator of the Flask app object, to map various URLs that the app supports, to functions of the app that implement the actions specified by those URLs.
I noticed what seems to be an error in this section; in the middle of the code that maps the URLs to functions, there is this line:
@app.route(...) and def appointment_edit(...).which is probably an inadvertent copy/paste from some of the text. But it would make the code fail to run, if copied as is from the ebook.
They do specify URLs (on the Packt site) from where you can download the source code for the program examples in book, though.
The use of the Flask url_for() function is described.
There appears to be an error in this section of code:
@app.route('/appointments/<int:appointment_id>/') def appointment_detail(appointment_id): edit_url = url_for('appointment_edit', appointment_id=appointment_id) # Return the URL string just for demonstration. return edit_urlThe function is called appointment_detail, but the url_for function is passed an argument 'appointment_edit'. In this case it would work, because it is just returning the URL string for display, not actually doing the appointment detail display.
Then it moves on to talk about how to handle different HTTP methods in Flask, as defined by the HTTP protocol, including GET, POST, etc.
It also mentions that instead of using the Flask route decorator, you can use a method, app.add_url_rule, as an alternative.
The section on using Jinja templates requires knowledge of CSS and JavaScript, and also Twitter Bootstrap and jQuery. The book gets a bit into Jinja features like macros.
Simple, Intermediate and Advanced sections are interspersed through the book (except for the first few sections, which are all Simple).
The book shows how to use some of Flask's error handling techniques, including how to generate a custom error page.
It ends with describing how to deploy a Flask app to production using nginx and gunicorn.
Other posts about Flask on this blog.
Other posts about Python on this blog.
- Vasudev Ram - Consulting and training on Python, Linux, open source
Labels:
book-reviews,
ebooks,
Flask,
Packt-Publishing,
python,
python-frameworks,
web-frameworks
Wednesday, September 18, 2013
PDF in a Flask
By Vasudev Ram
PDF in a Flask (pdf_flask.py) is a simple Flask web app that allows you to create a PDF file from text, over the web, by entering your text into a form and submitting it. It is written in Python, and uses my xtopdf toolkit for PDF creation, which in turn uses Reportlab.
PDF in a Flask is similar to my earlier post, PDF in a Bottle, but this app uses the Flask web framework instead of the Bottle web framework.
Here is the Python code for PDF in a Flask:
# PDF in a Flask. # pdf_flask.py # Description: Program to generate PDF from text, over the web, # using xtopdf, ReportLab and the Flask web framework. # It can be used to create short, simple PDF e-books. # Author: Vasudev Ram - http://dancingbison.com # Copyright 2013 Vasudev Ram # Tested with Python 2.7. # Version: 0.1 import traceback from textwrap import TextWrapper from PDFWriter import PDFWriter from flask import Flask, request app = Flask(__name__) @app.route("/pdf_book", methods=['GET', 'POST']) def pdf_book(): if request.method == 'GET': # Display the PDF book creation form. return ''' <form action="/https/jugad2.blogspot.com/pdf_book" method="post"> PDF file name: <input type="text" name="pdf_file_name" /> Header: <input type="text" name="header" /> Footer: <input type="text" name="footer" /> Content: <textarea name="content" rows="15" cols="50"></textarea> <input type="submit" value="Submit" /> </form> ''' else: # Create the PDF book from the posted form content. try: # Get the needed fields from the form. pdf_file_name = request.form['pdf_file_name'] header = request.form['header'] footer = request.form['footer'] content = request.form['content'] # Create a PDFWriter instance and set some of its fields. pw = PDFWriter(pdf_file_name) pw.setFont("Courier", 12) pw.setHeader(header) pw.setFooter(footer) # Get the content field. # Split it into paragraphs delimited by newlines. # Convert each paragraph into a list of lines of # maximum width 70 characters. # Print each line to the PDF file. paragraphs = content.split('\n') wrapper = TextWrapper(width=70, drop_whitespace=False) for paragraph in paragraphs: lines = wrapper.wrap(paragraph) for line in lines: pw.writeLine(line) pw.savePage() pw.close() return "OK. PDF book created in file " + pdf_file_name + ".\n" except Exception, e: traceback.print_stack() return "Error: PDF book not created.\n" + repr(e) + ".\n" if __name__ == "__main__": app.run(debug=True) # EOF
You can run the app with:
python pdf_flask.py
Then go to localhost:5000/pdf_book in your browser.
Enter some text into the big text box labeled Content. Also enter appropriate values into the other text boxes, such as PDF file name, header and footer.
When you click Submit, the PDF ebook will be created.
Here is a screenshot of the Guide to installing and using xtopdf, itself generated as a PDF book, using xtopdf and Python in a Flask web app.
- Vasudev Ram - Dancing Bison Enterprises
Contact me
Tuesday, July 24, 2012
Aspen, Python framework that uses simplates and the file system
By Vasudev Ram
Aspen, a different kind of Python framework
It makes some interesting use of the file system which I have not seen in other Python frameworks. Also, there are several testimonials about it by users, on its site. It's one of the smaller frameworks, not a large one like Django.
- Vasudev Ram - Dancing Bison Enterprises
Aspen, a different kind of Python framework
It makes some interesting use of the file system which I have not seen in other Python frameworks. Also, there are several testimonials about it by users, on its site. It's one of the smaller frameworks, not a large one like Django.
- Vasudev Ram - Dancing Bison Enterprises
Labels:
aspen,
frameworks,
python,
python-frameworks,
simplates,
web-frameworks
Subscribe to:
Posts (Atom)