Category Archives: Blog

My Internship in Japan

Last summer, I got to intern with Appirits, a web services company located in Tokyo, Japan. Aside from doing typical web stuff, they also have a department dedicated to making online games, known as the Appirits Game Project.

Most of their games are browser-only, and nearly all are Japanese-exclusive. However, one of them, Shikihime no Niwa, is available on iOS and even has an “English” version (inasmuch as “Summon Strong Hime!” is English). My job for the summer was to port over the 百鬼夜行 (“Pandemonium”) game mode from the browser version to the iOS version.


A screenshot of Shikihime no Niwa, quite possibly the most Japanese game ever.


Pandemonium mode in the browser version.

Since Japanese companies do not generally have summer internships as we do here, it was a very different experience from what I was expecting. While most companies here place a heavy emphasis on mentoring and creating a carefully structured intern project, Appirits took a very much hands-off approach—an approach that, I feel, gave me more freedom and control over how the project was completed.

I was given access to the client and server code for both the browser and iOS versions of the game. Getting things set up and running was a bit of a struggle at first; the company wiki with the deployment instructions was all in Japanese, and some of the details were outdated. But about a week in, I managed to get copies of the game running on my local machine.

While the server side was implemented with Ruby on Rails, which I am somewhat familiar with, the client side was implemented with Adobe AIR, a system that allows developers to deploy applications built with Adobe Flash across a variety of platforms. As you may know, Flash isn’t exactly the hottest technology right now, but, as with many semi-obsolete technologies, it’s still quite popular in Japan. However, the cross-platform nature of AIR should make porting things over a cinch, right?


The code also used the PureMVC framework, which is just as convoluted as its logo implies.

Ha. Not so. Even after I managed to copy all the relevant code between the versions and got the app running in the AIR Simulator, I was far from done. It turns out that there are quite a few restrictions when AIR apps are run on mobile devices.

The biggest restriction was on loading SWF files. Flash is fairly unique as a development platform because of its legacy as an animation tool. The two essential elements that make up a Flash “movie” are the Stage and the Timeline. Objects can be placed on the Stage and manipulated over time programmatically using ActionScript (a language very similar to JavaScript). What’s interesting is that the Stage, Timeline and corresponding ActionScript code can be exported together as an SWF, and then imported as an object into another Stage. This pattern lets you compose a scene by essentially piecing together SWFs, and is used fairly often in Flash development.

However, this functionality is extremely restricted on the iOS AIR runtime. SWFs that contain any sort of ActionScript code at all cannot be dynamically loaded, and even then performance is very shaky when more than a few are onscreen at a time. In addition, there’s a longstanding bug affecting AIR where certain SWFs cannot be reliably unloaded, resulting in memory leaks over time.

My solution was to strip ActionScript code from the existing SWFs, pre-rendering and caching the now “pure asset” SWF’s contents in the background, then manually animating the cached images by swapping the image to be displayed per frame. This process, though simple in theory, was again complicated by runtime limitations.

Stripping out ActionScript code (technically ActionScript Bytecode or “ABC”) was surprisingly difficult. There’s no built-in utility for this, and since the SWF file is a proprietary binary format, doing it by hand would be impractical. I ended up using the open source as3swf library to write my own tool to manually strip out the appropriate tags. Annoyingly, many of the SWFs contained no actual code at all, but empty tags would cause the runtime to complain anyway.

The pre-rendering process was also fraught with limitations. The mobile Flash runtime is fundamentally single-threaded, and there’s no real way to do something “in the background.” To get around this, I implemented a pseudo-threading system, where each render operation would have a fixed amount of time per frame to do its job before waiting until the next frame to continue. While this was imperfect in many ways, it worked well enough to avoid obvious framedrops.


The bane of all iOS developers.

Finally, I had to implement the caching mechanism. Initially, I simply held onto the cached resources for as long as the game mode was onscreen, a strategy that actually worked on all devices except the iPhone 4s, which only has 512MB of RAM. On the iPhone 4s, as more resources were cached, the game would get slower and slower until the OS killed the app entirely. That was unacceptable, so I decided to investigate the cause of this behavior.

On iOS, the system sends apps a UIApplicationDidReceiveMemoryWarningNotification (hooray RidiculouslyLongCocoaNamingConventions!) whenever memory gets low. The AIR runtime intercepts that call and activates the garbage collector. However, the garbage collector is unable to reclaim the memory taken by the cached resources, since those resources might still be in use. Ideally, the app should be notified when the memory warning is sent, and the cache should evacuate any contents not immediately needed. This required me to write an AIR Native Extension to bridge native and ActionScript code, since the runtime does not expose the memory warning to the ActionScript side by default.

