Console.log is my friend (yours, too)

I don’t get to use a lot of JavaScript at this point in my new job, so to keep up on my JS skillz I spend some of my weekend time practicing old things or learning new things. Right now I’m learning Node. And while reading some code for a basic Express server, I was reminded of the lovely thing that is console.log.

Here’s the code:


var express = require('express')
var app = express()

var jsonData = {count: 12, message: 'hey'}

app.get('/', function(req, res){
  res.sendFile(__dirname + '/index.html', function(err) {
    if (err) {
      res.status(500).send(err)
    }
  })
})

app.get('/data', function(req, res) {
  res.json(jsonData)
});

var port = 3000
app.listen(port, function(){
  console.log('listening on http://localhost:', port)
})

I can see the code is pulling in Express, that it’s declaring a jsonData variable and assigning an object to it, that the get method will call one of two functions depending on the path that’s being requested, and that the listen method will show me what’s happening on my localhost:3000. And I can see those two get functions are going to use req and res, and I can see what happens with res…but what about req? I figure it’s the request coming in, but I have this need to know what all parts of all things look like, so how do I find out? Put a console.log in those functions, of course! It’s about a gazillion lines of data so I won’t repost it all here but at the very bottom, I see something like this for the first get function when I ask for the root path(‘/’):


route: Route { path: '/', stack: [ [Object] ], methods: { get: true } } }

And something like this for the second get function when I ask for the data path (‘/data’):


route: Route { path: '/data', stack: [ [Object] ], methods: { get: true } } }

Doing things like this helps the code make more sense in my brain. While I understood that the functions were taking in requests and returning responses, now I can see what the requests actually look like and I can see how the functions are seeing the path. Yay!

Flex-basis, flex-grow, & flex-shrink

Flex-basis, flex-grow, and flex-shrink are three Flexbox properties that can make things easier when dealing with responsive design. So what’s the difference between them? Let’s take a look at some code and find out!

Flex-basis is how much space we want our element taking up in an ideal world, before we start addressing extra space or less space. So in this instance, we want each of these divs to be 100px wide.

.div1 {
  flex-basis: 100px;
}

.div2 {
  flex-basis: 100px;
}

Now, when we’re viewing these two divs in any browser wider than 200px, there’s going to be some leftover whitespace. Flex-grow helps us decide how we want to divvy up any extra whitespace between our elements. So, as whitespace expands, div1 will take up twice as much of it as div2:

.div1 {
  flex-basis: 100px;
  flex-grow: 2;
}

.div2 {
  flex-basis: 100px;
  flex-grow: 1;
}

Flex-shrink helps us decide how we want our elements to behave as space decreases. In this case, we want div2 to shrink twice as much as div1:

.div1 {
  flex-basis: 100px;
  flex-grow: 2;
  flex-shrink: 1;
}

.div2 {
  flex-basis: 100px;
  flex-grow: 1;
  flex-shrink: 2;
}

To make it much more concise, we can re-write our code like this:

.div1 {
  flex: 2 1 100px;
}

.div2 {
  flex: 1 2 100px;
}

I hope that helps make sense of these three properties. If you want to learn more about Flexbox, you can’t go wrong with Wes Bos’ free series.

On object manipulation in JavaScript

Honesty is important to me, even when it means coming clean about things I struggle with. Today, I confess that I struggle with comprehending object manipulation in JavaScript. Earlier this morning I was pairing with a friend on some katas in Code Wars, and I was struggling to understand what was happening with this code:

let staff = {
  tim: 'finance',
  jim: 'accounts',
  randy: 'canteen'
}

function boredom(staff) {
  var map = {
    accounts: 1,
    finance: 2,
    canteen: 10
 }

  var score = Object.keys(staff).reduce((a, b) => {
    return a + map[staff[b]]
  }, 0)

  return score <= 13 ? 'kill me now' : 'party time!!'
}

As you can see, boredom is taking in the staff object, where it wants to match up the staff values with the corresponding numbers in the map object, then tally the numbers to produce a score and return that score’s relevant string. So theoretically I understood all that, but not this specific part:

map[staff[b]]

My brain was reading it like this…

map.staff.b

…which is sort of right, but also why I was getting confused.
I mean, map and staff are two separate objects, not connected in any way, so how is that working? Let’s walk through it! And by let’s I mean me, so I can solidify my understanding 🙂

Alright, so the first time through, a is 0 and b is ‘tim.’ Which means map[staff[b]] is basically map['tim']. And what’s Tim’s value? It’s finance. Since Tim’s value is ‘finance,’ map['tim'] is basically map.finance. And what is map.finance? That’s right, it’s 2! So the first time through, 2 gets added to 0, and on the next time through 2 becomes a, and b is now ‘jim,’ and on and on until the numbers are reduced down and boredom spits out how you feel about your office’s fun level.

