A New Way to Take a Shower

My kids kept complaining about having to take a shower every night. They were always saying things like “but we didn’t go anywhere to get dirty” or “we don’t stink!” or “it takes too long”. So I told them I would build this contraption for them to use so they wouldn’t have to expend any energy in the future. Their complaints have been strangely muted lately.

 

Objective Reasoning – The Basic Javascript Object

What is an Object?

In Javascript an object is simply a container or store of properties that are related to what the object is modeling. These properties can be primitive data types, other objects or functions. Here’s an example of an empty object with no properties:

const furBearingTrout = {};

I’ve used object literal notation which is doing just what it sounds like – literally writing out the notation of an object. We do this using curly braces {}.

How to create properties

When we want to set a property on our object we can do it one of two ways:
1. Use bracket notation where we state the object name along with a property name in brackets and then assign a value using the equal sign:

furBearingTrout[“name”] = ‘Alpino-Pelted’;
furBearingTrout[“url”] = 'http://www.furbearingtrout.com/fish2.html';

2. Use dot notation where we state the object name followed by a dot followed by the property name we want to use and then assign a value using the equal sign:

furBearingTrout.name = ‘Alpino-Pelted’;
furBearingTrout.url= 'http://www.furbearingtrout.com/fish2.html';

I could have created our object with properties already assigned. Note that properties are written as name:value pairs separated by commas.

const furBearingTrout = { 
  name: ‘Alpino-Pelted’, 
  url: 'http://www.furbearingtrout.com/fish2.html'
}

How to access properties

Once we have properties we can access them using the same two methods we used to set them just without the equal signs that assign values.

console.log(furBearingTrout.name); //outputs ‘Alpino-Pelted’
console.log(furBearingTrout[‘url’]); //outputs 'http://www.furbearingtrout.com/fish2.html'

We can also create objects using the constructor method (new Object) or the Object.create() method but for this article we’ll stick to the literal notation for its simplicity and visual aid.

Functions in objects are methods

When the property is a function we call it a method. Methods do something with the data stored in the object. Imagine we had the following properties:

const furBearingTrout = {
  name: ‘Alpino-Pelted’,
  url: 'http://www.furbearingtrout.com/fish2.html',
  view: function () {
    console.log(`View the ${this.name} trout at ${this.url`;)
    }
}

You call a method by accessing the property name it’s associated with followed by parentheses.

furBearingTrout.view(); //ouputs ‘View the Alpino-Pelted trout at http://www.furbearingtrout.com/fish2.html

Why do I use ‘this’ ?

The ‘this’ keyword simply references the very object it’s inside of. So this.name is the same as saying neighbor.name. Outside of the object we would refer to furBearingTrout.name but inside the object we refer to this.name.

There’s a lot more to objects than what I’ve written here. But if you understand these basics you’ll already be able to model some fairly complex real world data and be able to manipulate it.

A Little Background on Map Elements

The problem

If you’ve ever had to place map elements like north arrows, text or scalebars on an ArcGIS made map, you know how they can get lost in the background of imagery or some other basemap. You can always try to change the items color or size to make it stand out. But the easier and more effective method is to change its background color to a solid color like white.

Map elements can get lost in the noise.

The problem with doing that is the background extent only stretches to the edges of its element. There is no padding between the element edge and the background edge.  Thankfully, ArcMap provides us with the ability to set a gap between the two edges.

Default backgrounds on map elements have no padding.

How to fix it

In ArcMap, right-click or double-click on the element to open its properties. Open the Borders and Background tab and select your backround color from the dropdown. Next, change the X and Y values next to “Gap”. The higher the number, the more padding you’ll get between element and background edge. You can also apply a “Rounding” percentage value to give your background panel rounded corners. That’s all it takes to make your ArcGIS map easier to read and more professional looking.

map elements
Adjusting backgound gap gives elements room to breathe.

 

Categories GIS

The Integrated Developer’s Environment

I was home sick from work the other day and had plenty of time to think. It occured to me that whenever I go in to the office I am very productive almost immediately. When I’m home, I tend to have little enthusiasm for programming. When I attempt to program at home I’m usually nowhere near as productive as at the office.

It hasn’t always been that way. When I lived in Las Vegas I wrote code at home on a regular basis. My immediate thought was that I don’t currently have the right hardware to be productive at home. In Las Vegas I had a decent desktop PC with two monitors and a hardwired internet connection. I currently have an old, slow laptop that shares a wireless connection among several people and lots of devices.

But is it really the hardware that holds me back? Most of my work is done in JavaScript which can be written with lightweight text editors/IDEs (I use Atom these days). I don’t need a lot of computing power for that. Honestly, my high-end rig at work is mostly for large imagery datasets and working with GIS.

