Reflection of DeveloperWeek Hackathon 2016

I haven’t took the Muni for a while. I totally underestimated the time, missed a bus, and ended up way too late.

Not a good start.

By the time I was there, there is only about 10 minute before the main stage kickoff starts – wait, I mean I was late for breakfast.

What? Breakfast is a very important part of hackathon. Especially if you are a coffeeholic. Oh, coffee, my precious coffee.

*Cough*

The point is that everyone is there, chatting among themselves or the booth host, and I am still didn’t had my morning joe… wait, the booth is already set up this year!?

Well, at least I didn’t missed the food.

The main stage kickoff was late this year, and there were some momentary confusion about when and where it was to happen. It didn’t help that the attendees are split into 3 stories, with the lower story being the actual place for the main stage. I stalked checked up frequently on DeveloperWeek’s Facebook and Twitter account. Finally, someone came in to inform us that the kickoff is about to start. It was pretty much just each company introducing themselves and their Challenges, which was posted at Accelerate.im, DeveloperWeek’s website for the hackathon event.

The companies involved this year that caught my attention because they were either on Opening stage or holds one of the booth includes Galvanize, Codeanywhere, Concierge, Flowroute, HP, CapitalOne, Cortical.io, IBM, Intuit, Magnet, NetApp, RedisLabs, SparkPost, CloudBees, Weebly, and Shippo.

It would be way too long to go over each company. I may go over them in a later post?

The decision to come to the Hackathon was last minute, so I didn’t really know what Challenges there were or had a team. I met up with a friend, but she was in a team that uses Ruby, which I know nothing about other than the fact my favorite and very awesome food subscription box uses it for their website (Yep, I checked their job page. What? An internship with a food company would be awesome! Except they use Ruby on Rails. And they don’t need interns. *Sighs* By the way, the company is Love With Food. Great snacks, fun preview video, and they donate a meal for each box purchased. Did I mentioned that they are awesome?).

So, first task. Read Challenges and existing Projects. The Challenge from Shippo caught my attention quickly. I thought of the multiple subscriptions of magazines and boxes I have, and how nice it would be to view them on one site. But then, no one seemed to have similar Challenge, so I decided to wonder around the booth, attend the workshops, and learned more about the available tools. After all, learning was my objective this time. While several were interesting, none of them materialized into a web app idea in my mind like Shippo did. In the end, I posted my own Project online onto Accelerate.im. However, I think I might had been too late, and no one is looking to team up anymore.

Lesson of the day, start and decide quick in a Hackathon.

One of the workshop, IBM’s Bluemix, did caught my interest. It seemed like I could use it to build web app, where I could input my code for Shippo. However, in the end, it was in vain. There were several errors that I came across, and it wasn’t friendly enough for me to create a login system in 24 hours. In the end, I became too obsessed with it and wasted time.

Another lesson learned. In hackathon, do not obsess over non-essential problem.

I did created a PHP class to extract the information given by Shippo’s API. I used WordPress and its numerous plugin for user registration. But by then, I realized I wouldn’t finish on time. I took too much time with IBM’s Bluemix, and there were also some issues with the WordPress plugins. I could do an all-nighter to make up for the time – except I had a volunteer project due and a dinner party for my dad the day when the Hackathon ends. I did not want to fall asleep for either of them for a project that I will either not finish or finished very roughly. Promised responsibilities comes first.

In the end, I turn of my laptop and went to bed. The idea is there now. Even if the hackathon had passed, I still got a project started that I plan to finished after my current EduGarden app, so not all is lost. Plus, this way, I get to make a much more complete project, which is much more satisfying for my perfectionist side. My current EduGarden app is being done with a focus on secure programming practices and an aim of learning PHP MVC. While EduGarden is made to work fine in both mobile screen and even without Javascript, my second app – now title SubscribeTrack – will probably focus completely on mobile usability with an aim to learn css3 media queries.

The current project of SubscribeTrack is now on Github without the WordPress codes, temporary placed on hiatus until EduGarden is done.

Winter Break Activities, 2015-16

So far, during this break I have:

  • Went to Japan with my family (Hooray!)
  • Started to volunteer for a non-profit that help local youth by teaching tech named Bayview Boom. Currently I am just discussing how to organize the page with the director, who is also a developer. Should be a good experience that we will let me both learn from a working developer and use my skills in front-end (the webpage is switching from Yola to WordPress.org) for a good, local cause.
  • Reading through the HTML & CSS3 For The Real World by Alexis Goldstein, Louis Lazaris, Estelle Weyl.
  • Reading through the C++ Primer by by Stanley B. Lippman, Josee Lajoie, Barbara E. Moo. I am taking CCSF’s C++ Fundamentals coming semester, even though I have never taken the C++  intro class! I had, however, taken the Java intro class, whose professor emphasized that if we took the Java intro, we should take the C++ intro. I hope he is right, but I am going to make sure that I am well-prepare.
  • Reading articles and books on mobile responsive design.
  • Random reading about random programming subject.
  • Tried Eclipse to do C++. Can’t do Ctrl C and Ctrl D, which is part of the book exercises. Prefers and went back to command line.
  • Added to my PHP class project from last semester. During last semester, I already finish the basic functions for the login, inventory, and cart page. I want to finish the shop and about page during break.