After lots of debugging, optimizing and testing, the game was finally running acceptably! However, the UI was still very much designed for a mouse and keyboard, with tiny text and scrollbars everywhere. Since I still had quite a lot of time left in my internship, I ended up redesigning and implementing a new finger friendly UI, using the Apache Flex framework, which was a whole other can of worms.


Sadly, most people have fingers larger than 5 pixels wide.


Ahh, that’s better!

All in all, I was pretty satisfied with what I managed to get done. While I may not have had the guidance or mentoring I had anticipated, I still ended up learning quite a lot, perhaps even more than I would have elsewhere. I got to act as not only the programmer, but also the tester and the designer. Aside from the general goal set in the beginning, I wasn’t really given concrete steps to follow, so I got to decide for myself what things were important, how to implement things and when things should be done—something I don’t think I could have experienced in a more traditional internship environment.


It all comes together.

Interning in Japan was definitely a once-in-a-lifetime opportunity, and one I wouldn’t have traded for anything else. If you’re interested in potentially studying or interning abroad, look into the Bing Overseas Studies Program — it truly is a life-changing experience and one I cannot recommend enough!


Thomas

Blogger:
Thomas Zhao

Favorite engineering-related sources for inspiration:
“The Design of Everyday Things” by Don Norman
iOS Human Interface Guidelines: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/
Nielsen Norman UX articles: https://www.nngroup.com/articles/

Why did you choose to be an engineer?
They say that sufficiently advanced technology is indistinguishable from magic. When I was a child, I was captivated by the mysterious apparatus that humbly sat on top of the desk in my parents’ room. That old, beige PC—clunky, noisy and unapologetically plastic as it may have been—never failed to fascinate my younger self with its seemingly mystical inner workings. As I grew up, I became more and more interested in puzzling out just how these magical devices worked. And it turns out, “engineer” is just the modern word for magician.

Hometown:
San Antonio, TX

Class Year:
2017

Field:
Computer Science

Blogger Bio:
Thomas is a junior at Stanford majoring in computer science and minoring in Japanese. His interests include app design and development and examining the relationship between humans and technology. 想像が創造の始まりだと信じている。

Summer Research in the Stanford Chemical Engineering Department 2015

Having long thought my future career would be in scientific research, I participated in the Stanford Chemical Engineering Department’s summer research program last summer under Dr. Gerald Fuller. I had never done research at Stanford and my high school research had been pretty rudimentary and guided, so I was excited to take on an independent project of my own. Of course, the experience would have been far less valuable without the guidance from my post-doc mentor, John Frostad, but having a project of my own has built my academic confidence and allowed me to clarify my future research interests.

I decided to apply to work in the Fuller lab the preceding winter quarter while taking his introductory fluid mechanics class (CHEMENG 120A). I was interested by the richness of fluid dynamical phenomena and the contradiction of the mathematical precision of the theory and the chaos that is often observed in real-life fluid flow. I spoke with Dr. Fuller after class one day to discuss potential projects and expressed interest in his spin rinsing project. I would study a poorly understood instability in the spreading of an impinging water jet on a rotating silicon wafer. The project offered experience in designing experimental setups and procedures as well as in image processing with Python libraries. Scientifically, I could alter the fluid flow pattern by varying the centrifugal force from the rotation, the hydrodynamic force of the impinging jet, and various rheological forces by pre-wetting the silicon wafer with different liquids. The diversity of experiences involved in the project has kept me interested through the present day and has encouraged me to apply for the Goldwater Fellowship for undergraduate research and ultimately write my honors thesis on my research.

Of course, several difficulties arose. Initially I had no experience with the Python programming language or image processing — just CS 106A freshman year. Designing image processing software daunted me, but tackling the challenge taught me the most important lesson in research, which happens to be Google Scholar’s motto: “stand on the shoulders of giants.” I didn’t need to reinvent the wheel or, in this case, image processing, but rather identify the appropriate methods and algorithms for my specific purpose. After testing out a few methods from the Python libraries for myself, I found a promising direction and completed a workable method to process all of our videos by the end of the first five weeks. That was when the real difficulties began, though. To improve the precision of the experiments, I had to automate the spin coater that rotated the silicon wafer by connecting it with the Matlab program that controlled the camera and impinging jet. The programming was easy after image processing, but I spent three weeks troubleshooting the Ethernet connection between the computer and spin coater. While proud of my perseverance in not giving up day after day, I was embarrassed to find that the problem was that the default “end command” character in Matlab was not the one the spin coater expected. Voila, a programmable spin coater. Definitely worth the misery.