Check out the reduce method on MDN.

Find out more about objects in Eloquent JavaScript.

And don’t forget, you can walk through code step-by-step on this site.

Thoughts from week 5 of coding bootcamp

Early in week 4 I’d wanted to quit for at least the 10th time; things got better after that. I don’t think it was because the material became easier or my brain suddenly understood everything – rather, I finally realized I am doing all I am capable of and there’s little sense in beating myself up over incomplete or not-up-to-my-standards homework. There is literally nothing more I can do. I barely see my family, my TV time is limited to Sunday evening’s Westworld, I haven’t gone to a movie or out with friends in who knows how long, I’m not doing the cleaning or the laundry or the cooking or the grocery shopping – all I am doing is bootcamp stuff!

And while my brain isn’t necessarily understanding things completely, it is beginning to grasp how all the pieces fit together and that’s making me feel a little less like drowning and more like (mostly) keeping my head (halfway) out of the water. I am still struggling with the execution of JavaScript itself, but conceptually I’m having no difficulties comprehending things like this, objects, constructors, or prototypes. We’re also dealing with Webpack this week and that’s been fun and interesting. If given the chance, I will still spend 10 hours of an assignment on the logic itself and maybe a half hour on styling and I don’t expect that to change anytime soon. JavaScript is just too interesting 🙂

Let’s learn about objects and this

No really, let’s. Because I’ve learned this already, but I need all the reviewing I can get. This should take 6-8 hours.

First, watch these videos by one of my very favorite JS resources, Mattias P. Johansson. (And later on, find time to watch all his other videos – he’s highly entertaining, very human, and also super nice on social media.) No need to code along.

Then read chapters 1 and 2 of this book by another one of my favorites, Kyle Simpson. You may, like me, feel both dumber and smarter after reading Kyle’s material, but that’s okay – he knows his stuff and it’ll be worth it. I like to code along with the examples Kyle provides, but you don’t have to.

Now, code along with Mary while she makes a fun little game. She moves fast and you may have to stop the video every few minutes to catch up. After you’ve got all your code written and working, watch the video again while adding comments to your code about what every single thing is and what it’s doing. You’ll learn more in this second run-through than you could catch in the first, trust me.

There, now you’re an expert! Okay, not really – but you learned some stuff, right? BOOM.

Thoughts from week 4 of coding bootcamp

Oof. Week 4 of bootcamp was tough. Tuesday morning found me feeling very down on the way to school. I wanted to quit. The day before, we’d been given an assignment using APIs, and I couldn’t get one small part of mine figured out. The issue wasn’t even getting the Ajax call to work – it was getting down into the right level of each object as I pushed them to the DOM in a table. This is the story of my JavaScripting life: knowing conceptually what I need to do and knowing how to do it, but missing one tiny piece of the puzzle. Terribly frustrating! But by Tuesday afternoon I’d solved my problem and was feeling good about the world. This lasted until Saturday, when I went to my third meetup of the week, and it all came crashing down again.

I’d wanted to quit in week 3, too. Actually, if I don’t want to quit at least 3 times in a week, I consider it a good week. Before bootcamp started, I had naive worries about the schedule, my class, the location. I never suspected the real battle would be convincing myself to keep going back. Every. Single. Day. Don’t get me wrong – I absolutely adore my classmates, our instructor, the campus director…everything about The Iron Yard, really – but it is hard to get a third of the way into this and still feel like I know basically nothing. Every day I feel like I am repeatedly throwing myself against a brick wall, with naught to show for it but a mutilated sense of self-worth.

(Pretty dramatic, right? I know.)

I’m trying to trust that this isn’t reality. That my brain is absorbing the things it needs to, and it’s all going to come together eventually. I asked a local Iron Yard alumni if she ever stopped feeling like she didn’t know anything, and she said it was in week 11 of 12. 7 weeks away. If you find yourself experiencing this during coding bootcamp, you’ll want to know how to hang on until then. Here’s what’s working for me so far.

Trust your instructor. So many times I’ve felt behind and didn’t want to do the morning exercises from our instructor; I’d want to read up on things to fill in the holes in my learning. But two days later, I would find myself relying on what I had learned during the morning exercises. Even when it’s frustrating, go with it!

Look back over your notes from previous weeks of class. Do you need those notes anymore? No, because you know that stuff by heart now. Tell yourself that in the future you won’t need the notes you’re relying on today. You will make progress!

