string(4) "work" Work - Swiss Misfit


Javascript Strings, Properties, Special Characters and Escape Sequences

Javascript Escape Sequence Backslash

Javascript Strings, Properties, Special Characters and Escape Sequences

Javascript strings are used for storing sequences of characters. Javascript strings are enclosed within delimiters, most commonly, single quotes, ‘ ‘, or double quotes, “ “. Text within delimiters is commonly referred to as string literals, where literal means that the value is a fixed value within the source code. You can think of literals as the exact opposite of a variable. Variables can take many values depending on the circumstances, while literals are ‘fixed’ on a particular value.

’string literal within single quotes’
“string literal with double quotes"

Length Property

Javascript comes built with a length property for strings. The length property returns the count of characters found within a string. A value of 0 will be returned for all empty strings. In the below example, a value of 6 will be returned.

Length Example

var string = "Hello!"
> 6

Escape Sequences

In addition to string literals and regular printable characters, Javascript is able to produce special characters using escape notation or escape sequences. Escape sequences begin with a backslash or escape character. The escape character ( \ ) can be used to insert apostrophes, new lines, quotes, and other special characters into a string.

The table below lists other special characters that can be added to a text string with the backslash sign:

\’ single quote
\” double quote
\\ backslash
\n new line
\r carriage return
\t tab
\b backspace

Escape Sequence Examples

In order to familiarize yourself with these commands take a look at the following examples oh how \”, \\, \n, \t are used to manipulate output with escape sequences.

“I’m kind of a \”big deal\” around here.”
> I’m kind of a “big deal” around here.
“The file can be found on c:\\Desktop\\Files\\Document.txt”
> The file can be found on c:\Desktop\Files\Document.txt
”This is the \n beginning of the next line.”
> This is the
> beginning of the next line.
“My favorite movies include: \n \t Dark Knight Series \n \t Iron Man”
> My favorite movies include:
>     Dark Knight Series
>     Iron Man

That is about it for string properties and escape sequences. Now to take it a step further and call methods on strings to begin manipulating them. Check out my post about JavaScript string search methods to begin exploring how to work with strings.

JavaScript: Learning String Search Methods

Javascript String Search Methods: Inspecting Strings

JavaScript String Search Methods

String search methods are pre-defined methods built into Javascript that help developers find, edit, manipulate, and work with strings more easily. String search methods provide a number of very handy pre-built functions that drastically increase development efficiency while limiting the amount of code needed to perform actions.

If you haven’t had a chance to read my short post on Javascript strings, properties, special characters, and escaped sequences, I highly recommend it, it may help in your understanding of some of the search methods defined below. Additionally, if you are unfamiliar with zero-based numbering [0],[1], etc. check out the wikipedia articlezero-based numbering for more details. Zero-based numbering is a common theme in most development languages, and understanding it is critical to understanding string search methods.

Searching And Locating Strings Within Strings

Often times developers need to search within strings to find values. These values are then either returned to the program to display to the end user or return to the application for additional operations. This post will cover indexOf(), lastIndexOf(), and search() methods. In additional we will review their syntax, parameters, and finally examples of the method.

Finding Strings with indexOf()

The first method, indexOf(), can be called on any string object and returns the zero-based index value of the first occurrence of the searchValue passed. If the searchValue passed is not found, the method will return a -1 value.

indexOf() Method Sytax

string.indexOf(searchValue, fromIndex)


The method accepts two parameters, searchValue and fromIndex. searchValue is the value that will be used to search against the string that the method is called upon. The fromIndex value is the zero-based index that the search will begin from, the default value is 0, and obviously passing any value larger than string.length will return a -1 value.

indexOf() Example

var string = “I want to learn more about strings, so I am learning string methods.”; console.log(string.indexOf(“learn”));

Return Value

The console.log statement will return the value 10. Let’s count off the individual characters to see how we arrived at 10. [0]I, [1] (space), [2]w, [3]a, [4]n, [5]t, [6] , [7]t, [8]o [9] ,[10]l. The first occurrence of the word “learn” begins at the tenth index in the string.

