Wednesday, February 15, 2012

Learning how to programmatically generate webpages

Over the course of my life, I've worked with a variety of scripting languages to automate tedious processes. I generally detest tedious work because it is both a waste of time and not intellectually stimulating so I've written engines on top of AutoCAD and 3D modeling tools to automate the generation of complex objects using simple commands which are easy to represent in code and gets translated nicely into commands for interpretation... and so I am back at it again with trying to programmatically generate html sites and content.

The difference between generating scripts and html

Generating dynamic html pages is a very old problem on the internet, one that was first tacked by CGI scrips by the likes of PHP. I never got into the world of PHP scripts because I've always felt that the languages were so limited and ugly looking that I abhorred looking html code. Even the html code for many modern websites can look pretty nasty. The number of attributes per tag and more and the incredible amount of parameters that ones needs to jiggle about is a pain in the rear. Many of those problems have been solved with the advent of Cascading Style Sheets (CSS) which are used to maintain style and formatting through out a website.

I've started looking at templating engines online to learn the frameworks people use to generate html pages and have been pouring through lots and lots of documentation. Most documentation will describe basic syntax and provide a few examples to get you on your way. The biggest thing I generally think about is if doing something a certain way is the most efficient way of doing it.
Since Python has become my mainstay language, I've been looking into templating libraries for Python (for which there are many) and have seen that many of these languages like to embed Python code into content, which is a similar track to what PHP does by embedding PHP code using commented out html and writing code into content. The biggest difference between writing script generating code is different because one generally does needs not worry about "content" and simply needs to worry about generating sequential commands with different parameters. The highly structured nature of writing scripts makes code to generate scripts very easy, where as html content follows no such rule.

To give an example, perhaps I might define commands to generate a 3D object using the following commands:

def boat(width, length, height, location):
hull(width, length, height)
anchor()
motor()
mast()
shift(location)

and then I would simply call the boat function a few times to create a fleet of boats at different locations with varying sizes.

Using code in this manner is great to generate results with small permutations with respect to a general form. The same thing, unfortunately, does not transfer well to text content because text content is not easily generalized to a simple form with small permutations. Most text content is unique and writing a function to generate each and every paragraph is rather meaningless since the main purpose of writing functions is to shrink repetitious tasks into short commands to make life easier.

Since using code to generate text is unfeasible, the best place to use code in a website is to aim for the most structured portions of a website, which are the database components and formatting of content where the application of code is most likely to shine. There still is the ugly part of dealing with html. Should html be 1) completely generated by external functions or 2) should code be embedded into html to generate content? I still haven't figured which is the best way of tackling this problem just yet, but I think embedding python code into websites is ugly and I would much rather have structured data generated outside of an html template and injected later on.

It just means that I have some experimenting to do before adopting a templating framework.

When cash stops being your limiting factor

I once said at work that we should automate our boring experiments and one of my superiors said we didn't have the budget to do that. Hah! Little did they know what I could do on a shoe-string budget, spare computers and parts.

I still have the blood of a scrappy university student in me, but it bugs me that despite being surrounded by researchers and engineers, no one here really knows how to build their own stuff. And then it dawned upon me, the limiting factor to my success isn't funding, but time because eventually I'll just be able to find the resources I need to put whatever I need together. After that, many things about what makes a successful business, a booming economy or knowing how to become rich started to make sense.

Creating Value (and knowing where to find it)

It sounds obvious, but it's a subtle problem. Hell, I work for a megacorp and despite being surrounded with smart engineers, the company has been posting losses for years. If it were an easy problem to tackle, then every business out there would be profitable. But if you do investing, then you'd learn fairly quickly that many companies do lose money. Being able to create value and knowing how to find it is hard enough, then there is also the funding, timing and competition challenges too.

Creating a successful business requires many successful factors; should any one component be deficient, the business will either be impossible to start or will eventually fail. A successful business requires the logical "and" of all important factors, meaning that running a successful business is an exponentially hard problem.

When exponentially hard problems work in your favor

Suppose every business requires a set of factors to pass. A business will need a market, a product, a talented team, the financial resources, a supply chain and more to pull things off. I've already listed 5 different factors that all must pass before succeeding. But dealing with a hard business problem is a good thing because competitors have to have to deal with similar issues, meaning that it is just as likely for them to fail. The difference is that the more pieces of the business puzzle that you're able to understand and solve, it's one less step to getting a successful business online and creating value for your customers and yourself.

My limiting factor isn't funding

I've got a scrappy side as a result of being a born optimizer and generally frugal. I never had an allowance until after my younger brother started getting one before I did. I used to save up money through money packets at Chinese new years and visits with relatives. With a very uneven lump sum cash flows as a kid, I've been able to stretch those funds far enough that I'd be able to save money from year to year. Despite being adverse to spending money, I still was able to have a good time and learned a lot of about doing thing without the need for spending exuberant amounts of money.

That trait would carry me through university; looking for parts through dumpster diving and building parts through scrap metal at the machine shop turned out to be great skills. I've also seen small businesses put together by students that weren't capital intensive and produced significant returns. It just became apparent to me that huge amounts of capital isn't necessary to create successful businesses or to get things done. I would eventually do the same as well and I once had the Engineering Physics Student Society president come at me a little worried that "we were supposed to be a non-profit organization." I made good money for those guys :)