I started realizing that it’s less the hardware and software that impacts my productivity and more the intended use of those things. When I go to the office, I use that computer for work. My home computer is used for surfing the web, writing emails and watching Netflix. When I sit down at it, my brain switches to mindless mode. I find myself wandering, checking email or googling things that pop into my mind.

So it’s less the development environment and more the developer’s environment that inluences his productivity. In my Las Vegas home I had set up my computer in a separate room and only really used it for programming. We had a separate laptop (the same one I have now) for web surfing and intertainment. For me, I have to have a psychological, if not physical, separation between work (anything that takes concentration and thought) and play. I would like to spend some time working on some open source projects on the weekends so it looks like I’m going to have to carve out some space in the house or a dedicated office.

Browser Tab Overload

I’m addicted to browser tabs. Right now on my work computer I have 50 tabs open and that’s after I closed the unimportant ones. I have a fairly large screen but with this many tabs open I can’t even see the tab titles anymore. I usually just forget about what’s there until some point in the future when I end up deleting a bunch of them just so I can see which tab my email’s on.

Computer With Multiple Tabs

Of course, every tab is important to me. Each one is a blog post I want to read or a tutorial I just don’t have time to go through yet. I’ve tried bookmarking pages instead but without something in front of me I usually just forget that I have things bookmarked. Of course I usually just forget that I have things tabbed too.

One thing that sort of works, sometimes, is to organize my bookmarks into logical folders and then show those folders on my bookmarks bar. But then my bookmarks bar gets too long and a lot of the folders get hidden and I end up forgetting about them anyway.

My work computer has a solid state hard drive, a 3.4 GHz i7 processor and 32 GB of ram. It has no problem holding 40+ tabs open in Chrome along with running five to ten other programs I regularly use. My problem is just being able to see what the tabs hold so I can read them later.

At home, however, I have a different problem. My home computer is a 7 year old laptop with a core 2 duo and only 3GB of ram running Windows 10. But I still have my tab addiction. Unfortunately, I’ve hooked my wife on tabs too. Now two of us want to bounce from site to site and keep everything we’ve seen open. Arrggghhh, there’s too much interesting stuff on the internet!

My home laptop slows to a crawl if I use Chrome with more than about four tabs open. And good luck having any other programs open at the same time. The best solution would probably be to just close tabs or at least bookmark them and hope to someday remember to look at the bookmarks. But no, I found a way to force my ancient computer to keep my tabs up without crashing.

I loaded the Chrome extension called The Great Suspender. It suspends (surprise, surprise) tabs that haven’t been focused for more than a set amount of time. When you click on a suspended tab it reloads and away you go. This way I can keep lots of tabs open without affecting my system’s performance.

Yes, it’s a band aid for a problem that should be fixed by bookmarking or something. Of course, now that I think about it, when I have a screen full of tabs open I usually forget to go back and look at them anyway. My parents used to tell me that if I couldn’t remember something, it probably wasn’t that important anyway. And if most of the things my tabs hold aren’t that important, maybe I shouldn’t keep them around in the first place.

I need to get out more.

Time to Start Thinking of Gardens

It’s that time of year again. The time when I wait too long to plant my cool weather garden. I then wait too long to plant my warmer garden. All of that comes after I’ve already forgotten to amend the soil properly for the particular plants I want to grow. But hey, every year’s a new year. Even though I should have already sown my first round of carrots, radishes, lettuce and peas, I can still get them in a little late. And there’s always Fall and early Winter.

 

My biggest goal this year is to get a harvest of winter squash off the vine and onto my plate. Last year’s crop was absolutely decimated by squash bugs. I had amazing plants with beautiful leaves but I let the squash bugs get established. They destroyed everything. It’s hard to see vibrant plants start to put out fruit only to see everything killed by little vine-boring punks.

I’m determined that this year will be different. I plan on putting in fewer plants and defending them to the death against the insidious squash but. There are lots of great ideas in books and on the internet of ways to kill or deter them organically (the only way I grow food plants). One can try Castile soap sprays, diatomaceous earth, row covers, traps, companion plants, oils and others. I’m willing to try them all. The ultimate, of course, would be to design a garden defense system that uses computer vision and laser beams to blast bugs. I might need to put a little more thought into that one.

I love Kabocha, Acorn, Delicata and Spaghetti squash. I’d love them even more if they came from my garden rather than the store’s shelves. With a little care and attention, along with a healthy dose of bug violence, I might be able to make it happen this year. Now I just have to go put it all on the calendar so I don’t forget to actually do it.

Chrome Developer Tools

As a JavaScript developer I need tools that help me figure out what’s going on between my code and the browser. Thankfully, most major browsers today provide developer tools that do just that.

 

Google Chrome Toolbox

 

With these tools you can see exactly how your code affects the browser. At runtime you can find errors in code you’ve written or how long your site takes to load. You can view or even rewrite your CSS rules to see what changes will look like before you ever even commit them to your source files.

 

