Javascript: Finding the First Monday of the Month

Inspired by a PHP version of this found here, here is a Javascript function that takes the number of the month (0-11) and the year and returns the Date object of the first Monday in that month.  I find it useful for determining weeks in the month.

 // get first Monday of the month, useful for determining week durations

 // @param - integer: month - which month

 // @param - integer: year - which year

  function firstMonday (month, year){

 var d = new Date(year, month, 1, 0, 0, 0, 0)

 var day = 0

// check if first of the month is a Sunday, if so set date to the second

 if (d.getDay() == 0) {

 day = 2

 d = d.setDate(day)

 d = new Date(d)


// check if first of the month is a Monday, if so return the date, otherwise get to the Monday following the first of the month

 else if (d.getDay() != 1) {

 day = 9-(d.getDay())

 d = d.setDate(day)

 d = new Date(d)


 return d  


Please let me know if you find it useful.  Enjoy!

function firstMonday(month, year) { var d = new Date(year, month, 1, 0, 0, 0, 0) var day = 0 if (d.getDay() == 0) { day = 2 d = d.setDate(day) d = new Date(d) } else if (d.getDay() != 1) { day = 9-(d.getDay()) d = d.setDate(day) d = new Date(d) } return d.toString() } firstMonday(10, 2011)

Two Months in … Working at Axeda

Two months into being an Innovationeer at Axeda, I ace the “waking up to work in the morning” test with flying colors.  Who wouldn’t want to be at the cutting edge of technology, with knowledgeable peers and mentors actively looking out for me, working on projects that are not only competitive, but compete with entire industries?

Let me say that again – each and every application built on the Axeda Platform models an entire industry.

Axeda’s signature product, the Axeda Platform is a secure and scalable foundation to build and deploy enterprise-grade applications for connected products, both wired and wireless.

Got a vending machine?  Connect it and harvest data for marketing.  Own a fleet of trucks?  Find out their location, speed, and maintenance history.  Work in the health industry?  Monitor your patients’ statistics transmitted from their mobile devices, while they check into their appointment on a kiosk that feeds your dashboard.  Providing solutions as diverse as the products they connect, the Platform’s full potential is waiting to be realized. 

With all this excitement, can you believe they’re still hiring?  You too can witness the emergence of a connected planet, or you can be the one who makes it happen.

Contact me today if you’d like to submit a resume or drop me a line on Twitter where you can find me as @saranicole .

Train Your Brain to Code

brainA brain is a lot like a computer. It will only take so many facts, and then it will go on overload and blow up.

– Erma Bombeck




One could argue that writing code can be boiled down to writing a series of AND, OR, and NOT statements.  Anyone who has seen assembly language knows the fundamental commands do not vary a whole lot.  So why is it that tutorials advertise “no coding necessary?”

There is an art to coding that is hard to pick up without doing the work.  I learned this from my own experience of coming from a humanities background and expecting it to be like picking up a language.  Learning the programming language is an important aspect, but the language has far less bearing compared to understanding the underlying technologies.  It’s like needing to know how acids and bases interact before you invent a new recipe.

1.   Play logic and math puzzles

If you’re not a puzzle type (I’m not), seek out opportunities to challenge that part of your brain.   Puzzles will teach you an intuitive grasp of the underlying math and logic so essential to the function of computers.  They will also train you to be thoughtful and persistent, qualities that will make you a successful coder in the long haul.   Check out for a nice selection.

2.  Break the task into higher level chunks

It’s tempting to start off a coding project by drilling down into the nitty gritty of how each and every function will work.  Learn to leave stub functions and classes for later and focus on the overall structure first.  Raise your view from the 1,000 foot level to the 10,000 foot level.  See the whole, then map out finer grained sections.

3.  Limit your use cases

Take on a specific type of coding when you’re beginning, such as website or app development.  You will become familiar with a small spectrum of tools, and that in turn will get you started on the thought process needed to build software.  By all means branch out once you’re bored, but when it’s new to you, avoid tackling Arduinos, ActionScript and APIs all at once.

How do you condition yourself to approach the ultimate coding mindset?  Or is there a way to bypass the limitations of the coder?

The Art of Breaking Your Design

ro·bust·ness: the degree to which a system operates correctly in the presence of  exceptional inputs or  stressful environmental conditions.




I had the bittersweet experience of watching my app break in a demo, bitter because everyone was watching and sweet because it was a demo.  The failure resulted from my assumption that the wireless network would be dependable, which sounds silly now in retrospect.  Proper error handling would have allowed the app to fail silently instead of exiting with an exception which is what it did.  Not only that but it would have been great for me to have the app pick up where it left off when the network was restored; instead I was obliged to perform manually the task left unfinished by the premature exit.

What I should have done is break my design pre-emptively.  Tests for robustness are a priority, not a nice-to-have.  I offer a few tips based on my experience …

1. The Test Environment != Reality

This one is a doozy – don’t assume that since the app works in the test environment that it will work under the stress of real circumstances.  Try to test in the field if at all possible.

2.  Write tests with assertions you don’t expect

Testing for expected inputs isn’t what will tell you whether the app will fail.  Test for the unexpected inputs which could actually break the app.  The weirder the better.

3.  Document Everything

The more you write about your code, the more chance you will see the failed logic you missed the twenty previous times you looked at it.  Teach the technique in a blog post or a tutorial, and make sure to write readable code with comments.

How do you test for the “real world”?  Or should we let the users drive the fixes?

Not Enough Time? Try These Tools


Much may be done in those little shreds and patches of time which every day produces, and which most men throw away.
- Charles Caleb Colton




With blocks on your schedule filling up, it’s easy to overlook the nuggets of time that, with proper management, allow you to recapture the value of your day.

The first question to ask is how do you want to be productive?  Try mind-mapping your thoughts in order to answer this question.

Mind Mapping – a mind map is a diagram used to represent words, ideas, tasks, or other items linked to and arranged around a central key word or idea (from Wikipedia)

FreeMindpremier free mind-mapping software written in Java

MindMeisteronline mind-mapping tool with real-time collaboration and mobile apps

Further discussion of the uses of mind-mapping available here

How will you keep track of the results of your efforts?  Create a searchable notebook.

Searchable Notebook – whether it be a personal wiki or an emailed note to self, having a central place for your notes can boost your time management

Wikihost a collection of public and private wikis to publish content, share thoughts and find people with similar interests.

Evernotesave your ideas, things you like, things you hear, and things you see, available as a mobile app

Further discussion about personal wikis here

Spend a lot of time commuting?  Use a portable mp3 player to listen and learn.

Podcasts/Audiobooks – make use of your time by learning and reading.

Open UniversityiTunes provides search for free lectures via podcast at Open University

Librivox LibriVox is a volunteer-driven provider of audiobooks from works in the public domain

A list of sources of free audiobooks may be found here

What tools do you use to get better value from your time?  Or do you have enough already?

Growing out of Crisis Mode

A term I hear often at work is “fire drill.” Priorities get elevated until there’s a problem and suddenly all eyes focus on it, scurrying for a solution. This surplus of effort detracts from other priorities, allowing them to inflate and erupt in a chain reaction of multi-stress. Not fun, and not efficient. Much of the energy is wasted in commotion which would be better spent re-engaging with the larger picture.

How do we go about de-escalating a fire drill?  First, stop escalating.  Keep control of the urge to move the issue up the chain of command.  Think it through with co-workers on your management level.  Second, relax, breathe, and step away for a brief amount of time.  Write through the problem if it helps.  Sometimes a simple break can give your mind the rest it needs to reset.  Finally, consider a re-do rather than patching up what’s already there.  A whole new version may seem like overkill, but piecemeal edits may gloss over the underlying glitch that created the problem in the first place.

Do you want to leave crisis mode behind?  Or can a crisis improve your overall results?

Being a Survivor of Change: Does it Get Better?

What does change feel like to you? A trickle? A stream? A firehose? Is there a degree of change that is easy for everybody to deal with, beyond which it becomes a hassle, then a crisis?

When I graduated with my Bachelor’s back in 2002, I had never experienced real change. I was not prepared for that in-between transition that feels exactly like failure. For a student with debt and no job, the years of hard work in school seemed like a waste.

I lived through that transition with the support of my family and went on to find my first full time job. Years later, I changed careers and found work as a software engineer. All in all, it took me nine years to become a professional with a definite career path.

This transition would have been smoother if I had anticipated change and seen it as a normal fact of life. Then again, is it possible to understand that without going through it first? What do you think?

Popping kernels: how long does good writing take?


In the age of print, lengthy articles gave readers the feeling that they got their money’s worth.  Writing was planting a seed that bore fruit, but only after investing a certain amount of time, emphasizing quality over quantity.

140 characters revolutionized the idea that content has to be lengthy.  If print is fruit from a seed, short real-time content is popcorn from kernels.  This style does not have to be at the cost of quality, but takes the philosophy that if you put that much out there, some of it is bound to be good.

Fishing for a sunburn: the guaranteed outcomes of taking action

How satisfying is it when you set out to accomplish something, strive for it and get it, all in a nicely packaged crescendo to climax?  For most of us living in the real world, these sorts of single-play successes are not the norm.  Instead, we have to work at it with patience and persistence, and the payoff may not come with a rest, but with a call to more work.

I went on my first deep sea fishing trip yesterday and spent eight hours on the water.  That’s eight hours of casting out, reeling in.  We didn’t come back with a fish, but guess what I did come back with?   A nice red sunburn with white raccoon eyes where I had sunglasses on.  Yes, I should have put on sunblock, I even had it with me.

A fisherman will tell you that sometimes you come back with a fish, sometimes you don’t, that’s why it’s called “fishing” not “catching.”  A blogger will tell you sometimes you hit linkback gold, sometimes not.  On the other hand, take a moment to think through the guaranteed outcomes of your work.  Will you build up experience, wisdom, a work philosophy and ethic?  As a blogger, every post you write is another post you can point to for an employer or as a writing sample.  We don’t all need to reach a huge audience or instigate global change.  Those are the “nice-to-haves.”

How do you make use of the incidental, guaranteed outcomes of your work?  Or does reaching a certain goal makes it worthwhile?

Cherry Equity – can it work for Content?

When I started running daily back in August 0f 2009, I was worried that I wouldn’t be able to keep up the habit.  I had tried running regularly before, but over time I would get lazy.  As a solution, I created an incentive system that kept me from petering out.

I called it Cherry Equity, and how it worked was if I ran twice in a day, once in the morning and once in the evening, I would earn two cherries the following morning.  Actual cherries,  a big bag of them.  If I did really well, I would earn an extra bonus cherry.  On the other hand, if I skipped an afternoon run, I would only get one cherry the following morning, and if I skipped a morning run, I would lose out on the whole reward.  The key to success was the fear of losing out on cumulative rewards.  If I had one cherry after every run, it wouldn’t have been as big a deal to lose the reward after one or the other.  On the other hand, losing out on a reward I had already earned was a drag.

Having come a year and a half of no longer needing cherries to keep up the habit of running, I find I would love to apply the system to writing content.  I am very sporadic when it comes to writing, but with a cumulative incentive system, it could work.  The question is what kind of incentive works well for writing, flavored pens?  I need a real content strategy, and writing twice daily could work but it will hinge on having a real reason to do it.  What’s your reason?