Case Sensitive Note

It may also be worth noting that this method along with many other methods in JavaScript are case sensitive. This means that in our above example a searchValue of “Learn” would return a -1 value for the method call. The reason being is that “Learn” does not equal “learn” in respect to the method.

Finding Strings with lastIndexOf()

lastIndexOf() works exactly like its counterpart indexOf(), however it will return the last occurrence of the value passed in searchValue.

lastIndexOf() Method Syntax

string.lastIndexOf(searchValue, fromIndex)


Again, this method accepts two parameters, searchValue and fromIndex.

lastIndexOf() Examples

var string = “I want to learn more about strings, so I am learning string methods.”; console.log(string.lastIndexOf(“learn”));

Return Value

The console.log statement will return the value 44. It is grabbing the zero-based character index of “learn” within the word “learning”. The method doesn’t care whether the sequence is its own word or not, it only cares if the string has the exact same character combination as what is passed in the methods searchValue parameter. In this case it found that the exact sequence “learn” was in the forty-fourth position in the word “learning”.

Searching Strings with search() Method

The search() string method is a quick and efficient way to search a string for a specific value passed as a parameter in the search() method. The search() method returns the zero-based index, or position, of the first letter of the first occurrence of the the value.

search() Method Syntax


regexp is simply a regular expression object. If a non regular expression object is passed, it is converted to a regular expression. Don’t let this consfuse you if you aren’t familiar with regular expressions. I plan on writing an in depth overview of regular expressions, but for now read more aboutregular expressions on Wikipedia.

search() Examples

var string = “I want to learn more about strings, so I am learning string methods.”; console.log(“learn”));

Return Value

The console.log statement will return the value 10.

indexOf() and search() Similarities and Differences

You may have noticed that the returned values for both indexOf() and search() are equal. They both accept the same parameters and return the same values. These two methods are very similar, however with the ability to pass regular expressions as parameters within the search() method, developers can make much more powerful search functions. I like to think of indexOf() as a saw used to work with strings, and the search() method paired with regular expressions as a scalpel. They both help us accomplish a task, however one can be used with incredible precision to help us facilitate tasks that wouldn’t have been achievable with just the indexOf() method.

Functional SMART Tasks and Managing Development

Functional SMART Tasks and Managing Development Process

Sprint planning is a rigorous process driven meeting that most development teams, on a good day, don’t particularly enjoy. The process can sometimes feel like it drones on without any real value being yielded by the team. However, it is important to realize that sprint planning many times sets up the team for a success or failure for any given iteration. It is because of this why we must facilitate this meeting and create a sense of value add for each of the participants so that they can champion the sprint planning meetings and scrum process to other members within the organization.

Functional Smart Tasks and User Stories

User stories in almost any methodology can be described by the acronym INVEST, Independent, Negotiable, Valuable, Estimable, Small, Testable. User stories add a small slice of value to the overall product and in many cases formulate around a feature set or business initiative that stakeholders or product owner has defined as a value add to the product. User stories are comprised of tasks that represent the smaller sub units of work that must be accomplished in order to complete an entire user story.

SMART Tasks – Tasks On A Mission

SMART tasks are defined as Specific, Measurable, Achievable, Realistic and Time-boxed. Tasks need to be well defined and narrow in scope to understand the entirety of a task. The task must have a clear beginning point and end state in order to properly measure progress and status. Tasks should always be achievable given constraints and resource availability. If tasks are being assigned to individuals that don’t feel confident in its ability to be achieved the team needs to take a step back and understand what steps need to occur in order for this task to feel achievable. Finally a task must be achievable within a certain time period. Ideally tasks would last no longer than a day. Anything beyond a day may need to be broken down into additional tasks.

Writing Better Tasks – Functional Smart Tasks

We reviewed SMART tasks above, but lets take our task creation game one step further. Let’s introduce the idea of functional SMART tasks. Functional smart tasks align perfectly with development terminology. All programming languages contain functions, often times written as function(). Functions, when combined with programming best practices define a snippet of code that executes one and only one task. Think of all tasks within a user story as functions that when combined in sequential order achieve the objective of the user story.