I remember a time after graduating where my main laptop broke down and the cost to repair one was about 70% of a new one and would take over a month to  get back. After being fed up with high repair prices and the risk of being without a computer for a long period of time, I would eventually buy a cheap EEE pc and put together a 1 GHz computer from salvaged parts from the university junk yard. I started learning how to code in Python because it was 1) free and 2) the computer didn't have enough memory to handle a full out install of Windows XP and Matlab running on top of it.

After starting work, I didn't need to ask for permission to buy expensive software like Matlab or Labview to do number crunching and managed to run under the radar, getting things done for nearly nothing. 4 years later, I managed to automate 2 of their machines and slashed a 7 day process down to 2 with my programming experience. The guys at work were floored and started ramping up prototype production thanks to the work I did. It became easy for me to talk my supervisors into buying me a new laptop and nice monitors to work on.

My limiting factor isn't funding; given time, I'll pretty much make it work. And then it hit me-- once you're not cash bound, you're just time bound.

The Time Constraint Problem

Time constraint problem is under appreciated because time as a resource is often taken for granted. Unfortunately time isn't plentiful and opportunities are moving targets-- what might have been a business chance today, may have been filled/saturated by the time you've made preparations to do something about it and then the process repeats. Time over time lost is a terrible situation to be in. Time constraints for smart people is poorly understood and I've found that I don't tackle this problem well because 1) Given time, I am smart enough to learn new things on my own and 2) finding people with the exact knowledge I need is sometimes hard.

The knowledge surface area to solving problems is broad and requires expertise in different areas which is hard for an individual to do alone. The process of discovering important things to know in each field of knowledge is also time expensive. In short, it's hard to be very successful as a lone wolf because you can do only so much within finite time. With smart people however, the price of learning and creating a function immediately drops and a team can get more done in less time making it easier to strike time sensitive opportunities. The challenge is to then bring together smart people, build quickly and leverage knowledge to create profitable business units.
This is exactly what I feel is happening in places like Silicon Valley, where serendipitous meetings of smart people and resources are bumping and reacting to create all sorts of interesting and profitable startups. There aren't a lot of places in the world that has the environment that makes silicon valley unique.

The first part of the question to first solve is to create a critical mass of smart, scrappy people together, where the exchange of skills and knowledge can occur to allow startups to be created. I think there needs to be tool for people to meet and exchange skills or share resources and form partnerships into great business ventures.

All I want right now is a bunch of scrappy but brilliant people to work with to churn out crazy projects lightening fast.

Tuesday, February 14, 2012

Saying goodbye to iPage

My webhosting service finally expired today, I paid about $50 for a year's subscription at www.ipage.com. It was fun to start off with, but in the end, the server that I would eventually try out putting on wordpress installations onto were way too slow for my liking. Considering that my renewal fees would jump to $100 after the first year, I decided against renewing my account.

In addition, I thought that iPage's renewal e-mail messages were sleazy, warning that my payments were "overdue" and warned that my account would be shut down; you guys have it wrong, I didn't like your slow servers and decided not to renew. As a saving grace, your customer support was decent. That's all that I could day.

I've since moved the one domain I had to a different registrar which I am happy with and have switched to using a headless computer that I bought for my serving needs. The computer is equipped with a i5 Core CPU from Intel and 8GB of ram. I had the whole thing put together for about $500. Compared to running a cloud server setup, having my own server is far more cheaper and easier to learn on.

I have since migrated some test installations of wordpress to the new server and playing around with mapping the domain name to my home computer, in addition to having scripts to automatically update my home address since I've got a dynamic IP. I've also finally figured out how to get the webserver to speak with back end code, meaning that I will be able to start putting together server side code to generate websites, which I am looking forward to doing.

There are some back end stacks that I'll be needing to learn, but with the advent of html5, there are a lot of cool things that I can do programatically do instead of doing things in a graphics editor, one of which is automatically generating beautiful buttons, tables and themes for websites. With the advent of webGL as well, making interesting web based interactive applications would be quite interesting as well.

One other thing, I've noticed how important learning good terminal based text editors since I've found myself interacting with code on the server while on the go. I've been picking up emacs recently and though learning new keybindings and how things work was a little annoying at first, I am starting to get a hang of it. Eventually, I'll have some applications out for the web in the coming months and if I have enough traffic to warrant it, I may consider moving to a cloud solution.

Wednesday, February 01, 2012

Some web hosts aren't all that good

A while back, I tried out iPage for some web hosting to see what it was like to run a site from a remote server. I was pretty dissatisfied with the result since the sight was really slow all the time. I didn't do much with it other than just use the site to keep online notes. Sort of a like a Dropbox on the go. Expiration for the service ends this month for me and with the cost to keep them as a host, I decided that it was better off ending my contract and moving on.

I have since started playing around with running my own little box as a host. It's rather cheap and fast on the local net. Still working with pointing domain names around and learning how to access the site from outside my LAN as I am playing around with nginx instead of the standard Apache.

Learning Linux administration stuff is kind of fun too.. couple that with some web programming it could possibly be an interesting adventure. Perhaps I could launch a service in the future? We shall see.