Coming semester:

  • I am taking 3 classes: Programming Fundamentals: C++, WordPress & Drupal CMS Development, Linux Administration Projects.
  • Be more active with Meetup.
  • Continue volunteering at Rebuilding Together in data entry, phone screening, Cantonese interpretation, and Traditional Chinese translation.
  • Start volunteering at Bayview Boom with their website. Seems like it will focus on WordPress plugin and related codes. My WordPress class in CCSF starts just at the right semester!
  • In progress of inquiring about a possible web/media internship with a non-profit. No email reply yet.
  • For the PHP class project, finished the home and product page. If possible, include an event page.
  • Add my current work to my portfolio page. Everything is just on Github now, which only have the code, not the images.
  • Really want to learn C so I can program my Pebble Watch, but that may be too heavy of a work load this semester with the C++ class.
  • I would complete all the Linux courses in CCSF. Should I take the Redhat exam even though my aim is front-end? I have enjoyed the classes very much. I should look more into that…
  • Speaking of which, I should work on changing my Nexus tablet’s OS to Linux. Totally forgot about that!
  • And last but not least, look for a job or internship.

Building my PHP Session Handler

My homework recently consisted of building my session handler, which confused me greatly – what on earth is session handler? At first glance, I wondered why would one use session handler? How is different from, say, calling the method by $session->getData()? Took me a while, but I finally got a working code that I have now recorded on Github, and I got some basic idea on What, How, and Why.

Note that this is really a blog where I store my notes for future references and to type out information so my mind can wrap around things. There is a lot of “typing whatever comes to mind” and cherry-picking only things that interest me. If you somehow wandered here looking for organized info on Session Handler, I suggest the tutorial on Sitepoint, which is way more organized and correct.

What is Session Handler: Like its name, it handles session. When a session starts, such as via session_start(), data are stored in $_SESSION with a configuration file php.ini, or at least that is my impression of how it works. Using those information and configuration settings, the handler manages database storage. Its basic, possible use includes opening database, reading the database and outputting the data, writing to the database with the values gain from $_SESSION, destroying selected data from database, performing garbage collect in the database, and closing the database.

How to do a Session Handler:

