< prev 11 Feb 2015 to 10 Jan 2015 next >

Posts tagged 'javascript'

  • Oh, neat

    Today: clearing out the backlog of things that I wanted to do on my homepage.

    You know, until AppAcademy, I hadn't seen much purpose for a homepage. I remember the days of the late 90s, when everyone had a homepage with "About Me" sections that (let's be honest) no one really cared about, and then some collection of things that they cared about, like spacecraft of the Federation. (There was one guy who had a homepage dedicated to the Performa 6400, and that I used for years to diagnose issues.)

    I may do something similar on my own page in time, but for now it's just a pretty good hub for everything I want people (who might want to hire me) might want to know about me.

    In trying to put my best face forward, I've been customizing my hosting. Among the NEAT things I discovered today:

    • Bare git repos, and the hooks directory in a git repo, that allows you to auto-deploy files (for instance)
    • I have control over all components of my chosen theme, which means I can debug broken scripts (damn designers!)
    • It's easy to override the designer's css, especially when he barely uses classes.
    • It's easy to keep my version of given plugins up-to-date in order to use the most recent features.

    I know, nothing here that's ground-breaking, but there were a couple times today that I found myself exclaiming, "neat!", if only because I figured out a way to get something closer to exactly what I wanted. … well, within a certain definition of "exactly". There are a lot of things I would do differently if I chose to build my theme from scratch, but given the constraints of using Wordpress and (most of) a pre-baked theme, it's pretty cool.

    I may still SASS my page up, since SASS is cool, and choose to redo major components of the design (e.g. the font-family), but all-in-all, it's close to where I want it to be to represent me.

    One thing I discovered: I haven't been nearly as consistent at posting here as I thought. The calendar widget at the bottom of the page has a LOT more gaps than I'd have believed at first. I shall try to rectify that. One change is that I intend to post more stuff that may not be public up there (here), including blog posts that don't have anything to do with AppAcademy. All in due time.

  • The Data Model

    One of my hangups about continuing work resolved itself over the past couple days. I ended up having a couple of redundant checkins—"Fixes data model", "Data model finally fixed"—but I think I'm there now.

    Collections have models, and certain models, like Posts, have collections of their own (in this case, comments). When you pull the data from the server for a non-root page, the data needs somewhere to "hang" so as not to face sync problems. So, when I fetch a post, I shouldn't fetch the class it belongs to, I should instead examine the post's section_id property, and then put that in an existing class's post collection. … Got it?

    User -> Sections Collection -> Section Model -> Posts Collection -> Post Model

    So, on fetch of the last item in that chain, I need to go to the head of the chain and request that this data goes in the proper place in that chain.

    It took me a while, but I think I ironed out all the kinks. It took moving some logic from the models into the collections: if you ask a Post what section (class) it belongs to, it asks its collection, which in turn had that property set upon initialization. (I also needed to start initializing new collections with (null, options) instead of ({}, options) because it turns out {} is a model on its own, just one with no attributes… derp.)

    What does this mean? A whole bunch of crazy sync problems disappeared all at once, and I can finally see the light at the end of the tunnel. I have never truly had a Minimum Viable Project (MVP), and I'm getting to the point where that feels possible, and likely to happen soon.

  • CSSris and spinning wheels

    One of our cohort has a job offer! Neat.

    I spent the past two (and a half) days getting up late and working later. I got nervous that I have absolutely nothing to show with regards to portfolio work and decided to do some mini-side projects that I thought would be good examples for my portfolio.

    The first of these was cleaning up Rails Lite, which I'm pretty happy with. When we were doing it in class, I was frustrated because of how fragmented the lessons were, but once I consolidated my code a little bit everything made perfect sense. When controller instances inherit from the ControllerBase class, they gain all the powers that it has, including auto-routing and rendering of default templates… it's actually quite clear, and quite neat how it all works. The inheritance tree is also much clearer, now, so I can see that parsing of input parameters and session management happens in quite the sensible manner. It's truly improved my understanding of how Rails works.

    One neat side-effect: When I told Tommy that I wanted to include Rails Lite in my portfolio because it made more sense to me, he and I talked for a bit about how rails is organized and it piqued my interest about the project codebase. So I started reading through the source on github, and ended up identifying a bug in the source that will prevent the current cohort from being able to complete the assignment on that class day. (Long story short: the way the project is designed, it will work with version 4.1.x but not version 4.2.) It was interesting to be able to dive into the code like that and know what I was looking for, and I feel more capable for it.

    Late Thursday, I started in on a project that I knew I wanted to do: modifying my Snake (game) code to instead implement Tetris. Besides being (I believe) the better game, it was something that I think could set me apart a bit on my portfolio, and it was fun to see JavaScript in a different light now that I'm more versed in the language. I've finished it up now, for the most part, after quite a bit of late-night logic-checking (pieces no longer get stuck in the sidewalls! Yay!) and I'm quite happy to say that I can be proud of my code in a way that I wasn't for Snake. It is my project and it works well and looks like what I envisioned when starting out, more or less.

    Curiously, I got the code 90% right straight out of the box when doing the initial implementation. I started it up without the rendering code, and after making a small fix (ensuring that the IIFE was starting correctly), I could step through the game logic and see little boolean pieces falling like they should. It was pretty empowering to have that be the case; writing (mostly) bug-free code with few syntactic errors is a powerful feeling.

    I added both projects to my resume, which has been cleaned up a bit, and I'm feeling (almost) ready to go full-in on the job hunt. I know I'm late to the game, but that's quite alright. This break has done me well, and if I can do that with as much determination as I've been able to muster the past two-three days, I should be fine.


    Now that we don't have to blog, I can blog whenever I want—which also means blogging in the middle of the day when I've found some solution to a particularly knotty annoyance and am taking a break from whatever.

    I'll try to keep this quick, and I still don't have it how I want it.

    Sign-in is handled through a modal (using a library that is just okay…). When the app first starts, it tries fetching the currentUser model (asynchronously, of course). Meanwhile, it tries to route to whichever route was input, and if the user isn't signed in (which he won't be, because we're still waiting on a server response), it redirects to the sign-in window, which has an initializer that tells it to destroy itself when it receives a 'signIn' event over the Backbone.Radio eventsChannel.

    Meanwhile, the modal animates, and only adds its keybindings once the animation is finished. But the 'signIn' event is received in the middle of the animation, which means that the view is destroy()ed before it has attached its keybindings… which it does after the fact.

    Long story short, when a signed-in user refreshes the page, the sign-in modal installs listeners that get uninstalled before they're installed, and the next time the user hits "enter" the modal executes a "submit" event on empty text fields.

    I got around it by having an onShow callback that checks to see if we're signed in, and ONCE THAT CHECK HAPPENS, install the 'signIn' event listener. If that check fails (we've signed in during the 100ms that the animation has as default) then we uninstall ourselves.

    Gah. JavaScript, why you hurt so much?

  • The ghosts of problems long dead

    Friday, I thought I had sign-in working the way I wanted. Saturday, I spent the day wrestling with the order that actions hit in Javascript.

    I am hesitant to say that I think I've got it, but it makes a lot more sense—no matter what path someone takes to a URL, make sure to bottleneck actions that need to take place in a certain order in order to make sure that everything related to cleanup happens when it should.

    Originally, the sign-in model we were given had login set with async: false, which is deprecated and rightfully so. A good portion of my day was spent looking at a repeated message from JQuery stating as much, and once I figured out what needed to happen—the user, on sign-in, throws a signIn event that other objects subscribe and respond to—I was most of my way to getting the interaction happening the way I want.

    This is a lot of wasted time, but I have to say that I really understand async events much better now, as well as pub-sub. Whenever I think I know what I'm doing, though, I learn more, so I'm reluctant to say that I know everything I need.

    One other thing happened in that was particularly frustrating. I removed my homebrewed utils directory from the manifest, only to change my mind and keep it in to be able to take advantage of a couple that I thought were useful. Well, for two hours I was getting weird behavior that, it turns out, was caused by my own implementation of router callbacks. Whoops, shit. I'll have to keep an eye on that sort of thing in the future.

    I've noticed that it's nice using a common naming scheme when creating files, but it often makes it challenging to figure out which show.js you need to be editing, or is throwing the error you're looking at. It pays to take the three seconds to verify what you think is happening is what's actually going on.

    I had a similar problem with Wordpress—I was making changes that didn't seem to be showing up in the final render, and I went down a lot of paths before I figured out that there are actually three different blog post views: all posts, posts by category, and single post. That's not DRY at all :(

  • Week 9 Day 5 - Presentation Day

    Well, not much to say… Today was presentation day, and I spent most of the day bug chasing, trying to get core features to work the way they needed to work and not the broken ways they had been. I feel like Javascript has more instances of dodgy edge behavior than any other language that I've worked in…

    Afterward, my peers and I spent a good amount of time talking about previous classes' projects. We thought, two weeks ago, that other people's projects weren't very good, but we came out today understanding just how hard it is to produce production-quality code in a short time period.

    I pretty much faceplanted on the presentation portion of the day. I want to go back to this project, to finish it up, but I know it can take as much time as I'm willing to give it over the next three weeks, or I can find other projects to also work on… time management will become even more important over this last period. Thankfully, we don't have to go in until 10:30 Monday, and this weekend will be a much appreciated break from the slog that was the project week(s), but … what will my portfolio look like? The pace doesn't ever end. What next? I have a book on Objective C, and an Arduino kit here, and I know that my portfolio might be able to say a lot about me, but what do I want it to say.

    Back to work Monday.

  • Week 9 Day 3 - The one good thing

    … about everyone having a slow day is that you can commiserate.

    I spent a while this morning moving items out of my TODO list and into Trello—might as well use it for something now that I have an account. I found that trying to read to-dos off of a serial text file is next to impossible, and until I can afford a more full-featured project management app, it should do the trick. (Why is OmniFocus so expensive?)

    From there I went down a rabbit hole of other people's code, doing a lot of thinking about separation of concerns and where and how views should interact, and how routers play into all that. The good thing is many people have asked themselves similar questions before; the bad news is that so many people have thought about it that there's no one good answer for how to address it, and Backbone is agnostic about the whole mess.

    That was most of my day. I did read a lot of code and learned more and more about how Backbone actually works under the hood (as well as playing with a number of neat Underscore functions) but at the end of the day what I have to show for it is clickable column headers that update the sort order of their associated table, and some utility code … not so much output.

    I'm already thinking about what I want to and need to do tomorrow, and prioritizing various tasks based on the knowledge that we'll probably have a 1-hour lecture at some point and that we have to present again on Friday… It's going to be close. Hopefully I'll have some "wow" by then.

  • Week 9 Day 2 - Movin' right along

    Today was the .css assessment, and after working late (and falling asleep while working a few times) and doing the practice twice, then studying the solutions last night and this morning, I kicked ass.

    To summarize: good design often has a logic, and good instructors are consistent, almost without fail. If there are exceptions, they are for a good reason - your instructor is working at the forefront of the field and the rules aren't established, the design language you're working with has some foibles that you have to work around.

    In our case, I've managed to pick up on and benefit from the design habits of our CSS specialist, Jonathan, and have slowly been trying to incorporate them into my own design language. For instance, set consistent (and generous) margins/padding, keep visual space symmetrical, tend to favor making item borders on the inside and container borders on the outside, … and so forth. I haven't built all of this into my site yet—it still looks like baby's first webpage, although thankfully not as 90s as all that—but there are a lot of things coming together very quickly.

    Case in point: investing in figuring out backbone means that I've basically added three full collections, three full models, and half a dozen views to my app today alone. I also added two utility … packages? files? to my app that enable some neat stuff, one that makes my life easier, and another that enables a pretty cool "live search" feature to the website.

    Yeah, it's all pretty silly overall—I'm reinventing the wheel—but I know why and how I'm reinventing the wheel here, which is okay by me.

    There's very little of what I'm doing that is really challenging now, which is okay after the weekend. To use a workout metaphor, this is my plateau, where I'm consolidating gains before looking for more of a training effect. Again, I'm okay with that.

    Meanwhile, I'm able to explain to a lot of people what their code is doing wrong, or able to sort through arbitrary code and understand it pretty idiomatically; I'm much more confident with git and am aliasing my most common commands regularly, and can find my way around Atom like nothing.

    Wow, they have taught us something. :P

  • Week 9 Day 1 - What day is it?

    I was actually going to post a partial update about my work over the weekend, but didn't manage to find the time. It might be a worthwhile task to do on my train commute, given that the normal sources of distraction are quite boring lately (although I suspect that others might think the same of my "content" on platforms such as fb).

    Long story short: after running a couple errands on Saturday, I made it to the office by 6 pm, and worked straight through until about 2am, slightly tipsy and having learning a whole lot about how rails and backbone routes interact. There are a couple people who were here when I got here, and I had a very enriching time between talking through errors and feature development. I ended up bouncing a lot of ideas off of one guy in particular, and that helped me nail down a particularly complicated process that had been giving me fits.

    Sunday, I woke up around 10 and started at the office around 2, and worked there for ten hours until the lack of running water in the building (long story) and the late hour drove me home. (I was also running on fumes, energy-wise). It was a long day of debugging, thinking through the backbone object model, and offering moral support to the other people working from the office.

    I, by no means, have the most broken nor the most functional app, but I feel that I'm in a good place right now—which is good, since I'm setting my own pace :P I'm confident in the kernel of my project: every re-factor so far has been on the order of 5-20 lines of code, with a noticeably left-leaning Poisson distribution (i.e. more short patches than long).

    Today, then, I woke up not sure what day it was, and I was somewhat disappointed to realize it was "only" Monday. When you work through the weekend, there's not much point trying to differentiate between each day. Nonetheless, today was better than a typical day at work, from my past life… this feels like just "what I do" now.

    One thing that I like about the approach I've been taking toward development is that at every stage, my app works. I have yet to have a period, once I finished the core view, that adding a feature caused another feature to fail. Part of this is due to my deliberate approach to development, thinking through how the features will interact down the road, but most of it is due to a highly incremental process of grafting features on sensibly.

    I do, however, wonder if I can keep this up.

  • Week 8 Day 5 - A brief pause

    It's telling about my state of mind that I tried using an Atom shortcut, namely cmd-enter, to insert a carriage return below the current line, and ended up instead sending my blog post off into the internets.

    We've all been staring at text editors for nine hours (minus breaks and lunch) and it's been a long, albeit productive, day. I can tell what everyone's up to and no joke I'm behind… however, I haven't asked for technical help or code review in three days.

    … I'm not sure if I should be proud or ashamed of this fact…

    My rails product looks pretty good. The models all work, modulo a couple details that will start to come out in the wash; most of the controllers are up and running well, and many of the views work the way I want. I'm starting to transition to Backbone—normally, we would have been doing three-minute presentations of our progress today, but that's been pushed off to Monday, at which point instead of showing our Rails MVP we'll be showing our Backbone MVP.

    What this means, for me: I have no free time this weekend. Or, more accurately, my free time will be spent in the arms of javascript and, more precisely, Backbone.

    Now that I remember how to rails, it'll be interesting to transition back to JS.

< prev 11 Feb 2015 to 10 Jan 2015 next >