Saturday, 1 September 2018

VuePress Examples

I Had great fun writing playing with vuepress and netlify putting together https://vuepress-examples.netlify.com/ however as usual I have to move onto other things and stop having fun.

Still a really useful way to put quick sites together especially for documentation and so on.

Tuesday, 3 September 2013

Who is Installing gbrainy?

While I was flicking through the metrics from installion.co.uk last night I was shocked by just how many hits the Debian and Ubuntu installation pages for gbrainy had had. It seems that from virtually out of nowhere a while back, an increasing number of people are trying to install it on a linux box and it made me wonder why.

The way I look at it there can only be two reasons:

  1. It's just really good and so is spreading virally.
  2. Everyone is being asked to install it by some educational or training body - maybe it's on some curriculum somewhere.

Having Goggled around and wasted more time than I really should have I came up with nothing except that Edubuntu comes with it installed (and surely schools are using that?)

Anyway, if you have any ideas then let me know. Meanwhile I'm just sitting here playingr gbrainy like the rest of them.

There's a neat article here

Thursday, 16 May 2013

Python _imaging cannot open shared object file

Okay so I'm using a 64 bit Linux and I was having a lot of trouble getting Calibre ebook tool to convert books into Kindle loving mobi format. I was getting a python error:

ImportError: libjpeg.so.62: cannot open shared object file: No such file or directory

Turns out all you need to do is

sudo apt-get install libjpeg62

You can test this by starting python and doing:

import _imaging

Friday, 1 March 2013

Installing Git and Virtualenv on Linux or Mac

For Debian/Ubuntu Linux:

sudo apt-get install git python-setuptools

For Redhat/Fedora Linux:

sudo yum install git python-setuptools

For Mac:

Install MacPorts and then:
sudo port install git python-setuptools

Continuing on for all of the above

sudo easy_install pip
sudo pip install virtualenv virtualenvwrapper

Now, you may want to set some defaults in your ~/.bashrc. My relevant entries look like this:



export WORKON_HOME=$HOME/Projects
export VIRTUALENVWRAPPER_HOOK_DIR=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_LOG_DIR=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

git config --global user.name "Terse Col"
git config --global user.email myemail@gmail.com
git config --global http.sslVerify false

Now away you go:

mkdir $HOME/.virtualenvs
source $HOME/.bashrc
mkvirtualenv mynewproject 
cdvirtualenv

Tuesday, 29 January 2013

Install Google App Engine on Ubuntu 12.10

Google App Engine  is currently on version 1.7.4 and Ubuntu has recently released Ubuntu 12.10 (Quantal Quetzal). Quantal Quetzal comes with Python 2.7 installed, and App Engine has been providing that version of Python as an option since February 2012. So if you are starting a new App Engine project, it's probably a good time to move to Python 2.7.

I'll explain briefly how you start a new project and there's a nice clean copy of the code at the bottom that you can cut and paste.

Let's get the show on the road. Choose a name for the project and create and switch to a virtual environment:

PROJ=gae_project
mkvirtualenv ${PROJ}
cdvirtualenv

Note that note that "--no-site-packages" and "--distribute" are now the defaults for mkvirtualenv. You don't even need to use "--python=python2.7" on Ubuntu 12.10.

Now we need to know what the latest version of App Engine is, but as of writing it's 1.7.4:

GAE=1.7.4
wget -O /tmp/gae.zip http://googleappengine.googlecode.com/files/google_appengine_${GAE}.zip
unzip /tmp/gae.zip

Now let's create an App Engine app. The app will need a name that has been created in the App Engine Console:

GAE_APP_NAME=dummy
mkdir -p gae_app/static

Now create the app.yaml file:

echo """application: ${GAE_APP_NAME}
version: development
runtime: python27
api_version: 1
threadsafe: true

default_expiration: 7d

handlers:
- url: /static
  static_dir: static
- url: .*
  script: wsgi_app.app
""" > gae_app/app.yaml

And finally the app itself:

echo """import webapp2

class MainPage(webapp2.RequestHandler):
  def get(self):
      self.response.headers['Content-Type'] = 'text/plain'
      self.response.out.write('Please replace me with a decent WSGI App Framework such as Flask')

app = webapp2.WSGIApplication([('/', MainPage)],
                              debug=True)
""" > gae_app/wsgi_app.py


And finally to run the development server:

python ./google_appengine/dev_appserver.py gae_app/

I hope that this has all been of some help to you. Did I miss anything? Please comment below.

Sunday, 13 January 2013

A Review of the Nagare Microframework

The analytics tell me that the keywords for this blog are "Best Python Framework" which is odd because I don't think I can pretend to have that answer. What I can do is point out what the differences are and let you find the one that suits you best. Nagare for example offers some concepts that you won't be used to if you come from using Django or Flask and the like.

If you have read Install Stackless Python on Ubuntu and could get stackless running the examples I showed you, then just follow these commands to get a stackless virtual environment running a nagare project called 'nagaredemo':

In the examples below, paste the code directly into the file
//negaredemo/demos/demos/app.py
and be aware that when you change the code you need to  restart the development server (Ctrl-C stops it.)

Hello World!



Okay, so example1 shows the basics of rendering a Welcome object.
http://localhost:8080/demos/
You'll notice immediately that we're not using a templating language here, but rather the built in Domain Specific Language (DSL). In reality you would use the DSL to build xhtml snippets and then use meld to insert them into templates. I've not used meld before, but it looks very straight forward - neat in fact. Now onto example2.

Callbacks



Here we've registered two callbacks on the DOM without having to explicitly declare the URL mappings. have a look at the rendered HTML to see how this has been implemented. Now, that's pretty handy.

Tiresome RESTful URLs



Example 3 takes that same code and augments it to allow us to have more ReSTful URLs. I'm not sure this is as obvious as I'd like, but it works I suppose.
http://localhost:8080/demos/Counter?value=7

Saving State Automatically


Nagare can hide the request/response object and global session from the developer. Object states are automatically saved in a server side session during the request/response round-trip. This allows for a more direct style of programming like in a desktop application.

And there's more


There's more documentation on the Nagere website itself, so scoot along there and see what else there is to offer. Nagare is built upon ConfigObj, WebOb, Paste, PEAK-Rules and lxml, so it's on good foundations. I'm told by HervĂ© Coatanhay that the next release will introduce non stackless support using pypy or CPython.

Conclusion


Nagare is able to implement Continuations and that's a great thing. However I'm not sure I like the way it obfuscates the implementation. I'd much rather be able to see what was going on.

For example, saving state between requests is nice, but is it secure? Do I need to plough through the code to find out? In my opinion it would have been better to have offered a structure that allows for others to plug in solutions/implementations.

The documentation is somewhat limited, which is probably because the community is still fairly small. However sinceteh project has been running since 2008, perhaps that's something to be concerned about.

Thanks to HervĂ© Coatanhay for suggestion the illustrative code snippets.