6 Reasons Why Functional Smart Tests Benefit Process

Now for the reasons why you should actually care about why I am advocating for this idea. The benefits of functional smart tasks are limited to this list, however these are the primary reasons I continue to practice this method with my team.

1. Uncovering the ‘WHAT’ of User Stories

Functional smart tasks define the WHAT of a tasks objective, allowing for the developer to address the HOW. The how is the skill set that developers were hired to solve, and it is our duty as managers to trust and respect our developers to make the best decisions and provide the optimal solution. Developers who make how decisions are far more engaged and feel a greater sense of accomplishment when a user story comes together. It is this engagement that creates a happy work environment. This is one point that I can’t stress enough, manage the what and leave the how to your team.

2. Don’t Miss A Beat

Walking through functional tasks that comprise a user story will ensure that you won’t miss anything and you won’t include any unnecessary tasks.

3. Measuring Progress

Measuring progress it far easier and more efficient if you don’t need to add any additional tasks during the sprint.

4. Opening Up Dialogue

Discussion and questions centered around each functional task will greatly mitigate any misunderstandings or communication issues that may center around a specific task.

5. Swarm User Stories Effectively

SMART and functional tasks are independent, allowing multiple team members to work together on the same user story and effectively ‘burn’ down user stories in the order they are prioritized.

6. Setting Up For Test Success

Functional tasks lend themselves perfectly to unit testing, providing clear expectations for what tests need to be developed in order to meet acceptable criteria of each functional task.

At this point you are either sold on the idea, or are thinking this guy doesn’t know what the hell he is talking about. Hopefully I have done a fair job explaining the benefits and why of SMART functional tasks. Check out my article on How To Create Smart Functional Tasks to learn about team exercises and methods for creating SMART functional tasks.

Connect to MySQL Database

Connect to MySQL Database


In order to complete the following steps you will need to have a version of MySQL installed on your machine. If you are unsure type the following command in terminal. $ mysql --version

If a mysql version is not listed check out my tutorial on how to Setup Local MySQL Server. This will guide you step by step on installing MySQL and starting up a local MySQL server.

Run MySQL and Connect to Database

Now that we have our MySQL instance running we simply need to run MySQL and connect to our database file.


Within the terminal application we will execute the following command: $ mysql -u root -p

Let’s break this down into the details of what is being executed. This command states that we want to run ‘mysql’ and the ‘-u root’ option designates that we want to connect as the root user. The -p option tells mysql to prompt you for the password. In most cases the password will be blank. Simply hit enter when prompted for password.

Connect to Database

Notice how are prompt has now changed to ‘mysql >’? We are now running MySQL within the terminal! Our final step in this process is to either create a database file or connect to an already existing database file. In either case you will execute the USE command on the newly created database or the already existing database.

Create Database

What if you don’t have a database already? No problem, we will create a new database with the following command. mysql> CREATE DATABASE database_name;

This command tells MySQL to create a new database with the file name database_name. Now that we have a database we can proceed to use the database.

Use Database

At this point you either have an existing database you want to connect to, or you created a new database in the previous section. Time to connect to our database with the following command: mysql> USE database_name;

Import Data From Database

We have connected to an already existing database and now we need to import the data into the database. Use the following command to import the data from a source: mysql> SOURCE ~/directory/file_name.sql;

This command tells MySQL to import data from a .sql file on your machine. Your path may be different that the one displayed above, so make sure to define a clear path to wherever the file lives on your machine. To avoid needing to define an absolute path you could change directories to the directory that contains the .sql file prior to running MySQL. This would allow you to execute this command instead: mysql> SOURCE file_name.sql;

Setup Local MySQL Server

Setup Local MySQL Server

Setting up a local MySQL server can seem daunting your first time through, however the process is fairly straightforward and not nearly as complicated as it sounds. I will review a couple options to install MySQL and the terminal commands needed in order to setup local mysql server.

