Saturday, August 29, 2015

getComputedStyle(), where have you been all my life?

I learned about a new DOM method tonight: window.getComputedStyle().MDN Link

From what I read, you can use this to get the style of an element that is set by an existing stylesheet.

Why did I learn this?

I was trying to cement the things I've learned about JavaScript Events and the new HTML audio/video things in the TreeHouse course I'm currently on. I actually thought of a little project to apply this knowledge to. A simple page with two buttons. When you click the video button, a div with a music video embedded in it pops up. Click the audio button, you get an audio player. I wanted them to toggle, but first things first, get the content to appear when I click the buttons. 

At first I used display: none to hide everything, but then I switched to visibility: hidden instead. Another new thing I found. I liked the space it left better.

I expected to do this for about 20, 30 minutes tops. Nope. It was a good hour or so. Of Googling.

I got to this point where it was working, with a hitch:

videoButton.addEventListener("click", function(){
  
        musicVideo.style.visibility = 'visible';
  
}, false);

That worked. The hitch was that I couldn't get a toggle to work. This is without jQuery mind you, because the classes I'm taking are all doing the vanilla stuff right now, and I wanted to try it the hard way. jQuery would have got me in bed sooner, but I wasn't having it!

If I tried to set up a toggle, I had to click twice to show the video and it wouldn't hide again. The stylesheet was right, everything was there, but earlier I had gotten null errors and general unresponsiveness if I tried a 'if hidden make it visible else make it hidden' deal. Almost said screw this I'm getting a snack.

