Sunday, October 19, 2008

Fear Factor presentation from Tim Bray

Tim Bray gave a great talk/presentation at FOWA in London titled Fear Factor. In speach he outlined some general tips and strategies for web developers to survive this economic crisis.

He also created series of blog posts starting with "On tough times" that go more in depth to each of his major survival points:

Make sure you read comments on individual posts.

In presentation and later in blog post he mentioned his belif that current cloud computing offers lead to vendor lock-in. There are some very insightful comment on his original post (Get In the Cloud) and the follow up Lockin-Free Cloud? (my comment on the topic)

But my biggest take form his talk was when he talked about old javaEE an php code bases. There will be good opportunities for people to work with them, since people will be less likely to risk something new (read anything from ruby or python) and will rather patch the old code.

I am just developing application in Django, but after I finish with it I think I'll put some of my time in learning new PHP [1] just in case. [2]

Also like he said this is good time to add to your skills. On my immediate howto is jQuery (and js in general), and finally learn ruby on rails. (If you get to create new project from scratch you are not limited to old languages and tools )

[1]: last time I worked with php it was still at 4.*
[2]: I have never worked with javaEE, only plain java in University and some desktop apps. I don't know if its worth learning it form schrach at this time though.

Saturday, October 11, 2008

Code highlighting on blogger

Ok lets see if new highlighter works.


#! /bin/env python

def python_funct():
a = a + b
print "Hello Highlighted code"

class Foo(Bar):
pass


So how to do it?
Simply use googles own client side code highlighting library .


Its easy. Just include this two lines at top of your blogger template:

<link href="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js"> </script>



And change body tag in your template to include onload="prettyPrint()":
>
...
<body onload='prettyPrint()'>
...


And thats it. Now all you have to do when you want highlighted piece of code in your blog is to use.


<pre class="prettyprint">
... # Your code goes here
</pre>
EDIT: Urls to prettyfy.js and prettyfy.css were wrong. They are fixed now.

Creating new python project

How to set up development environment for new python project.

Some of the tools I use:

  • virtualenv - creates self contained python enviroment (you can even ignore systems site-packages). Its usefull for installing new python libraries or eggs that you may not want to install systemwide.
  • paster - (from pastescript)it helps you with crating project skeleton (including setup.py and eggs config). If this is wsgi project you can also use it for deploying.
  • nose - my preferred python testing framework. One of its biggest benefits is that it works with existing unittest tests and doctests.
So tipicly for crating new project cli session would look like:


$ cd py.virt/
py.virt$ virtualenv --no-site-packages Foo
(...)
py.virt$ cd Foo && source bin/activate
(Foo)$
(Foo)$ easy_install nose
Searching for nose
Reading http://pypi.python.org/simple/nose/
(...)
(Foo)$ easy_install pastescript
Searching for pastescript
Reading http://pypi.python.org/simple/pastescript/
(...)
(Foo)$
(Foo)$ paster create Foo
Selected and implied templates:
PasteScript#basic_package A basic setuptools-enabled package

Variables:
egg: Foo
package: foo
project: Foo
(...)
(Foo)$
(Foo)$ cd Foo
(Foo)$ python setup.py develop # creates registers with python so that ' import Foo works'
running develop
running egg_info
writing Foo.egg-info/PKG-INFO
(...)


Now our package should be created and registered with python. Lets see:

(Foo)$ python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo
>>> dir(foo)
['__builtins__', '__doc__', '__file__', '__name__', '__path__']
>>>


Now we can start coding.

Sunday, February 3, 2008

Test post - Posting source code

This is a test post


Inside Block quote
def main:
print "blah"



Inside code block
def main:
print "blah"



Inside Block and code quote
def main:
print "blah"


Inside pre block
def main:
print "blah"

Seems the best way (easiest) to post source code into blog
is using <pre> tags with following css:

pre {  
font-family: "Courier New", Courier, mono;
font-size: 12px;
color: #000000;
background-color: #FFFFCC;
padding-top: 8px;
padding-right: 8px;
padding-bottom: 8px;
padding-left: 8px;
border: #000000;
border-style: dashed;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
width:auto;
}