Immerse yourself! You might as well, right? Read a JS book on the train, listen to a JS podcast on the walk, read JS blog posts in the morning with your coffee. Right before I go to bed, I like to give my brain one last concept to play with while I’m sleeping. The JS dreams are getting exhausting, it’s true – but if it helps me learn, I’m willing to deal with it.

Go to meetups for rejuvenation and inspiration!! I’ve mentioned that I’m terrified of meetups, but I go anyway – because no matter how bad my day has been, I always come away feeling amazing. Even the meetup on Saturday, which I felt woefully unprepared for and almost walked out of halfway through, reminded me that hey, I may not know anything yet, but JavaScript is still completely fascinating to me and I am on the right path.

It is so much info. Your brain is processing it whether you realize it or not. Hang in there. You can do it!

JavaScript thoroughly. JavaScript and repeat.

An image of a JavaScript book by Kyle Simpson.
A fantastic book series I read on the train to and from school every day.

This won’t be a ‘thoughts from week 3 of bootcamp’ post, because I have no thoughts left in my head.

There is only JavaScript.

If the thing I’m trying to think about is not JavaScript, my brain is just not interested, thank you very much.

The hour-long journey to and from campus every day has become a blur. Some days I cannot remember if I walked the final two miles or took Trax. Spans of time the length of entire workdays pass without me noticing. A couple of nights ago Dustin came home from work to find me sitting in the dark with my MacBook, not having bothered to turn a single light on during the past 5 hours because hey, not JavaScript. I misplaced my phone four times between heading upstairs for bed and actually getting into bed. One evening I was water-flossing while mulling over my code when my brain developed a solution, and I walked straight to my computer to write the code, accidentally leaving the WaterPik on – full and running.

My brain is only interested in JavaScript even when it’s supposed to be sleeping. I wake up multiple times a night to find it tossing around coding assignments in an infinite loop. I imagine what it must be like for my loved ones right now: They talk to a blank-faced robot about their daily struggles, and when they’re finished the robot comes to life and responds with a bunch of jibberish about callbacks, promises, prototypes, and inheritance. Frequently the robot has a breakdown and cries just like a human would, but don’t be fooled – it’s only crying about JavaScript.

It’s not like I want my brain to be this way. I appreciate its preoccupation with JavaScript, because my goodness, it is fascinating stuff – but damn, a girl would like a break! 10 hours of JS a day should be enough, right? I’d like to have oysters and champagne with Deez without thinking about let, const, and var. I’d like to shower without reminding myself, “Now I’m shampooing my hair, now I’m conditioning my JavaScript…” and 5 minutes later having to repeat the process. I would love to be able to answer questions like, “Do you want roasted peppers on your salad?” or, “Do you want a beer?” with a word besides, “What?”

I really can’t expect anything else of my brain right now with all that’s being thrown at it. The first two weeks of bootcamp were pretty chill compared to the acceleration that’s happening now, and I know our instructor is still holding back. How do people doing this without a support network survive? I’m trying to imagine not having Deezus doing the grocery shopping, cooking, cleaning, laundry, and offspring-wrangling while I’m in bootcamp, and I can’t even. I did all that stuff myself while in college and working full-time, which was incredibly difficult – and this is waaaaay harder than college! If you are a bootcamp grad who made it through without any help, @ me, because I need you to teach me things!

In the meantime, I’m going to go get some JavaScript.

Specks of victory

They warn you to be okay with being uncomfortable. You read a hundred blog posts that say the same. YOU RETWEET QUOTES ABOUT IT. You think to yourself, “It’s part of why I’m doing this, because I was too comfortable in my previous life – I was getting too stagnant.” But no…you have no idea.

No idea what it will be like to go from having every answer you need, from being queen of your domain, from feeling good about yourself because in general you’re doing shit right, to experiencing day after day of failure, to being thrown so off-balance by the paradigm shift that it even starts affecting the rightness of stuff you do in your home life, to feeling afraid to do anything at all because recent experience has taught you the probability of getting it right is NOT GOOD.

And you thought you had this discomfort thing down because hey, you’d already survived letting down the ones who count on you by quitting your cushy job; and hey, you’d already gone against everything you believed about money in order to take a giant risk with basically your entire savings account; and hey, you’d already spent countless hours over the last 16 weeks alone, with yourself, dealing with the crazy beasts inside your head. But no…you had no idea.

No idea that this discomfort would tear you down, but it doesn’t build you back up, no – it leaves you to fend for yourself, leaves you to sift through the rubble looking for the tiniest speck of ANYTHING you can call a victory. Last week you were aware that you had strengths and weaknesses. This week you only have weaknesses and a keen desperation to not feel like a fool. So you search, and you search, and eventually your brain comes up with:

Weakness: Teaching others.
Speck of victory: Within that inability to guide/teach someone else, there lies a window for them to find their own way. And I do have the ability to support people as they discover their own best way of doing things, and encourage them, and help them feel safe making mistakes.

Weakness: JavaScript solutions don’t come naturally to me.
Speck of victory: My code is organized, detailed, and at least I do understand what it’s doing.

Weakness: Basically terrified of meetups.
Speck of victory: I still make myself go.

And your brain has to be satisfied with these three itty bitty victories it found, because you now have 5 hours to sleep before getting up and throwing yourself at failure again. And you’re not quite sure if the rest of your life will be this way, but it’s the decision you made, so ÂŻ\_(ツ)_/ÂŻ

Thoughts from week 2 of coding bootcamp

Monday

1) We opened with some Markdown exercises. I can see its usefulness when blogging about things in specific languages. Despair as I think, “Will I ever get to that point?!”

2) Iron Yard students are expected to teach crash courses to the public, and take turns hosting the JS Learners group. This is awesome but terrifying. Who wants to be the teacher/host unable to answer questions, so students feel they wasted their time?

3) We reviewed our weekend projects in class (here is my GitHub page for it) and discussed what makes good visual design. It was actually pretty fascinating, which surprised me. Imagine knowing all the things that the eye expects and then how to make those things happen!

4) The global day of code is coming up and I want to participate, but I’d hate to get partnered with someone who has to carry me and do all the work. I am not a person who rides on others’ coattails and doesn’t contribute!

Tuesday

1) Okay, so CSS and all its inheritances is pretty dang cool. I can imagine it’s hard to be really good at CSS, which is funny since so many people dismiss it as easy, or as ‘not programming.’ But this person could be hella important on a team. I kind of want to go do all the learning on CSS now, but no time for that yet – JavaScript starts today.

2) We were given 5 JS problems as homework. I had a rubber duck moment with one – I was venting to my husband about how I couldn’t figure out how to do the Rovarspraket and as I was explaining it, it dawned on me exactly how to do it. Rubber ducking is not limited to tech of course – he responded that earlier that day, as soon as he started explaining a new process to his team, he realized he’d made a mistake and what it was.

Wednesday

1) Playing with JavaScript is fun, even if I’m writing the smallest, simplest function. So much more fun than HTML/CSS! (Sorry, my first week friends – you’re still cool, but…) I was familiar with the built-in methods for arrays but I had no idea strings had the same sort of thing and this just made my day. Spent a half hour reading up on regexes and am excited for when we are allowed to use those.

2) My poor spouse. Probably any poor significant other of a bootcamp student. He has to deal with me texting him little snippets of code I write, or showing him what I did at the end of the day because I’m so excited. He’s willing to listen even if he doesn’t understand, of course – because he’s the best.

Thursday

1) JavaScript comes easy to me, but it doesn’t come naturally. Does that make sense? Once I’m shown or figure out how to do something, I get it pretty quickly, but as for being able to pull out of my head a hundred different solutions to whatever is presented to me – nah, that’s not me. Not yet anyway. Accounting was the same way at first, but I did get to that ‘natural’ point eventually (after about 8 years, haha).

2) We did some more mob programming today. I thought I would dislike being the head navigator but I ended up enjoying myself immensely. I’m surrounded by smart people; when I need input or ideas everyone is ready to help out. I feel super lucky to be in this specific cohort.

Friday

1) Presentation day! Turns out presentations aren’t all that bad once I’ve had time for the slightest bit of preparation. Inspired by this blog post by Rob Martin, I presented on collaboration in tech, how mob programming is one of the ways we collaborate, and how we can be better collaborators. My five minutes was up way too soon.

2) For weekend homework we were given a project quite beyond what we’ve learned in class, but that’s okay – our instructor has given us the resources and techniques to find answers to our questions, so I’m still excited to give the assignment a try!

Also published on Medium.

Thoughts from week 1 of coding bootcamp

Monday:

1) They’re not joking when they say it takes energy and time – I’m ready for bed by 730pm. My brain is very happy, though. My brain hasn’t been this happy in a long while actually, and that’s something I require and a major reason I chose to learn how to code.

2) Everyone has their strengths and weaknesses. The person struggling with the command line today may kick your ass at CSS tomorrow; the person flying through git today may not know anything about HTML tomorrow. Help each other whenever you can, knowing that you’ll be the one needing help soon enough.

3) Last week I couldn’t have put together any sort of code while listening to music. Right now I’ve got Talking Heads in my earbuds, the presidential debate on the TV, and I’m cruising through stuff no problem. THE BRAIN IS AMAZING.