The problem was that I was using .style.visibility when I was trying to check if the div was hidden. I guess .style checks for dynamically placed styles. It's all a blur now, but it seemed like clicking was removing the hidden value, adding back on then switching it to visible, hence the two clicks. My style declarations weren't being taken into account. This wasn't Git-worthy so I wasn't doing version control on it (I know, I'm sorry).

After a bunch of searching I found window.getComputedStyle(). This checks the styles that exist in the document on load, meaning the .css file attached to the page. So I was able to do this:

(I grabbed the button and saved it to the variable videoButton to save some keystrokes)
videoButton.addEventListener("click", function(){
   var musicVideo = document.getElementById('musicvideo');
   if(window.getComputedStyle(musicvideo).visibility === 'hidden'){
        musicVideo.style.visibility = 'visible';
   }else{
    musicVideo.style.visibility = 'hidden';
   }
}, false);

I click the button, it checks for visibility: hidden, then makes the musicvideo div visible. If not, it hides it again. Same things goes for the audio section.

It was a long slog trying to get those search queries right and weeding out the "just use jQuery" answers, but I found something. Something that's not being given to me in a tutorial. I feel good about it.

(I just looked at my todo note and I wrote 'use jquery to toggle'. I like making things difficult, don't I? But it was educational)

Now I'm going to watch some youtube videos guilt-free.

Thursday, August 27, 2015

I added some comments to an old piece of Epicodus code I wrote about a year ago. Someone in the fcc help channel mentioned the reverse a string thing, and I thought, "I did that before".

As usual, the standard split/reverse/join on MDN didn't want to work in my console. I might have skipped a conversion or something.

Plus I don't remember what's an array method and what's a string method. I tried to memorize them in the past, but it never sticks.

So it took a minute to look over my code and see why it's longer than that one line.

For the sake of quickness, here's the main function:

var reverseInPlace = function(string){
  //turn the string into an array of words
  var splitstring = string.split(" ");
  //array for the words as they're being reversed
  var reverseArray = [];
  
  for(var i =0; i < splitstring.length; i+=1){
    //removes 1st word from array
    var word = splitstring.splice(0,1);
    //turn it into a string, then splits into array of letters
    //reverse array and rejoins as string
    word = word.join().split("").reverse().join("");
    reverseArray.push(word);
    i-= 1;
  }
  var reverseString = reverseArray.join(" ");
  return reverseString;
};


I wasn't terrible. At least I went above and beyond turning a single word around.

I'm at the jQuery part of Free Code Camp now, so I should be back to thinking like a programmer soon.  The chat room thing went okay today. The local chat rooms closest to me are dead whenever I check them, so I stayed global. Hopefully it keeps going well.

Social media woes.

I don't know how to make friends online. I suck at it. It seems the more I talk, the quieter it gets.

Maybe it's the moderate depression shining through. I don't know. It's not something I can hide under a fake smile. That wouldn't be honest. Besides, it's not like it's something I talk about. Much. I mean to say I don't get deep into it in public.

Seeing people I talked to a few times listed as "not following you" kind of stung. I don't tweet much because I don't want to discuss my sorrows; I keep up that illusion of "things are semi fine to great" that most people swear by. I have talked about family emergencies. Maybe that's too real? I try to talk about programming but I'm so rank beginner it feels shameful.

I was tempted to ask one person why but I don't want to feel worse. I'm stopping at telling myself it was probably nothing personal. And not conflate it to something worse.

I do feel like I'm a pile of bad luck. I wonder if I can find some newbies to talk with. They're probably all at their local meetups, that I have no access to.

See? My thinking snowballs when I'm sad.

I try to keep a happy face on. But when personal stuff weighs you down and it looks like you're the only one that feels that way, it's difficult.

Sunday, August 9, 2015

I'm on TreeHouse trying to work through some tutorials and doing a bad job of it. To take a break because my concentration sucks, I went to the unanswered question section in the forum.

The question was already answered but it was a "Take a look at my code" thing. It was for the random number generator in the JS basics course. I tried to run it then start trying to fix it. It took a little longer than it should have because the guy had plenty of misspellings and extra parentheses that were making it weird.  I rewrote the meat of the code and it ran. Hurray.

That was kind of fun. Have to find more experiences like that.

Friday, August 7, 2015

Junk to do

I need to get back on Treehouse again. I tried watching videos on my phone but the connection decided to become unreliable. When it wasn't I was trying to work and make a few dollars. The tethering actually worked well when it wasn't 2G. It's limited though, not a new concept to me.

Now that I'm not worrying about bandwidth I've been doing the mturk thing and not a lot else. Because money unfortunately comes before the other stuff.

I have to look at some new job sources. Mturk actually picked up a bit, even though they raised requester rates. I can start automating things more, which might add a few cents per task, I hope. But I have to prepare for the worst.

I wish I could change bad habits in 10 days that easily. Criminy...

The long nightmare is finally over. Tell that to my mind, please.

I gots that cable internet now.

But two years of being ball and chained by Exede got me out of the habit of thinking "let me look that up real quick". Until Tuesday, my internet usage consisted of counting every byte and writing notes to myself for anything major to do in case I forgot when midnight rolled around, when the "free zone" happened that didn't count against the data cap.

I downloaded youtube videos to my hard drive so I could watch them during the day, grab podcasts and music and try to do coding tutorials all in that 5 hour period. I'm human, so it wasn't all work, which made it harder. And if it went out that night, tough shit! No rainchecks.

It made my already messed up sleep patterns worse and choked my motivation. I'm pretty sure I killed some brain cells. My myopic vision is more so. It's over but I still feel like I'm in jail. I'm still fucking with my phone when I can just use the computer and be done.

I wonder if I could have progressed further if it wasn't for that worse than dialup bullshit I had to work with. All those live coding vids I had to pass on, all the Japanese language streams I couldn't absorb new words from. The time lost.

Now I have to learn to be a spoiled, impulsive first world internet brat again. God help you all.

But I won't forget.

Sunday, August 2, 2015

No internet, no problems?

(Typing on this phone is bad even with the stylus. You go too fast and it puts spaces where they don't belong. Can't calibrate the damn thing either. LG must hate lefties. I've had to backspace so much for this tiny post.)

My only internet connection for the past week is through my phone. It's shaky, I can't work or watch a lot of tutorials because the connection isn't stable. When it is stable (It's happened twice) I work my ass off doing tasks until it drops out again.

No TV either, until mom begged directv to take her back. My set top box is on the other side of the room. I've liked the quiet. The only thing I've missed is being able to have news on in the background. Eventually I'll hook it back up. Law & Order SVU reruns aren't going anywhere.

Why all this 1990s living? Charter didn't test before they set up the install. The cable was cut so they said they would put a rush on the repair. No follow up call or anything else. I just happened to call to get dates. I see why Charter has a shitty reputation. But don't they all? It's the only option where I am so all the complaints in the world won't change them. Because they're still getting paid. I told them how inconsiderate it seemed and they didn't give a fuck.

The connection better be worth having to grovel like a dog for. People still steal cable and I can't judge.

I'm hoping Tuesday's the day I can get online like the cool kids again. In the meantime I'll sit here with my thoughts a bit longer. I won't have to stay up all night to watch a damn YouTube video. No ridiculous caps. I hope I can make up the non turking days with the speed alone.

I'll be able to watch the FreeCodeCamp stuff too. Since they rehauled it and community college in nc seems pretty fucked (or I'm catching every single person on their bad day) I need a way to at least build up a body of work. Things are pretty bleak right now.

Please let this actually happen. I don't want to be here the rest of my life.