Showing posts with label web. Show all posts
Showing posts with label web. Show all posts

Sunday, March 4, 2018

Browsers should be more configurable or programmatic (like any other software)

By Vasudev Ram


Browsers should be more configurable or programmatic (like any other software).

Just thought of this when my current browser tab was at extreme left, then I did Ctrl-T in Chrome (create new tab), and the new tab appeared at the extreme right (of the tab bar). There should be a way to change this, like to set the new tab to appear next to your current tab - to either the left or right of it, as you choose, or any other position you configure it to appear at (in your browser settings).

P.S. If any browser makers implement this, you know where to send the royalties ...

#web #innovation #design #UI #UX

- Vasudev Ram - Online Python training and consulting

Get updates (via Gumroad) on my forthcoming apps and content.

Jump to posts: Python * DLang * xtopdf

Subscribe to my blog by email

My ActiveState Code recipes

Follow me on: LinkedIn * Twitter

Are you a blogger with some traffic? Get Convertkit:

Email marketing for professional bloggers



Saturday, March 8, 2014

The html5lib Python library (and Animatron :-)

By Vasudev Ram



I came across the html5lib Python library recently. The site describes it thusly:

"html5lib is a pure-python library for parsing HTML. It is designed to conform to the WHATWG HTML specification, as is implemented by all major web browsers."

So it doesn't say explicitly that it is for parsing HTML5, though the library name includes "5" in its name. But I tried it out on a simple HTML5 document and it seems to be able to parse HTML5 - at least the few HTML5 elements I tried it on.

Here's the code I used to try out html5lib:
# test_html5lib.py
# A program to try out the html5lib Python library.
# Author: Vasudev Ram - www.dancingbison.com
import html5lib

f = open("html5doc.html")
tree = html5lib.parse(f)
print "tree:"
print repr(tree)
print
print "items in tree:"

for item in tree:
    print item
    for item2 in item:
        print "-" * 4, item2
        for item3 in item2:
            print "-" * 8, item3
And here is the output of running python test_html5lib.py:

<Element u'{http://www.w3.org/1999/xhtml}head' at 0x02B663C8>
<Element u'{http://www.w3.org/1999/xhtml}body' at 0x02B66488>
---- <Element u'{http://www.w3.org/1999/xhtml}header' at 0x02B664B8>
-------- <Element u'{http://www.w3.org/1999/xhtml}h1' at 0x02B66530>
-------- <Element u'{http://www.w3.org/1999/xhtml}h2' at 0x02B664E8>
-------- <Element u'{http://www.w3.org/1999/xhtml}h3' at 0x02B665F0>
---- <Element u'{http://www.w3.org/1999/xhtml}p' at 0x02B66650>
---- <Element u'{http://www.w3.org/2000/svg}svg' at 0x02B66BC0>
-------- <Element u'{http://www.w3.org/2000/svg}defs' at 0x02B66B60>
-------- <Element u'{http://www.w3.org/2000/svg}rect' at 0x02B66B30>
-------- <Element u'{http://www.w3.org/2000/svg}text' at 0x02B66BD8>
---- <Element u'{http://www.w3.org/1999/xhtml}footer' at 0x02B66BF0>

Here is the documentation for html5lib.

And speaking of HTML5, coincidentally, I came across Animatron via Hacker News, today:



Animatron is "a simple and powerful online tool that allows you to create stunning HTML5 animations and interactive content." Animatron is not really related to html5lib, except for the fact that both of them are about HTML5, but it looks cool. Check it out.

Hacker News thread about Animatron.

Enjoy.


- Vasudev Ram - Dancing Bison Enterprises

Contact Page

Saturday, March 1, 2014

The protocol-relative URL (for web links)

Seen via a Hacker News thread.

http://www.paulirish.com/2010/the-protocol-relative-url/

Monday, January 27, 2014

JackDB, a web-based database client

JackDB - http://www.jackdb.com/ - is a browser-based database client. It requires no installation.

Friday, November 15, 2013

A basic WSGI PDF server


By Vasudev Ram

Humpty Dumpty

While browsing the Python Reddit, I saw this post:

Python website tuts that don't use Django, in which the poster (user amnion) asked (excerpted for brevity):

"I'm trying to get a feel for how Python can be used for websites ... I want to familiarize myself with everything under the hood more. ... any resources that show how to make a website without using a framework?"

Many of the answers were interesting (and some had useful links to related reading), but I found this one particularly of interest (user name showed as [deleted] for some reason):


Here's a basic wsgi server (aka "enough to make a website without using a framework").

The variables path and method will contain the path portion of the requested url and the http verb (GET, POST...). "Real" web frameworks are built up around this interface, adding features for url routing, authentication, session management, persistence, etc.

Sans framework, you're free to produce html in any way you see fit. This ten line example runs on python's simple http server, but it will also run on apache/ mod_wsgi, google app engine, or anything supporting wsgi.

"""
basic_wsgi_server.py
Basic WSGI server in Python.
From: http://www.reddit.com/r/Python/comments/1eboql/python_website_tuts_that_dont_use_django/c9z3qyz
"""

from wsgiref.simple_server import make_server

host = 'localhost'
port = 8888