Class Session {   // Or whatever you name it as.

// I am using the constructor in PHP 5 style. Do not misspell it as constructor. Certain someone spent a whole night wonder what is wrong with her constrictor because of it…

function __construct() {

// The build-in function below “sets the user-level session storage functions” (via php.net), which pretty much means that it designates when the methods in this Class is invoked. Yes, the methods are invoked automatically basing on the condition! Most of the time anyway. Do not misplace the order of the arrays, or your function will be invoke in the wrong condition.

// Placing it inside the session class constructor is optional. However, placing it outside the class would mean you would type it out each time the class is invoked, plus “$this” will be change to the name of the object created by the Class, which is just annoyingly repetitive.

session_set_save_handler(   

array($this, ‘open’),    // 2nd parameter’s name is personal preference, but pick something easy to understand. ‘Open’ is pretty standard.

array($this, ‘close’),

array($this, ‘read’),

array($this, ‘write’),

array($this, ‘destroy’),

array($this, ‘gc’)

);

session_start();   // though not required, it’s good idea to place session_start() her so you don’t to invoke every time you create an Object with this class.

}

function open() {

// Invoke condition: whenever session is starting, such as when session_start() is used.

// Typical content: call to database.

}

function close() {

// Invoke condition: after write() was called or when session_write_close() is called.

// Typical content: close database.

}

function read($sessionId) {   // all method’s parameter seems to be optional. Each method’s first parameter calls the value from $session_id(). You as the coder don’t have to do anything other than call the Class (or session_start() if it is not in the Class’s constructor. See, this is why its good to put session_start in the constructor) unless you want to change the default session id. You should not have to type read(1234) or something like that.

// Invoke condition: whenever session starts or when session_start is called() – but after open().

// Typical content: what you want to display from the database.

}

function write($sessionId, $data) {   // like read(), $sessionId will call the value from $session_start(), while $data will call the value from $_SESSION[‘data’]. Again, you don’t have to do anything other than calling the class unless you want to change the default value. I change the $data in my handler to take in the input value, but I did it by reassigning the value in $_SESSION[data] outside of the class ($_SESSION[‘data’] = $_POST[‘something’]) and not by $data = something.

// Invoke condition: whenever the PHP shuts down or when session_write_close() is called, but after the output stream is closed. close() is executed after this.

// Typical content: writing to database. Note that $_SESSION[‘data’] is automatically serialized. This means you have do some unserializing and serializing, plus you have to make sure to prevent SQL injection. In my own code, I:
(1) Copy the serialized session $_SESSION in a different variable, $original.
(2) Unserialized $_SESSION. Note that after PHP 5.3, using unserialize() on a SimpleXML_Load_String() will result in an error message, which is what will happen with $_SESSION. Use session_decode() instead.
(3) Store the unserialized content in a variable $output, then real_escape_string() it to prevent SQL injection.
(4) Restore $_SESSION with the variable containing the serialized session ($_SESSION = $original).
There are other methods, but this is the quickest one I can understand – I am working on a deadline after all.

}

function destroy($sessionId) {

// Invoke condition: whenever the session is destroy, either via session_destroy() or with session_regenerate_id() set to parameter TRUE.

// Typical content: what happens if a session is destroy. In my case, I set my codes to do a session_destroy if a submit button “Logout” is press (AKA, check if a $_POST[‘logout’] exist, if so, call session_destroy() ). When the destroy() is invoked as a result of that, it remove the entry in my database associated with the current session id.

}

function gc($lifetime) {   // $lifetime calls the value store in session.gc_maxlifetime.

// Invoke condition: called periodically by PHP, with the frequency based by session.gc_probability and session.gc_divisor.

// Typical content: what happens if a session is garbage collected. In my case, in my construct(), I set the session.gc_maxlifetime to 15 minutes. My database contains a column, ‘time’, that stores the time the entry was first written. When gc() is invoked, if any rows have a ‘time’ cell older than 15 minutes ago, the row is removed from the database. In another word, a user is automatically logged out after 15 minutes with its session id and data removed.

}

Why use Session Handler: It is probably because it (1) reduces the amount of coding when you store session repetitively and (2) sets a lot of automation.

When I first started building the code and my constructor wasn’t working, I placed session_start() outside of the class. I also attempted to invoke the methods manually:

$session = class Session();

session_start();

$session ->open();

$session -> read();

$session -> close();

That is a lot of code to be typed each time you invoke a session class. With the session handler, all the methods are invoked automatically when conditions are met. Even the parameters, like $sessionId, $data, and $lifetime that I mentioned earlier, are automatically set. Coder can change them by change the values in $_SESSION[] or session.gc_maxlifetime, but it’s pretty automatic.

Summer 2015 So F ar

One of my goal this summer is work on my project, which ended up with me taking a long detour in both brushing up and learning new skills in JavaScript, JQuery, Ajax, PHP, MVC, and OOP. There was a lot of reading, online video/school, and coding. I have sadly ddiscovered that I have learned more about Ajax in a 2-days self-study using Treehouse video and books than I did a semester of class, but hey, some classes are better than other. It’s been good, although I ended up pushing back my C and Anduino learning.

IT network self-study has been going well. Since I am taking the same professor as I had in my Introduction to Networking for the next semester course in Network Security, I feel that I should brush up on my network knowledge. When I took my first network class over half year ago, I was new to CS and have no idea what is going on. I am half-way through re-reading my books and notes. Now that I have a lot more experience, it makes much more sense, and I feel more comfortable about jumping back to a networking class this Fall.

In term of Fedora, because of that fact that half of my self-study files are local, I lacked a reason to even turn on Virtualbox. But no more. Most of my learning files and even a good portion of my project files are now on Dropbox. I installed both Dropbox and Sublime Text on Fedora, so I can now do most of my coding and studies in Fedora!

Although, Fedora have problem waking up from its sleep in Virtualbox. It would either remain the black screen of death or refuse to let me type anything. In addition, I am consistently clicking on command-C instead of control-C. In Virtualbox, control-C actually exits the Virtualbox out of its full-screen mode instead of copying text. As someone who loves shortcut key and types pretty quick, it’s driving me a bit crazy. I pretty much do a command-key shortcut every 10 minutes when I started using Virtualbox, then when I do return to my Mac OS, I would do the opposite! (As in using control-key for shortcut every 10 minutes). For the first time in my life, I curse my ability to type so quickly…

Project Euler is getting easier!

For the last 2 days, I have been catching up on PHP OOP via PHP Objects, Patterns, and Practice. I figure a change of pace is good – I need to do some problem-solving!!!

Quickest way to find things to do is Project Euler. I have solved Problem 1 and 2 before in Project Euler in different language. The most memorable one were the time I used Bash scripting (It really isn’t a language for math, I know, but I want to try!).

This time is by far the quickest I have done it. I don’t know if it just because I more used to programming now, or if PHP is just that much easier.

I also found that combing Project Euler with PHP Cookbook was very helpful in learning the PHP built-in functions. I read the problem and started browsing through the Cookbook for possible functions that I can experiment with. I was able to significantly reduce my code length. For example, in my previous coding for one of the Fibonacci sequence problem, I had used multiple enclosing loops to refer back to the last two number and sum them together. This time, I used prev() and end() to point to the last two number of the array and sum them together – in one loop. I also experimented with array_filter to replace one of the foreach loop. I found it to much more concise.

My code is so much shorter and easier to read! Is it strange that I am getting the sort of feeling that one would get after cleaning their room!

Tiny Itsy Changes on my Homework

This is what the teacher provided as sample for our homework, which is to use array in PHP and print out a table of selected background and text color:

phpHwA

This is what I ended up doing:phpHwBAesthetic doesn’t play into grading, but I prefer the cell separate by space instead of black border, and with the limited text, it almost look like a card game! It was just a basic homework assignment, but a little change can make it more fun.