Installing MySQL

MySQL installation can be achieved in many ways, however I will be reviewing two methods that are widely used. The first is an installation directly through website. The second is through a popular package manager called Homebrew. If you are unfamiliar with Homebrew check out my more in depth discussion, Understanding Homebrew. I prefer the Homebrew approach given the hassle of creating an Oracle account when downloading MySQL through Direct Download

Downloading MySQL from the website is a bit more involved, but doesn’t require any prerequisites like the Homebrew option. If you have extra time I highly recommend becoming familiar with the Homebrew package manager. I promise it will be worth your time if you plan on adventuring into development.

  • Step 1: Downloading MySQL requires you to visit MySQL’s Website – and select the downloads tab in the main navigation. Beneath the MySQL Enterprise Edition utilities list select the “Download from Oracle eDelivery” link.
  • Step 2: Sign in or register an account with Oracle’s Software Delivery Cloud. Agree to terms and restrictions documentation and select “Create Account”
  • Step 3: Select the MySQL Database product pack for Mac OS X platform and press the “Go” button.
  • Step 4: Product results should now be visible below and I suggest downloading the DMG file labeled “MySQL Database 5.6.19 DMG for Mac OS X 10.7 x86”. Once the download has completed open the DMG and install the mysql-advanced-5.6.19-osx10.7-x86_64 package.

Homebrew Package Install

The Homebrew option is more technical in nature, but lucky for us Homebrew does a lot of the heavy lifting and keeps the busy work to a minimum.

  • Step 1: To begin we will want to install Homebrew to our machine. We can accomplish this by typing the following command in terminal. You can find terminal in /Applications/Utilities/ and as a reminder for those unfamiliar with terminal, we don’t actually type the $, that is just a reference to the terminal prompt. You should see the $ at the end of your terminal line. $ ruby -e "$(curl -fsSL”
  • Step 2: Once the download has finished we will use Homebrew to install git. Check out my series on Git, Getting Started With Git, if you are unfamiliar with git and why it is so awesome. Use the following command to download and install git. $ brew install git
  • Step 3: Now that we have git we are going to update Homebrew. Type the following command to update Homebrew. $ brew update
  • Step 4: Great job! In this Last step we will have Homebrew download and install MySQL to our machine automatically. $ brew install mysql

Congratulations, regardless of what option you chose, you now have MySQL installed on your machine and have one more step to go to a setup local mysql server.

Starting, Stopping and Restarting Local MySQL Server

In order to connect to a MySQL database or create a MySQL database, a local MySQL server will need to be started. The code to follow may look intimidating, but I will break it down.

Start Local Server

Within the terminal application we will execute the following command. $ sudo /usr/local/mysql/support-files/mysql.server start

This command starts up a local instance of a MySQL server. The ‘sudo’ preceding the command denotes that we will be running this command as a super user (SU), eliminating any issues we may have with permissions. Following the execution of this command you will be prompted to enter a password. This password is your account password, which is the same password you use to login to your Mac user. After entering your password you will be prompted with a success message.

Stop Local Server

Similar to start, execute the following command within terminal. $ sudo /usr/local/mysql/support-files/mysql.server stop

Restart Local Server

If you attempt to restart a server that isn’t running you may receive an error. “ERROR! MySQL server PID file could not be found!” This executed command first stops the MySQL server instance and then starts a new instance. Within terminal execute the following command. $ sudo /usr/local/mysql/support-files/mysql.server restart

Recent Projects
    Explore and discover new foods!

    Explore and discover new foods!

About Me Dal Price: SwissMisfit

I’m Dal, an enthusiast for all things technology, design, music, and food. This is a collection of inspirations, misfit thoughts, and random musings that may or may not be interesting to others.

Other Places to find me
  • RSS
    Feed updates from the blog

  • Twitter
    Bits of random 140 characters

  • Flickr
    So many pruty pictures!

  • XBox
    Pwning N00bs

  • Instagram
    Filters make my pictures better