def app(environ, start_response):
    path = environ['PATH_INFO']
    method = environ['REQUEST_METHOD']

    response = 'This is the page for "{}"'.format(path)

    start_response('200 OK', [('Content-type', 'text/html')])
    return [response]

make_server(host, port, app).serve_forever()

I tried the above code (I named it basic_wsgi_server.py), and it worked.

Then, out of interest, I thought of modifying that basic WSGI server to make it serve PDF, using my xtopdf toolkit for PDF creation. Constant PDF content, though, not dynamically generated stuff. So here is the code of basic_wsgi_pdf_server.py:

# Basic WSGI PDF server in Python.
# Adapted from:

# http://www.reddit.com/r/Python/comments/1eboql/python_website_tuts_that_dont_use_django/c9z3qyz

from debug1 import debug1
from PDFWriter import PDFWriter
from wsgiref.simple_server import make_server

host = 'localhost'
port = 8888

def app(environ, start_response):
    debug1("Entered app")
    path = environ['PATH_INFO']
    method = environ['REQUEST_METHOD']
    print "path:", path
    print "method:", method

    #response = 'This is the page for "{}"'.format(path)

    lines = [
            "Jack and Jill went up the hill",
            "Humpty Dumpty sat on a wall,",
            "'You are old, Father William,' the young man said,",
            "Master of all masters"
            ]

    debug1("Before creating PDFWriter and setting its fields")
    pdf_filename = "Nursery-rhymes-and-stories.pdf"
    pw = PDFWriter(pdf_filename)
    pw.setFont("Courier", 12)
    pw.setHeader("Excerpts from nursery rhymes and stories")
    pw.setFooter("Generated by xtopdf and basic_wsgi_pdf_server")

    debug1("Before for loop to write the lines")
    for line in lines:
        pw.writeLine(line)
        pw.writeLine(" ")
    pw.close()

    debug1("Before with statement to read file contents")
    with open(pdf_filename, "rb") as fil:
        response = fil.read()

    #start_response('200 OK', [('Content-type', 'text/html')])
    debug1("Before start_response")
    start_response('200 OK', [('Content-type', 'application/pdf')])
    debug1("Before returning response")
    return [response]

debug1("Before make_server and serve_forever()")
make_server(host, port, app).serve_forever()

Ran it with:

python basic_wsgi_pdf_server.py

Note that I added a few calls to a function called debug1, which is a slightly improved version of the debugging function I mentioned in this post:

A simple Python debugging function

, in order to proactively get information about any problem with the program. But it turned out to have no issues - worked straightaway.

Here is a screenshot of the output:


References:

[1] Jack and Jill
[2] Humpty Dumpty
[3] Father William
[4] Master of all masters

Isn't my test data better than Lorem ipsum? :-)

- Vasudev Ram - Dancing Bison Enterprises





O'Reilly 50% Ebook Deal of the Day

Monday, April 22, 2013

pypng, pure Python module to encode/decode PNG


By Vasudev Ram



pypng is a pure Python library to read/write PNG images.

Here are some code examples of using pypng. Note: the actual library is called png.py, not pypng.py. So import that, not this :-)

I tried out a few of the examples, and they worked.

The image above uses the transparency feature of PNG.

- Vasudev Ram - Dancing Bison Enterprises

Monday, December 3, 2012

A glimpse into the future of open web science

This article is about how science may be in the future, with wide collaboration and the use of web/Internet technologies:

A Vision of Web Science | Climate Code Foundation

Found it interesting.

Some of the points are speculative, others are either possible or already real.

- Vasudev Ram
www.dancingbison.com

Monday, October 15, 2012

Glassboard, private sharing for Android from Sepia Labs (also for web and iPhone)

By Vasudev Ram

Glassboard is an Android app that allows only private sharing. It's by Sepia Labs, and developed by Nick Bradbury, who created famous / best-selling product HomeSite, and also FeedDemon.

UPDATE: You can also get Glassboard for the web and for iPhone.

- Vasudev Ram - Dancing Bison Enterprises

Wednesday, June 27, 2012

Launching Google +1 Recommendations Across the Web

Seen here:

http://googleplusplatform.blogspot.com/2012/06/launching-google-1-recommendations.html

It is in a preview phase as of now.

-Vasudev Ram
www.dancingbison.com

Wednesday, September 21, 2011

Flotype enabling easy large-scale real-time web apps? Berkeley founders, has funding, clients, claims revenue

By Vasudev Ram - dancingbison.com | @vasudevram | jugad2.blogspot.com

This is a quick post. Haven't checked out Flotype in detail but seems like it could be something, based on what I read so far.

Flotype is a Winter 2010 YCombinator startup that seems to be enabling easy-to-create large-scale real-time web apps via their product NowJS which seems to be based on Node.js. The 3 founders, all 19 years old (Hey, Bill, Larry, Sergey, Mark, ... :-) , are UC Berkeley engineering dropouts; the company has funding from YC and others, and may have clients and claims revenue on target to $1 million.

Check the links.

http://flotype.com

http://flotype.com/products

Flotype named in "Silicon Valley's Top 20 Startups":

http://www.businessinsider.com/20-silicon-valley-startups-to-watch#anyone-can-build-web-apps-with-flotype-1

Their main product is NowJS, seems based on Node.js, and is open-sourced:

http://nowjs.com/

- Vasudev Ram @ Dancing Bison