Blog logoThe Open Source U

quick-tip

Quick tips are notes or ideas I want to keep track of. The posts are generally short.


Bit Masks

 •  Filed under OSS, oss-concepts, computer science, reference, quick-tip

Bit masks are a computer science concept; in a nutshell, they represent options which can be combined in a variety of ways.

A very basic example colors. Blue and Green combined create yellow. This can be represented in bit masks.

The following example is sourced from the Bit field article on Wikipedia; it illustrates the concept well for those new to it.

Consider the following1 and take note of the binary version which is in the comment.

// primary colors
#define BLUE  4  /* 100 */
#define GREEN 2  /* 010 */
#define RED   1  /* 001 */

This creates the base options. The next example uses the above to further define more colors without assigning them specific numbers, although they would output as numbers.

// mixed colors
#define BLACK   0                    /* 000 */
#define YELLOW  (RED | GREEN)        /* 011 */
#define MAGENTA (RED | BLUE)         /* 101 */
#define CYAN    (GREEN | BLUE)       /* 110 */
#define WHITE   (RED | GREEN | BLUE) /* 111 */

Notice that WHITE is all the colors -- all the bits are "on" and black is no color -- all the bits are off.

I've seen this used quite a bit although, I must admit, I don't come across it quite as often as I used to. Rest assured, it is still in use and is quite useful.

  1. The code presented is Pseudocode. It is not intended to be complete.

What is a "contribute.md"

 •  Filed under OSS, GitHub, quick-tip, oss-concepts

In most established open source projects, you should find some sort of information regarding contributing to that given project. This could be called contribute.md or CONTRIBUTING.md or is simply a section in the repository's Readme file.

If you intend to contribute to a specific open source project, ensure that you follow that projects' "contribute". Most project maintainers won't accept your pull request unless you do.

For example, here's the contributing guidelines for Nightwatch -- a project I hope to cover in the near future.

https://github.com/nightwatchjs/nightwatch/blob/master/CONTRIBUTING.md

Here's a subset of their document with regards to submitting a pull request:

  1. Follow the usual git workflow for submitting a pull request

    • fork the project
    • create a new branch from master (e.g. features/my-new-feature or issue/123-my-bugfix)
  2. If you're fixing a bug also create an issue if one doesn't exist yet
  3. If it's a new feature explain why do you think it's necessary
  4. ...
  5. ...
  6. Do not include changes that are not related to the issue at hand
  7. Follow the same coding style with regards to spaces, semicolons, variable naming etc.
  8. Add tests - after all this is a testing framework

List globally installed package for NPM

 •  Filed under npm, quick-tip, reference, nodejs

I found myself in a situation where I needed to list all of the global npm packages I had installed on a (windows) server. The command, it turned out, was quite simple:

npm ls --global

npm ls itself will list the packages installed locally which can be helpful unto itself.

Then, slightly related is that I needed to remove a select global package which is easy enough.

npm uninstall --global package-name