Date: Tag: Website
And so the work on this page slowly continues. On a better note, recently I discovered AppFog and gave it the free account a try. In case you have not heard about it, AppFog is a PaaS(Platform as a Service). Basically, PaaS is similar to a fancy free hosting, but a bit different. The workflow is as follow: create an app/project, select a service (PHP, NodeJS, Rail, etc), select a cloud service to create a VM, done! Unlike a free hosting, you don't transfer files via FTP. You need Ruby command line to install "af" command line tool. Using af, you can upload your code for the project to the host. Another difference is the app/project/service system. On a free hosting, you own a folder and manage everything under. In PaaS, each project is its own folder.
Anyways, give it a try and see how you like it. In fact, I have setted up a personal MediaWiki on it.
Update Website
Date: Tag: Website
So GoFreeServe took down my site after a month of inactivity, just like most free host... So, I am back to hosting static pages with CSS and javascript. Just few weeks ago I heard about Site44 web hosting. However, it is unique than other free hostings because it is free hosting via *your* DropBox's public link. But since I am using DropBox for something else, I ended up using a similar service but with Google Drive. The service is called http://gdriv.es/. You can find more details at http://gdriv.es/massmind
Site and Progress
Date: Tag: C++, Blog
So, the last couple weeks I have been somewhat occupied with Olympics (and the lack of coverage by NBC). In the mean time I finally got around to writing base64 encoding and decoding (see [1] and [2]) in C. These functions only take the input chars and split out the values. You can extend this to be a class that takes a file or a stream (as a filter).
As for this site, it is a work in progress. You can see it here -- http://kainr2.gofreeserve.com/blog/latest
Reference:
[1] Encode base64: Show | Hide
//------------------------------------------------------------------------------ /// Convert given 3 bytes of characters to 4 chars in base64 /// /// @args[out] output An array for storing the output /// @args[in] input An array of chars (3 bytes) /// @args[in] nBits How many bytes of valid input /// /// @return Number of bytes written /// int encode64(char output[], const char* const input, int nBytes) { // Define binary map for each of the three chars // 0000-0011 1111-2222 2233-3333 // * http://en.wikipedia.org/wiki/Base64 static const int BYTE0 = 252; static const int BYTE1A = 3; static const int BYTE1B = 240; static const int BYTE2A = 15; static const int BYTE2B = 192; static const int BYTE3 = 63; static const char TERM_CHAR = '='; static const int MAX_OUTPUT = 4; // Error check: Check for how many bytes are going to be read if (nBytes < 1 || nBytes > 3) { printf("Error: incorrect amount of bytes (%d)\n", nBytes); return 0; } // Error check: size of output if (sizeof(output)/sizeof(char) < static_cast(MAX_OUTPUT)) { printf("Insufficient amount of output buffer (%d)\n", sizeof(output)/sizeof(char)); return 0; } // Read each char input int nBytesOut = nBytes+1; if (nBytes>=1) { output[0] = (input[0] & BYTE0) >> 2; output[1] = ((input[0] & BYTE1A) << 4) + ((input[1] & BYTE1B) >> 4); output[2] = output[3] = TERM_CHAR; } if (nBytes>=2) { output[2] = ((input[1] & BYTE2A) << 2) + ((input[2] & BYTE2B) >> 6); } if (nBytes==3) { output[3] = (input[2] & BYTE3); } // Convert to base64 -- five sets // (1) 0-25 [A-Z]=[65-90] // (2) 26-51 [a-z]=[97-122] // (3) 52-61 [0-9]=[48-57] // (4) 62 [+]=[43] // (5) 63 [/]=[47] // * http://en.wikipedia.org/wiki/Base64 // * http://www.asciitable.com/ for (int i=0; i < nBytesOut; i++) { if (output[i]<=25) { output[i] += 65; } else if (output[i]<=51) { output[i] += 71; // 97-26 } else if (output[i]<=61) { output[i] -= 4; // 48-52 } else if (output[i]==62) { output[i] = 43; } else if (output[i]==63) { output[i] = 47; } } return nBytesOut; }
[2] Decode base64: Show | Hide
//------------------------------------------------------------------------------ /// Convert given 4 chars to original 3 bytes /// /// @args[out] output Output buffer (3 bytes) /// @args[in] input An array of chars (4 chars) /// @args[in] nBytes How many bytes to read from input /// /// @return Number of bytes written /// int decode64(char output[], const char* const input, int nBytes) { // Define binary map for each of the three chars // 0000-0011 1111-2222 2233-3333 -- output-input bit map // 7654 3210 7654 3210 7654 3210 -- bits index of output // // 000000 001111 111122 222222 -- input-output bit map // * http://en.wikipedia.org/wiki/Base64 static const int BYTE0 = 63; static const int BYTE1A = 48; // 32+16 static const int BYTE1B = 15; static const int BYTE2A = 60; static const int BYTE2B = 3; static const int BYTE3 = 63; static const char TERM_CHAR = '='; static const int MAX_OUTPUT = 3; // Error check: Check for how many bytes are going to be read if (nBytes < 2 || nBytes > 4) { printf("Error: incorrect amount of bytes to read(%d)\n", nBytes); return 0; } // Error check: size of output if (sizeof(output)/sizeof(char) < static_cast(MAX_OUTPUT)) { printf("Insufficient amount of output buffer (%d)\n", sizeof(output)/sizeof(char)); return 0; } // Convert from -- five sets // (1) 0-25 <- [A-Z]=[65-90] // (2) 26-51 <- [a-z]=[97-122] // (3) 52-61 <- [0-9]=[48-57] // (4) 62 <- [+]=[43] // (5) 63 <- [/]=[47] // (*) Skip terminal char // * http://en.wikipedia.org/wiki/Base64 // * http://www.asciitable.com/ char buffer[4]; for (int i=0; i < 4; i++) { buffer[i] = (i < nBytes) ? input[i] : TERM_CHAR; if (buffer[i]>=65 && buffer[i]<=90) { buffer[i] -= 65; } else if (buffer[i]>=97 && buffer[i]<=122) { buffer[i] -= 71; } else if (buffer[i]>=48 && buffer[i]<=57) { buffer[i] += 4; } else if (buffer[i]==43) { buffer[i] = 62; } else if (buffer[i]==47) { buffer[i] = 63; } } // Read each char input int nBytesOut = nBytes-1; output[0] = output[1] = output[2] = 0; // clear the buffer if (nBytes>=2) { // Take th lower 6 bits from buffer[0] to highest bits 7-2 of output[0] output[0] = ((buffer[0] & BYTE0) << 2) + ((buffer[1] & BYTE1A) >> 4); } if (nBytes>=3 && buffer[2]!=TERM_CHAR) { output[1] = ((buffer[1] & BYTE1B) << 4) + ((buffer[2] & BYTE2A) >> 2); } if (nBytes==4 && buffer[3]!=TERM_CHAR) { output[2] = ((buffer[2] & BYTE2B) << 6) + (buffer[3] & BYTE3); } return nBytesOut; }
BBC Documentary -- 'The Men Who Made Us Fat'
Date: Tag: Documentary, Health
Earlier this week, I saw part of the three hours BBC documentary called 'The Men Who Made Us Fat' on youtube. This documentary looks into the causation of why obesity is spreading rapidly among the British (and American) people. Looking at U.S. stat alone, the percentage of obese adults (age: 20 to 74) rises from appoximation 10% in 1950s to 30% early 2000s [See Wiki:Obesity_in_the_United_States]. Here are some of the key highlights I have seen so far:
- Critical United States' public policies including the conversion of industrialize farming in the 1970s, and the beginning of fructose production
- The undermining of public health policies and guidelines (ex: sugar consumption doesn't contributes to diabete) by corporate lobbies
- Marketing strategies that change the social norm in U.K. to be a snacking and eat-on-run society
- Ideas and innovation in business which push consumers to eat more, the healthy food paradox
- And some suprising facts, like low-fat products use more sugar than normal to compenstate for the taste
In my opinion, this documentary is pretty bias against corporations and in favor of more government oversight. It doesn't ask much for a personal accountability, but this IS a U.K. documentary afterall. The European philosophy of safety net is pretty strong. Anyways, this documentary is still worth taking a look. You can check it out on youtube also!
http://www.youtube.com/watch?v=iE-H__aIEFE&list=PLA0E2B2461B536A26&index=1&feature=plpp_video
Zend Framework and the Genius Teacher Problem
Date: Tag: Zend, PHP
I think most people has this experience before. There you are in a classroom furiously writing down what the physics professor had on the board, while trying to understanding his explanation of an abstract physics theory. Every once in a while he provides examples that give a glimp of hope to understanding it. More often, everything just look confusing and incoherent. Your mind already give up after 10 minutes into the session. When you look around, other students are doing EXACTLY the same things -- taking notes and look confused. At the end of the class, the professor gets up and goes back to his research.
For the last few weeks I have been learning Zend Framework for PHP. After hearing so much praises about its MVC framework, and how so many companies uses it, I decided to try it out. The concept and theory I read in the introduction were great -- MVC, convention overs configuration (a concept from Ruby on Rail), bootstrap, etc. Learning practical examples turned out to be a bad experience.
- Zend's official quick tutorial throws you into the water of VC in MVC without a proper explanation about how a regular
index.php
is linked to a controller. Assuming you can get it working, you still have no understanding about why MVC framework without knowing how or why it works - Zend's API Document is not available offline. You are forced to use their online API Document web-app (generated by DocBlox). It run like a snail on my Firefox, and sometimes crash it also. This is my first time that an API Document crashes my browser! In contrast to Java, which has giant amount of documents, but able to keep it simple (KISS)
- Zend's API Document is incomplete. It has the usual prototype of the constructor and public functions, but it really lack thoughtful explanation, examples, pitfalls, and exception thrown
- Sheer out wrong information about certain concept. This is probably the part that scare me the most about Zend. I was looking at Zend to see if it can be used to provide a RESTful web service. Google points me to this document on Zend_Rest_Client & Zend_Rest_Server classes. It is almost as if they mistook REST for RMI. Nothing about CRUD or resource operation via URL
Adding to these problems, the documents are not updated. Comments from 2009 pointing the flaws and complains on the poor documents are still valid. To be honest, giving how much it is being used in the industry, I am surprise that no one tried to create a better document for them yet. So, how is this relate to the story I mentioned earlier? You should know by now, Zend is like the Physics teacher that students that nobody quite understand. Zend's official document is like those ambiguous lessons that students merely follow but not master. I could on with my analogy, but it only going to sound bitter.
In the past, Zend was the only big MVC framework in town, so people were forced to adopt it. However, serveral new PHP framework are popping up and gaining lots of momentum (See CssReflex.com). They are leaner, faster, and better documented. Any hope to redeem Zend is almost pointless. If Zend really want to compete and stay in business, they better fix all these document issues in Zend Framework 2.0.