In the final two weeks I felt rushed trying to pull together another round of experiments with the automated spin coater and put together a final presentation for group meeting. Thankfully my mentor had been requiring the other intern and me to work on and present a portion of our presentation at weekly group meetings (moral: you should always be working on your poster/presentation); however, the changes in the experimental setup meant my image processing software no longer worked. Here I learned the other important lesson in research: everything takes longer than expected. Thankfully I’ve been able to continue research during the school year. Although I’m still working on getting the data I originally wanted at the start of the summer, I’m learning practices, techniques, and life skills I’d never have even been aware of without this project, which has made it the most valuable academic experience I’ve had at Stanford.


Andrew

Blogger:
Andrew Ylitalo

Favorite engineering-related sources for inspiration:
Computer graphics of fluid flow and deformable bodies by a professor at Stanford: http://physbam.stanford.edu/~fedkiw/

Why did you choose to be an engineer?
Having originally decided to major in Physics, I switched to Engineering Physics this year because I realized I wanted to solve real-world problems and design novel products through my research.

Hometown:
Stillwater, MN

Class Year:
2017

Field:
Engineering Physics

Blogger Bio:
Andy mostly studies physics but is interested in mathematical modeling and data analysis. He is most interested in fluid dynamics currently but is considering condensed matter physics as a field for graduate school. In his free time he sings in a choir, plays saxophone, and watches Spanish and Armenian TV shows.

Matematica Italiana

When I arrived in Florence last year, I had a rough plan of the classes I would take: some Italian, some art history … and a materials science class (with recorded lectures) that would fulfill an “engineering fundamentals” requirement for my computer science degree—or maybe an online CS course through Stanford’s SCPD program. This plan did not last.

I’m sure that had I followed through on my initial course of study, I would have ultimately been okay with that choice. Instead, I realized quickly that I didn’t feel excited about taking those engineering classes and spending however many hours a week in front of my computer rather than outside in one of the world’s most wonderful cities. Instead, I picked up a class on the history of Florence in the Renaissance and another on mass extinctions and the geology of the area in addition to my Italian and art history courses.

But none of these classes count toward your major, a part of my mind squeaked. And this was true, and it was worth acknowledging. But I would be able to take all the requisite classes when I returned to California, and here I was in a new place, so why not be completely present, and what does it really mean for something to “count,” anyway?

Certainly, studying in a directed fashion to acquire a degree is valuable in some sense, but my time in Florence as been one of several events in my Stanford experience that—in addition to exposing me to all sorts of new knowledge, teaching me to love Italian culture, and bringing profound joy to my life—has really challenged me to consider what it means to get an education, and, more generally, to learn and to live well.

All this is not just to say “Go abroad!” or “Have a fun time in college!” or “Study a wide range of things!” (though these are all decent pieces of advice). Rather, I simply wish to pose to the reader: What counts?

The question that continues to challenge me almost every day. And while it probably means something different to you than it does to me, I urge you to consider it constantly.

Arno
                      Walking by the Arno

Alec

Blogger:
Alec Glassford

