Package.json engines (don’t you dare forget to specify them)

One incredibly powerful tool for NPM is their package.json. It allows you to set the tone for what your project is going to contain, how it will run, and a million other things it seems like. It is a very powerful little file! And it’s all in JSON!

But like they say, “with great power, comes great responsibility”.

One very cool ability of a user’s package.json, that I have often times not seen people taking advantage of, is specifying their engines. In today’s day an age of NVM and our ability to quickly and easily hop between node versions (and in doing so, NPM versions), we lose track of exactly which combination of NODEjs/NPM work with certain projects.

This is where the developer(s) of the project should be using the engines property to set the tone for what works best with their project. It’s a simple add to their file and can certainly save others lots of time and headaches.

An example of specifying just your node and npm version is below:

"engines": {
    "node": "^0.10.x",
    "npm": "^2.11.x"

So I beg of you, if you are building something that has a package.json, do include the engines specification. I promise you others will be grateful.

So, you want to publish your first NPM module?

You have just written some badass code.
You want to share it with the world.
You think it will make the perfect new NPM module.

BUT… you have no idea what to do to make that happen.

No worries!!

It’s simple, fun and I am here to walk you through the process.

Lets start with the code you have written (this post assumes it’s written in NodeJS).

A sure fire way to get users digging your new module is making sure that once they require it into their project, that it is easy to use.

A couple of ways I have found for doing this are simple.

First, if your code is a cool function that you want to give to the user:

module.exports = function(data) {
// Your awesome secret sauce here

Now your end user can use your cool new module like this:

var coolNewModule = require('yourModule')

Pretty simple, right?

Now I know what you’re saying, “But Kevin, what if I have a bunch of cool functions I want to give the user?” Great question!

Here’s a great and simple way to do that:

function one (data) {
// whoa, awesome function dude!

function two (data) {
// Holy cow, even cooler function!

module.exports = {
one: one,
two: two

What this is doing is returning an object where the value of each property is actually set to the cool function you just wrote, also affectionately referred to as object methods 😜.

Your end users would now be able to use the functions like this:

var coolNewModule = require('yourModule')

“But Kevin, what If I just want to deliver the end user with module that simply takes an input and delivers a transformed output ?”

That’s a great question and it’s also really easy!

module.exports = function(data) {
// your awesome code that transforms stuff...
return {
//...will ultimately return this awesome newly formatted object

Now you end user can use it like this:

var coolNewModule = require('yourModule')(data)

How cool is all that!

“Kevin, how do I actually get it onto NPM after writing all that awesome code”

A few prerequisites:
1.) Make sure you have a ‘package.json’ set up correctly in your project (This shows more about package.json files clickMe)
2.) Make sure you have a NPM user
3.) Tests aren’t a bad thing to have in your project either 😛

**For this part, make sure you have already created a user on NPM

A simple 3 step process will get your cool new module published:
1.) Inside you terminal, CD into your awesome new project and run ‘npm adduser‘ and follow the prompts on the screen.
2.) Ensure things have been set up correctly by running ‘npm config ls‘ (you should see all your configs printed out)
3.) This is the one you’ve worked so hard to get to… run, ‘npm publish

And just like that you are now an open source contributor!!

Give yourself a pat on the back and keep contributing, because the world needs more people like you!

If you would like some video guidance on those 3 steps, be sure to check out this awesome video that NPM has already put together VIDEO

Utilizing Dropbox API to store file uploads when using ‘Paperclip’ gem in Ruby/Rails

How to use the Dropbox API as a storage center for your file uploads when using the ‘Paperclip’ gem.

A simple 10 step process to get you up and running. This tutorial will go over how to use the Dropbox API to store your files/images while using paperclip to upload them in your app. This tutorial assumes you are using the paperclip gem and have it set up already. This is a great solution to store image uploads for your deployed applications.

1st :

Head on over to Dropbox and go through the motions to sign yourself up for an account. You will need one of these to use their API. Don’t worry, it’s free and they are an awesome company.

2nd :

Find your way to the Developer section of their site. Here is will you will be creating an app and registering it with Dropbox. Click on ‘App Console’ and then ‘Create App’. Choose the ‘Dropbox API app’ selection and then choose ‘Files and datastores’. The next part is up to you. I generally limit my app to only its own folder. Now, name it!

3rd :

On the next page you will find you ‘App Key’ and ‘App Secret’. These wil be crucial in getting things fully setup. Go ahead and keep this page open in your browser for later.

4th :

Head over to your Gemfile and include this guy and then bundle install:

gem "paperclip-dropbox", ">= 1.1.7"

5th :

This part will be up to you. It depends on what version of Rails you are using and what you are comfortable with. For this example I will be using the gem ‘Figaro’. Some of you may prefer to just use your secrets.yml file. All up to you! Head over to Figaro for instructions on how to set ‘Figaro”. I like ‘Figaro’ to store all my secrets and keys that I might be using in my app because it automatically adds these to your .gitignore file via the application.yml file. Don’t upload your secrets to Github! In your application.yml file, add this code and replace the app_key and app_secret now with your info, we will fill the rest in later.

APP_KEY: "your credentials here"
APP_SECRET: "your credentials here"
ACCESS_TOKEN: "your credentials here"
ACCESS_TOKEN_SECRET: "your credentials here"
USER_ID: "your credentials here"
ACCESS_TYPE: "app_folder"

6th :

Now we are going to want to create a ‘dropbox.yml’ file in our ‘config’ folder.

7th :

This will be the code we put in the ‘dropbox.yml’ file if we are using ‘Figaro’:

app_key: ENV['APP_KEY']
app_secret: ENV['APP_SECRET']
access_token: ENV['ACCESS_TOKEN']
access_token_secret: ENV['ACCESS_TOKEN_SECRET']
user_id: ENV['USER_ID']
access_type: 'app_folder'

8th :

We now want to add some code to which ever model we are using ‘Paperclip’ on for uploads. This will be what the code looks like:

has_attached_file :image,
    :storage => :dropbox,
    :dropbox_credentials => { app_key: ENV['APP_KEY'],
                              app_secret: ENV['APP_SECRET'],
                              access_token: ENV['ACCESS_TOKEN'],
                              access_token_secret: ENV['ACCESS_TOKEN_SECRET'],
                              user_id: ENV['USER_ID'],
                              access_type: 'app_folder'}

9th :

Now in the terminal we will want to run this code :

rake dropbox:authorize APP_KEY="your_app_key" APP_SECRET="your_app_secret" ACCESS_TYPE=app_folder

It will respond with a URL. Visit this URL and allow your app persmission to your Dropbox. After doing so it will give you the remaining puzzle peices that we need. These will be in the form of an ‘access token’ , ‘access token secret’ and ‘user_id’ . Use these to fill in the remaining fields in your application.yml or secrets.yml file.

10th :

Last but not least… restart your app and start uploading! Your uploads will no begin being saved to your Dropbox account. You can verify this by logging into Dropbox and checking out your apps folder to see all the uploads.

Hope this helps you with storing your uploads for your deployed application.

I always enjoy feedback!

Big thanks to both the paperclip gem and the paperclip_dropbox gem.


PASSION. MUSIC. This magnificent beauty that enables that most amazing of feelings, the down right worst of feelings and every little emotion in between. Music has this innate ability to take us to any place in time. It enables us to time travel throughout our experiences in life. It allows individuals of every single background to come together to enjoy a similarity, music.

I was once told that to see into a person’s soul you must look into their eyes. I believe music gives us the ability to look into an individual’s soul without ever looking into their eyes. Music is one of the purest forms of self expression in the world. Wether the content of the song has positive connotation attached or negative, it provides us with this brief glimpse into the true feelings of the songwriter. Their art is what allows this escape.

This art that allows us to go out on friday and dance like there is no tomorrow. This art that allows us to sit at home on a depressed feeling evening reminiscing about things that are better left in the past. This art that reminds us of the favorite songs of individuals who have passed. This art that allows us 3 minutes and 42 seconds of absolute peace because it can take us back to that one moment that was unlike any else. This art is what these individuals create without ever knowing they are producing these moments. They provide us with it not because of the necessity to give us these feelings, but to show their own.

I had the extreme privilege of touring with an incredible artist many years ago. He is what I believe to be the true essence of an artist. Not just an artist but an incredibly talented one. I can remember back to a specific weekday when we shared a phone call about passion. About how it was every individual’s responsibility to not only find something they are passionate about, but to follow those passions no matter the cost. We discussed the love and dedication it takes to pursue that life. We discussed the rewards that are captured for choosing such a life, as well as the hardships that are felt. He understood better then anyone these feelings.

These feelings that are not restricted to only “artist” to feel, but to any single human being that is brave enough to find what they truly love. To find what makes their life more fulfilled then anything else. To find what drives them to dump every last feeling they may carry into it and to sacrifice whatever it takes to continue pursuing no matter what the hardships or negative events. To live a life without passion and drive, is to not live.

So to every single person who has decided to do what they love, to follow their passion, to disregard what others may consider “not normal”… you fucking rule. You are the person more should aspire to be. You are what gives hope to those who only need to understand the power of passion. Because our passion is what will produce not only the greatest of results, but the most true.

I normally finish these off with a quote.. but tonight I leave you with a video of a friend. A friend who understands the true aspects of sacrifice to follow their passion and the beauty that can come from it.

mind over matter

Kevin, why do you constantly tell us things we already know? Why do you remind us of elementary subjects that seem so obvious when read from the text on your page?… GOOD QUESTIONS!

It is because we all forget. Wether we forget because the hustle and bustle of everyday life distract us. Or wether we forget because we see it as elementary, enabling us not to pay close enough attention. What I am about to type is real. We all forget, but we must not, because life is short and fragile and as cliche as it may seem, it will pass us by faster then we could have ever imagined.

The mind will forever be stronger then the physical being that we are. OH, NO SHIT KEVIN? … I get it, what I am saying seems obvious enough. But I know that I have often times forgotten this.

As a matter of fact, I have often not remembered this in the least bit. A few years back I had the privilege to travel around the world. To see things that forever changed my perspectives and how I viewed life. Most importantly, it gave me the opportunity to prove to myself… that no matter what we have been through, what we are going through, or what faces us ahead… we can do anything.

During my journey, I got the chance to climb up to everest base camp. While most people might take the chance to relax, to spend money on luxurious material things or both, I took the chance to embark on a life long lesson. A lesson that is forever instilled in me, that we as humans, no matter what our background, or our struggles, or our futures, have the ability to do whatever we set our minds to.

We can walk 70-80 miles uphill to 18,000 feet or we can spend 12 weeks fully immersed in a challenging, mind boggling adventure. No matter our choice, that decision must lead us somewhere we want to end up. It is our choice and we can do whatever we want. We only have to know that we can and know that all we have to do is set our minds to it.

I mean, shit, if you are growing up saying you want to be an astronaut, then freaking do it! If you want to be a P.E. teacher, do it. Do not settle for anything less then what YOU know YOU are capable of…. Which is ANYTHING… because our minds are this incredibly powerful thing that are only limited by the thoughts which we provide it.

Never quit dreaming. Never quit doing. Never quit achieving. Never quit… Cause your mind, it’s more powerful then anything.

The test of a first-rate intelligence is the ability to hold two opposed ideas in the mind at the same time, and still retain the ability to function. One should, for example, be able to see that things are hopeless and yet be determined to make them otherwise. ~F. Scott Fitzgerald

Marathon, not a sprint.

This blog’s topic comes courtesy of my friend Mary (who is a complete badass and a great person). Enjoying happy hour on a relaxed Monday evening lead to some enjoyable and thought provoking conversation. We were discussing jobs and how she could not seem to find the right one. At some point she said “yeah, but you’re only 25, what’s your dream job?”. I had no hesitation… I responded “I have my dream job. I am challenged everyday. I learn something new everyday. I get to directly influence people’s lives in a positive manner while continually perfecting my craft. I have a skill-set that allows me to work anywhere in the world at anytime. I love what I do.”

I did not have to think for a second about my answer.

The biggest struggle I have these days, is sometimes… I wake up still tired.

For those who don’t know… I am a software engineer at a pharmaceutical company that specializes in medication management. It is completely awesome! I have only been on board for a few months but have already garnered an immense amount of skill/experience from my time with them. The future is going to be awesome!

While I love my job, I often face the same recurring internal struggle… I want to be the best at my craft. I want to learn everything I can (most of the time in a single day). I want to know more than you. I want to be able to know it all so I can help others “know it all”. Software development/engineering/programming (whatever you want to call it) is a life long marathon. There is always something new and exciting to learn. There is always going to be something fresh to absorb into that sponge of a brain of yours/mine. No one can finish a marathon if they are sprinting the entire time.

My problem is, I want to know it now. I want to treat this marathon as if it were a sprint and I was Usain Bolt. I have to constantly remind myself that that is completely impossible. No human could ever acquire all the knowledge they seek overnight. I have to remind myself that the people beyond my knowledge, are years ahead of me in terms of experience. The finish line I seek is forever moving a little further away. But that is why I chose this path. I never want to reach a plateau. I want to be challenged everyday. I want to learn everyday. I want to become the best possible me (and a kickass/ninja/wizard/gandalf/programmer). The only thing that stands between me and that greatness…is me. Failure is but a hurdle I will rocket over while striving to reach that greatness.

“I was never afraid of failure; for I would sooner fail than not be among the greatest.”  ― John Keats

Regex, you devil you! A guide to some simple validation using ng-pattern and regex (cron syntax validation)

I recently encountered a problem in an app I was building that involved some validation on a form in Angular. After a little research and a lot of trial and error. I was able to find a good solution to my problem. It was in ng-pattern that I found this solution. A beautifully simple way to provide validation for inputs on your Angular forms.

Ng-pattern allows a user to validate against a pattern of input that they specify. Yes, just like it sounds, it checks for a pattern. I am not going to go in depth on the ng-pattern because enough people have and it is quite simple to implement. Here are some great resources to read up on this Angular awesomesauce.

Here is an example of adding ng-pattern to your HTML:

Screen Shot 2014-12-10 at 9.31.35 PM

Now, when it comes time to create that pattern, Regex pops its evil (what I used to think) head in. At first glance, regex can seem like a crazy thing to write. It seems upon first glance that there is absolutely zero readability. This was my first thought as well, but it is actually quite simple.

So in your Angular controller you can set your syntax there to keep your views a bit more clean.

Screen Shot 2014-12-10 at 9.33.50 PM

That is literally all it takes. Not bad at all. Now your input is validated based on the inputs pattern.

So my problem was validating the input for a CRON time. This can be a bit complex…or so I thought. If you have ever had an input for CRON time and had to explain to people who do not know CRON syntax how to input the right CRON time, you can understand this. So this is where validation for the pattern can come in handy. My CRON time input accepted: Seconds, Minutes, Hours, Day of Month, Months and Day of Week.

This will help you understand CRON if you are not familiar:

There are a ton of great tools out there for helping you along the way when you face a problem as such. Regex is not the scary beast it may appear to be and others have already sharpened the sword to help tackle that beast. Here are some awesome resources to help you along the way.

This cheat sheet is awesome:

This visualizer is a life saver:

The last link provides an awesome visualization map to show you what your regex is actually doing and to help test it. I HIGHLY recommend it.

This is what my map for a CRON syntax regex ended up looking like:

Screen Shot 2014-12-10 at 9.46.13 PM

Now I know that a lot this is not the world’s best regex for CRON syntax patterns, but hey, you do better (and then please share it with me :p  ).

Here is an actual snippet of code for validating CRON time syntax:

Screen Shot 2014-12-10 at 9.53.41 PM

And BOOM! There you have it! A nice, clean way to provide a regex pattern validation to your Angular forms.

If you have any suggestions, criticisms or recommendations for this post, please post a comment.