You can also dig into the browser itself and inspect its cookies, local storage and cache. And with web users quickly transitioning to mobile devices, developer tool device emulation can show what your site looks like on, and how it will interact with, phones and tablets.

 

Every year that passes gives us better developer tools from the major browser makers. We are fast coming to a point where any tool you choose will be just as good as another. But for one reason or another developers tend to find themselves gravitating towards a particular set of tools.

 

When I surf the web I like to use more privacy oriented browsers like, well, anything but Google’s Chrome. But when it comes to debugging and developing code, Chrome takes first place in my world. I like the default look of the Chrome tools UI (although Mozilla’s Dark theme is slightly more pleasant to look at if you’re into dark themes). I also find Firefox developer tools to be a little slow when emulating mobile devices while Chrome is snappier. Other tools in Chrome also appear more polished and have more functionality.

Some browser developer tools might have features that others don’t but that’s usually only true until the others release their next version. Good ideas tend to spread themselves around quickly.

 

There are lots of tools out there for JavaScript developers and web designers. But Chrome’s developer tools provide great runtime debugging, design assistance and performance insights. If you’re a web developer and are not using these tools and features to the fullest, it’s worth taking the time to dive deep.

How to Change a Github Repository Language

I created a new Github repository today for a Node/Express project at work. After pushing the project code I went to Github and saw that the language for the project was listed as CSS. To be fair to Github, I did style my app with CSS. But as it’s a Node app, I expected to see the JavaScript tag instead.

It turned out the third-party image gallery library I was using had much larger files than anything I was writing. Github’s Linguist library picked up on the larger files and used those to extrapolate CSS as the dominant technology in the app. I still don’t entirely understand why, since the library’s JavaScript files were three times the size of its CSS files.

Now I needed a way to change what the language tag said. Unfortunately, Github doesn’t give you a good way to do this. The Linguist library does give you options to ignore files from third parties though. Here’s how you do it:

  1. Create a .gitattributes file at the root of your local repository.
  2. Inside the .gitattributes file, type a path to the containing folder holding your third-party code. At the end of the path type “/*”. 
  3. After the path type “linguist-vendored”. Here is the example from the Linguist troubleshooting section: 
    special-vendored-path/* linguist-vendored

    Save your file, commit it and push it to your remote Github repository.

This takes the third-party code out of consideration for the Linguist algorithm. Once you refresh your Github page the language tag should be different. If the language still doesn’t match what you think it should, try adding the “linguist-vendored” tag to other folders to reduce the types of files Linguist searches.

Use Yarn in Place of npm

Condensed version of This Post

Use Yarn in place of npm: Workflows don’t change; Packages load faster; Consistent node_module structure.

yarn init = npm init
yarn install = npm install
yarn add [package] = npm install [package] --save
yarn add [package] --dev = npm install [package] --save-dev
yarn remove [package] = npm uninstall [package]

 

Longer Version of This Post

npm is currently king of the Node package managers. Yarn is an alternative package manager that tries to fix what could be problems for some npm users. Yarn provides faster load times, dependency consistency and shorter commands, all within the same workflow you are used to with npm.

 

Installation and Use

If you already use npm, install Yarn with npm install yarn -g . That’s it! You can now use the yarn commands just like you would with npm. If you feel silly installing npm’s replacement with npm you can download an installer instead. Use your existing package.json file or create a new one with yarn init . Run yarn add [package]  to install new package dependencies . Removing installed packages is as easy as yarn remove [package] . Install all of the dependencies of an existing project using yarn install,or even just yarn .

 

Deterministic Package Installs

Deterministic Package Installs is a fancy way of saying: The same module dependencies will be installed with the same structure on any machine using yarn. The structure of dependencies in the node_modules directory can be different from machine to machine when using npm. This can potentially cause a dependency to work on one machine but break on another.

Speed

Yarn installs packages faster than npm. Yarn starts by comparing a dependency against what’s already in the global yarn cache. If there’s no package cache, the package is downloaded and placed in cache. Once all dependencies are cached, yarn copies all necessary files only once to the project’s node_modules directory.

 

Downloaded and cached packages don’t need to be re-downloaded in the future. If you nuke your node_modules folder and run yarn install  again, your dependencies will be copied from the cache into your new node_modules directory very quickly. If you start a new project somewhere else on the same machine, only dependencies that have never been used elsewhere are downloaded. The rest are pulled from the cache and merged with the downloaded ones. This makes for a very fast load.

Conclusion

Do you really need to use Yarn? Of course not. Lot’s of people use npm for their projects with little problem. But on projects where dependencies have to be installed separately among several users, module consistency could become a problem. Yarn solves this and provides other great enhancements to npm. Yarn provides a similar use experience to npm. It provides all the same packages, is faster and has simpler commands. It can even tell you why a package is being used. There are few if any downsides and you can always go back to npm.