JavaScript

String Replace in JavaScript

Today, I had the need to do a String.Replace in JavaScript. I thought, “surely, this is an easily solved problem”. It turns out that I was both right and wrong.

A quick DuckDuckGo search brought back that I could do something like this:

var input = "I hate Fridays.  Fridays are the worst!";
var output = input.replace("Fridays", "Mondays");

I would expect the value of output to be “I hate Mondays. Mondays are the worst!”. But it isn’t. Instead, the value is “I hate Mondays. Fridays are the worst!”, because the replace method will only replace the first instance of the match.

The first solution that I found to this was to modify the code to use a regular expression, which the replace method also takes. All you have to do is include the RegEx and the “g” flag to make the replacement global. That would make the code look like this:

var input = "I hate Fridays.  Fridays are the worst!";
var output = input.replace(/Fridays/g, "Mondays");

This does give us the correct output of “I hate Mondays. Mondays are the worst!”, but if this were to be a reusable method or a pattern throughout an application, getting the correct RegEx can be tricky to debug or come back to later. Not everyone is a RegExpert. That’s why the next solution that I found was ingenious and was the one that I ended up going with.

In this code, you split the string on your “outgoing” string, and join it back together again with your “incoming” string. That would look like this:

var input = "I hate Fridays.  Fridays are the worst!";
var output = input.split("Fridays").join("Mondays");

That gives us our correct output of “I hate Mondays. Mondays are the worst!”. This method can be slower in some browsers (This JSPerf test has Split/Join as coming out ~40% slower in Chrome), but if you aren’t doing this several hundred times in a loop, I think the readability and maintainability of the Split/Join way makes this easy to do.

Android

Podcast Episode 26 – Rondale Williams on Android and Breaking Into the Game

Rondale WilliamsThis time, in Episode 26, I interview Rondale Williams. Rondale is a freelance mobile developer new to the development space. During the course of our interview, Rondale talks about what it is like to be self-taught, why he started to go back to college for CS, and what his advice would be to other people just starting out. We also talk about RxJava, Android Emulators, the Android vs iOS development ecosystems, and whether or not he’s found the community to be friendly.



Links Mentioned in this Show:
Rondale’s Blog
Rondale’s Twitter
Rondale’s LinkedIn
RxJava
Genymotion
Lynda.com
Pluralsight
The New Boston (Bucky’s World)
Udemy
Udacity
Meetup
RemoteCoder.io

You can also subscribe to the podcast at any of these places:
iTunes Link RSS Feed

Thanks to all the people who listen, and a special thanks to those who have rated me. I really appreciate it.

The episodes have been archived. Click Here to see the archive page.

Podcasts

Podcast Episode 25 – Increasing Productivity

Productivity - Pomodoro Timer

Episode 25 is all about increasing productivity. It isn’t about getting into the “zone” or getting into the “flow”. It isn’t even productivity hacks like “Listen to all podcasts at 2x speed” (which is a good tip and I do it every day). This episode is full of useful “rubber meets the road” practical tips that you can use to become a more productive developer.



Links Mentioned in this Show:
Trello
.Net Rocks! – Getting into the Zone
Parkinson’s Law
Entrepreneur On Fire
James Altucher – How to be a Super Human
John Sonmez
Pomodoro Technique
Music to Code By
GitHub Student Developer Pack
ReadMe.IO

You can also subscribe to the podcast at any of these places:
iTunes Link RSS Feed

Thanks to all the people who listen, and a special thanks to those who have rated me. I really appreciate it.

The episodes have been archived. Click Here to see the archive page.

Podcasts

Podcast Episode 24 – Wolfgang Goerlich Talks Application Security

J Wolfgang GoerlichEpisode 24 was planned to be timely, but it ended up being super timely. Originally, I wanted to have Wolfgang Goerlich come on and talk about application security after the iCloud photo leaks. But, between the time that we recorded the interview and the time I’m releasing this episode, the Shellshock bug/vulnerability came to light as well. Listen, folks, writing secure software is hard! Wolfgang talks about the average day in the life of the good guys, what mindset makes a good security expert, how developers can write more secure code, why the Internet of Things might be a security nightmare, and why you shouldn’t “poke the bear”.

Links Mentioned in this Show:
Brakeman
Visual Studio Code Analysis
Converge Conference
OWASP Detroit
misec
OWASP
Viopoint
Wolfgang’s Twitter
AFNetworking v2.0 Dimecast (Link Removed)
JSONPlaceholder

You can also subscribe to the podcast at any of these places:
iTunes Link RSS Feed

Thanks to all the people who listen, and a special thanks to those who have rated me. I really appreciate it.

The episodes have been archived. Click Here to see the archive page.

Dimecast

Screencasting is Fun

Recording Doctor Swift BSo, ever since I did my first Swift screencast on my YouTube channel, I’ve been hooked on Screencasting. Earlier this month, I let you guys know that my first Dimecast was up and that just broke open the floodgates. To date, I’ve done a total of 7 Dimecasts this month (with number 8 coming in the next few days). I already linked to my first one, but here are the others that I’ve done.

Intro to Swift Programming
Learning Objective-C Part 2a
Learning Objective-C Part 2b
Intro to CocoaPods
Intro to Swift Programming Part 2a
Intro to Swift Programming Part 2b
(Links Removed)

I’ve also made all of the code available on GitHub for everything that I’ve done and I will for every Dimecast that I will do.

I’m having an insane amount of fun making these videos. I really enjoy it. I like thinking of topics that I can cover, inventing projects for them, practicing, recording, and even editing. The biggest difficulty that I’m facing is that I don’t have a quiet place to record. I have to either get up very early or stay up very late to be able to get ~10 minutes of silence. Even then, it doesn’t always work out and I have to wait and then edit out the noises or else there is occasionally some noise in the background.

Even with that hassle (and setting aside my fantasies of a sound-proof “studio”), I’m finding this entire creative process very fulfilling and I hope that people are getting value from it.