May 21, 2017

-4294967295

Nicolas approached me a couple days ago and told me he would be starting a blog for bell.lahs.club, which is especially interesting given that we’ll be graduating in less than two weeks. I’m told the domain is being passed on though, so I guess this is for posterity.

I guess an introduction is in order. I’m Jonathan Shi, graduating senior, headed to Berkeley in EECS next year. I wrote the Chrome extension for bell (which is the reason Nick said I could write a post, downloadable here), and I’m one of Nick’s roommates next year. He told me I could write about anything here, so I’ll write about a few things: 1) my prior programming experience, 2) the reason I undertook this project, and 3) a little bit of the technical side of stuff that happened over the course of this project.

My life story

Anyway, here’s my life story.

Somewhat ironically, I didn’t really get into coding until this year, after my mom forced me to take an online intro Java course throughout second semester junior year. It was interesting, but not all that inspiring. Then I did a summer thing at COSMOS UC Davis, and one of the things I did was a lot of coding in GNU Octave (a free version of Matlab). I thought it was interesting, so I started learning more code. Throughout the past year, I’ve learned a decent amount of Java (thanks to APCS), Python (thanks to Francis in Computer/Programming Club meetings), a decent amount of Haskell (thanks to Nick and Learn You a Haskell, and, obviously, a decent amount of Javascript.

Long story short, it doesn’t take a whole lot of programming experience to do something fairly substantive if you put a lot of effort into it; while writing the Chrome extension wasn’t all that difficult since most of the difficult code (like that governing the bell schedule and stuff) was already written by Nick, I still managed to figure things out with barely a year of coding experience. Why I did this

The inspiration for this project wasn’t entirely altruistic — my labor of Javascript love/hate was physics.lahs.club, if you’ll excuse the shameless self-promotion. Rather, one of the requirements for the senior project (a really big research project on a topic of your choice in senior English that also requires a “hands-on project” related to your topic).

I actually made the Chrome extension for my project. Take a guess at what my topic was.



Copyright law.

It’s related, trust me. Here’s how:

  • The DMCA (Digital Millenium Copyright Act, 1998) governs the enforcement of copyright on the Internet and on digital devices, and its second provision (17 USC §1201) makes it illegal to circumvent “technological measure that effectively controls access to a work protected under this title” (source). Basically, if a company encrypts their software/firmware, its illegal for users to break that encryption.
  • One of the many problems this causes is that users have no way of knowing what their software might be doing because the source code is unviewable, leading to situations where companies are being evil in a Google “don’t be evil” kind of way. That is, they’re taking their users’ information, or worse, creating security vulnerabilities (which I don’t feel like explaining right now, if you want to read more, refer to this piece). One possible solution to this issue is…
  • Free software, where, as defined by the GNU Project, is software that lets users run, study, redistribute, and modify the program at leisure. The license with which a project is distributed, indicating how it may/may not be used, is protected by copyright law.
  • Free and open source software are not technically the same thing, but the nice thing about bell is that it’s both. So I joined it.

However, bell was not the first open source project I tried to work on. I spent a couple weeks trawling github and various other sites for a project within my skill range, until I finally found a fairly large one that looked good. Then I tried installing all the dependencies (vagrant, docker, and some other random node stuff that I don’t want to deal with) and it failed, so I gave up and asked Nick if I could help with bell somehow. Even after that, a Chrome extension was not my first option.

First, I wanted to write an iOS app (although its usefulness would be rather dubious), tried learning Swift and Xcode, but gave up after trying to figure out how to parse JSON and send HTTP requests and then learning that stackoverflow answers applying to Swift 2 might not work in Swift 3.

I then tried to write an Android app, because Android is written in Java/XML and I know Java. But Android’s libraries are kind of messy, and I didn’t want to deal with JSON in a strongly typed language, so I gave up on that.

That left me good old Javascript. Turns out Chrome extensions are written in Javascript with fairly straightforward APIs, so I settled on that. After a couple weeks of coding (and heavy consulting with Nick throughout the process), I got a working version. The experience made me learn to both appreciate and hate Javascript more, for reasons that I’m sure are already well-documented elsewhere.

What I actually did

Throughout most of the process of making the extension, I was working in parallel with Nick. Most of the Chrome-exclusive stuff is my work only, but I asked him a lot of questions about how to do things, and also how to use the bell libraries he wrote for the main site.

Writing new code actually wasn’t the only thing I did. I also helped squish bugs in the code for the main site: for example, you know that bug where class/theme cookies would disappear after a session instead of a year like they were supposed to? Turns out that was a flipped conditional operator in CookieManager that I noticed in Wind Ensemble with Nick one day. You’re welcome.

I also wrote a bunch of documentation; in some places it was easier than others. If I recall correctly, about a third of the BellTimer API and most of ThemeManager and CookieManager are documented, hopefully accurately.

A few internal changes on the site also happened while I was working with Nick; for example, you’ll now notice that the site’s cookies are stored in base64. That mostly happened because Google’s cookies API is super weird about how it deals with plaintext, so he decided to store everything in base64 mostly for my benefit. Schedule data is now also stored in cookies for potential offline use. Another, even less noticable thing is that the BellTimer class (at least the version in my fork) now allows you to retrive schedule data from any chosen host, so Bell should now hopefully work with any site that specifies /timesync, /api/version, /api/schedules, /api/calendar, and /api/correction.

Also, turns out git is weird. Here’s a snapshot of a Hangouts conversation I had with Nicolas:

J: how do i pull changes from an upstream repo
N: you've done it before, right?
J: maybe
N: i dont actually know how
J: nvm i googled it
N: something like git pull remote branch
or something
J: aaand there's a conflict
N: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
there is a conflict in syria

The final version of the extension is listed under Nick’s name because making a developer account requires you to pay a one-time $5 fee, which I was too lazy to do. Nick already made an extension for image stamps or something, so I just asked him to host it for me.

Don’t tell anyone, but the first version that was pushed turned out to be something like 9 MiB (Google’s choice of units, not mine). I made the mistake of not removing node_modules. As of version 1.0.2, the extension should only include necessary HTML, images, and bundled js, which brings it down to about 300 KiB.

Thanks for following along with this stream of consciousness dev post. Maybe I’ll do another one of these again someday.

— Jonathan Shi (github)