Favorite engineering-related sources for inspiration:
XKCD: (https://xkcd.com/)
Ada’s Technical Books in Seattle: (http://www.seattletechnicalbooks.com/)

Why did you choose to be an engineer?
I like the idea of making new things and of making things better.

Hometown:
Seattle, WA

Class Year:
2017

Field:
Computer Science

Blogger Bio:
Alec studies computer science (and creative writing and history). He likes to read, to write, and to use computers to play with language. Basically, he really likes words. Other favorite things include tea, people, and vegetarianism.

Road Networks in California

Currently, I’m working on a project to apply network analysis and machine learning to road networks of California. Our goal is to evaluate the road networks in terms of accessibility and efficiency, and then come up with alternative solutions to improve on these road networks or even create new ones.

Growing up in the Bay Area, I’ve always been aware of our dependence on cars and how much our lives are affected by transportation systems. One thing that we sorely lack is a dependable public transportation system; in my ideal universe, we’d have buses, subways, and trains instead of freeways! Although that being said, tearing up infrastructure and forcing people to give up cars is easier said than done. So the question is, how can we leverage our existing road infrastructure to make traveling easier?

transportation

(Photo courtesy of LA Times: http://lat.ms/1QmiUf6)

One potential solution we are exploring is rethinking GPS navigation tools like Google Maps to optimize routes in terms of efficiency for all travelers. This idea is motivated by one night in San Francisco where my family and I had just eaten a delicious dinner in Chinatown and were trying to drive back to my apartment. As usual, we were following the shortest path that Google Maps had routed for us. Unfortunately, as we sat in our car in downtown traffic and watched pedestrians and bikers pass by, we realized that everyone around us was more or less following the same route. We realized that if we just made a detour down some random side street, we ended up reaching my apartment much faster. This made me think: wouldn’t it be cool if there was a GPS navigations tool that would route different travelers down different paths? That leads to one of the challenges of my project: If we knew the location and destination of every moving vehicle at a time, how could we direct traffic to optimize the greater good?

One thing I am amazed to realize is that there are massive datasets available online for both California road networks and traffic data. Imagine all the interesting research you could be doing with this data!


Karen

Blogger:
Karen Wang

Why did you choose to be an engineer?
I chose to be an engineer, and a computer scientist specifically, because I like being able to use abstract concepts to solve a wide variety of real-world problems

Hometown:
San Jose, CA

Class Year:
2016

Field:
Computer Science

Fun Fact:
I’m an art minor focusing on photography, and currently working on a project in color film.

Pepping Up Intro Computer Science: A CS106 Section Leading Project

If you asked me four years ago what I wanted to study in college, computer science would not have been on my list. Too afraid was I of entering a field that so many have started exploring seemingly since their kindergarten days. It also did not appeal to my inner musician. What could computer science ever have in common with creative expression?

Stanley_Image2

Stanley, the driverless car developed at Stanford that won the 2005 DARPA challenge.
(Photo courtesy of http://cs.stanford.edu/group/roadrunner/old/presskit.html)

Audrey

I loved the intro CS classes, which not only let me discover that I enjoyed building programs but also showed me the elegance of programming and that I can be a CS major. At the same time, I think that an interdisciplinary approach to introductory CS would be fascinating and beneficial to a large group of students, especially those who did not intend to study CS in the first place. More than half of all the students in CS106 classes are not CS majors or undeclared. Wouldn’t it be great, if they could learn how they could apply their new CS knowledge to their own areas of interest? This vision inspired me to pursue an undergraduate research project under the guidance of Professor Stephen Cooper. The goal was to create new interdisciplinary section problems, which would motivate students to learn the material, increase their awareness of CS as a broad discipline and inspire them to take more advanced classes.

Genetic_Algorithms

The topics of the sections include localization for self-driving cars, genetic algorithms, sentiment analysis, traffic optimization and image compression. For example, the section on genetic algorithms introduces you to programming inspired by biology and lets you practice the manipulation of linked lists. You learn how genetic algorithms work and how they are used to find close-to-optimal solutions to NP-hard problems. Then, you implement two crucial steps of the algorithm; the crossover and the mutation steps. In the crossover step, two selected chromosomes cross each other at a random gene to create two new chromosomes. In the mutation step, a gene is deleted randomly inside the chromosome while a new gene is added. This section can inspire you to explore biocomputation, solidify your understanding of linked lists and encourage you to learn more about computationally hard problems.

I am very grateful for the opportunity to do research as an undergrad. It allowed me to explore an area I am passionate about and to receive amazing mentorship from Prof. Cooper as well as from other faculty and lecturers. The CS department also holds a speaker series for undergraduate research students over the summer, featuring inspiring professors and cutting edge projects. You can do research as early as your freshman year. If you are interested, you can find out more at curis.stanford.edu/.



Lisa

Blogger:
Lisa Wang

Favorite engineering-related sources for inspiration:
Artistic visualizations of algorithms: http://bost.ocks.org/mike/algorithms/
SSO Delta: https://ssodelta.wordpress.com/
Red Blob Games: http://www.redblobgames.com/

Why did you choose to be an engineer?
To show the world that anyone can be an engineer! Engineering also appeals to both halves of my brain by letting me be analytical and creative at the same time.

Hometown:
Karlsruhe, Germany

Class Year:
2016

Field:
Computer Science

Fun Fact:
I love doing handstands and seeing the world upside down!