4) I already can’t wait to get up in the morning and do it all again. The people in my class are smart, willing, and funny, and I know it’s soon but I feel like they’re going to make it all worth it.

5) My goodness, I am grateful for a supportive husband. He met me for a cocktail after class and is now cooking a delicious dinner while I finish up some homework. And he woke up with me to do this:

An image of Ashly LaMarr on her first day at The Iron Yard.
“First day of class” pics are a big thing here in Utah. My husband surprised me with the sign and the pic 🙂

Things which may be difficult:

6) Mondays. Class is in downtown SLC and on Mondays Dustin works a block away. He’s a blast to hang out with and we’re surrounded by tons of great bars and food, so I will be sorely tempted to meet him at 5 on Mondays, regardless of homework completion. (Really, it’s a pretty great thing to struggle with.)

7) Being around people for 10 hours a day. Introverts, you feel me.

8) Finding a way to concentrate when surrounded by noise. Today we had some reading to do. I have ADD, which I choose not to medicate. I wanted to put my headphones in with some white noise while reading but was afraid this would be misconstrued as being shut off from my classmates or unwilling to cooperate. I don’t want to alienate my fellow students; I will have to find this balance.

Tuesday

1) More gratitude for Dustin. I came home to Pimm’s Cups and a bacon-covered meatloaf. I mean, seriously!

2) Ugh, could not be more disinterested in a subject than I am in HTML/CSS. I know its importance and I know I’ll have to know it and I can do it but I am secretly praying I won’t have to deal with it constantly.

3) I could take the Trax directly to campus, but instead I’m walking the two miles from the train station through downtown, then back again at the end of the day. SLC has a lovely downtown. So clean. So many friendly people. It’s a good way to work exercise into my day and I’m already worried about what I’ll do when the snow and inversions come.

4) Still love my classmates, but by noon I am drained from being around people and all the auditory stimulation it brings. Today I barely had the energy to walk half a block to grab a sandwich, and I was desperate to find a quiet little green space where I could sit and eat my lunch alone to recharge. Luckily my twitter followers had some great locale suggestions I’ll need to check out. So far, I think this is going to be my biggest struggle. I love the lively discussion during lectures, and helping or being helped by my deskmate, but if I don’t force myself to take those moments to be quiet and alone, I’m not going to make it. At a workplace I imagine it to be easier – surely I can go for a brief walk or hey, even hide in a bathroom stall if worse comes to worse. I am now fully coming to understand the word IMMERSIVE.

Wednesday

1) First day I wanted to flip off my computer. Forget you, CSS and your stupid :first-child, :last-child rules (this got better by the end of the day and I ended up gladly turning to it for the weekend assignment).

2) Gratitude today turns towards my classmates, teacher, and campus director. These people are the bomb.

3) Still exhausted, but not by being around others – just by the material. Two days in a row now I’ve tried to plan running a super short errand after class and just haven’t had it in me to do so.

Thursday

1) We tried out a version of mob programming today, and while I enjoyed it and could immediately see the benefits, I think it’s tough to do when no head navigator is designated. It becomes easy for some to fly under the radar, or to not feel valid/needed enough to share their ideas.

2) There was a discussion on work-life balance at lunch. I’m of the opinion that as long as employees allow ridiculous working hours to happen, they’ll keep happening. For 15 years I put my career ahead of everything else in my life, and I ended up paying for it dearly. I won’t do it again. I’m determined to always be in a position where I can walk away from a job that demands too much of me and my family.

3) A regional gent presented on Iron Yard career services and gave us some things we can start doing today, including updating our CV, social networking, and finding 10 companies we think we might want to work for. Right now I only know of one company, so looks like I have some work to do.

4) Much-needed easier day at TIY. We are three days in and I’m already a walking zombie and sleeping through alarms. My body hurts from sitting down so much, and my neck is demanding I get to the Apple store and get a stand/keyboard.

Friday

1) We have to present every week – eek! Following up on what Shawn spoke about yesterday, I presented on the benefits of social media networking as I’ve experienced them. I hate presenting. I never know what to do with my hands (note to self, next time hold the laptop and have something to project), I struggle to make eye contact, and just generally don’t like having attention on me. I may have been the worst presenter but hey, I survived and that’s part of what this class is for – a safe zone where we can fail (and often fail together). Loved getting to know my classmates even more through their super cool presentations.

2) Got a keyboard, stand, and mouse, and my neck is going to be so happy! Excited about the weekend assignment we were given and am looking forward to plugging in some music to my ears and just going to town.

Also posted on Medium.