npm linked modules with webpack

I was was having some problems with an npm module that was not updated on the "master" branch. It also had a lot of dependent child libs. There was a "develop" branch that I wanted to try. For some reason I had an issue with trying to use the "develop" branch from npm.

npm install user/project#branch

I probably should have open a Stack Overflow question about it, but maybe later.

I ended up going a different route and using npm link and cloning a copy of the library.

I am trying to use WebPack, which seems like black magic... like a lot of the node ecosystem if you ask me.

Anyway, the code was still not compiling and could not find some of these dependent modules. Turns out this was not WebPack's fault, but another pain point I have found when using npm link.

The WebPack documentation has a description of the problem in their troubleshooting guide to get WebPack to find the dependencies of npm linked modules.

http://webpack.github.io/docs/troubleshooting.html#npm-linked-modules-doesn-t-find-their-dependencies

StrongLoop Reddit Vote Manipulation

Wow, I found this Reddit thread the other day where StrongLoop seem to admit to vote manipulation on Reddit.

Vote manipulation. Suddenly, spam accounts everywhere submitting strongloop, commenting favorably just on strongloop posts, etc. Really obvious pattern. Proof is easily found by looking at the domain search for strongloop, and by submitting anything pointing to the domain. Immediate spam queue - the domain is reddit-shadowbanned.

reply by jakerella

Hi there, I'm a DE for StrongLoop. Yes, there was some tomfoolery going on previously, and I've specifically pushed for that to stop. Lately (last few months at least) you won't see that. That said, when other people post SL stuff we do pile on, but it's our staff voting up those posts, and we encourage them to be active members of the community at large. Again, not trying to excuse previous behavior, but trying to show that we're working to be better.

Exception Handling - Promises vs Observables

A friend of mine was studying Promises in JavaScript. I mentioned how Promises swallow exceptions and continue execution by default.

I have recently been following RxJS and decided to knock up an example to find out how exceptions are handled differently in Promises versus Observables.

In the JS Bin below you will find the Promise swallows the exception thrown and we continue onto the Observable.

When subscribed to, the Observable throws an exception and the execution is halted. We never reach the last console log.

If you use the commented out catch statement for the Observable, then we can run to the last console log and exit cleanly.

So if you are going to use Promises, make sure you are vigilant and don't let those errors slip through and bite you later on. Perhaps look into libraries like Bluebird that provide methods like onPossiblyUnhandledRejection to help you out. Or get on the Observables train ;)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var promise = new Promise((resolve) => {
console.log('running promise');
console.log('about to throw exception in promise');
throw "Error Promise";
});

promise.then( x => console.log(x));
console.log('NOTE: promise swallows exception and continues');

var source = Rx.Observable.create((observer) => {
console.log('running observable');
console.log('about to throw exception in observable');
throw "Error Observable";
observer.onNext('observable onNext');

// uncomment below to catch observable exception
// }).catch(function(e){
// console.log('Caught observable exception and returning it');
// return Rx.Observable.return(e);
});

//subscribe to observable to kick it off
source.subscribe(function(i){
console.log(i)
});

//shows we got to the end of the program. We never get here unless we catch the observable exception
console.log('last statement running');

Outputs:

"running promise"
"about to throw exception in promise"
"NOTE: promise swallows exception and continues"
"running observable"
"about to throw exception in observable"
X "Uncaught Error Observable (line 34)"

Removing the comments from the following lines:

1
2
3
// }).catch(function(e){
// console.log('Caught observable exception and returning it');
// return Rx.Observable.return(e);

Outputs:

"running promise"
"about to throw exception in promise"
"NOTE: promise swallows exception and continues"
"running observable"
"about to throw exception in observable"
"Caught observable exception and returning it"
"Error Observable"
"last statement running"

I don't have a Pro account, but you can play with the JS Bin version.

Babel transpile ignoring native Javascript

I was thinking today that we want Babel to ignore transpiling native JavaScript available in Node.js.

You could whitelist or blacklist what you want Babel to transpile and a few people list options in the comments here.

Babel 6 now does nothing by default, but there doesn't seem to be any Node.js version specific presets mentioned on the Babel page.

Finding out which options you need for your version of Node.js might be a bit tricky.

The famous Kangax page for ES6 (yes, I prefer that name rather than ES2015 too) is a good source and shows some different Chrome and Node.js versions.

This link on the Node.js site shows what features are available in Node.js, but I am not sure how up to date it is kept.

It notes you can find in progress V8 options with:

 node --v8-options | grep "in progress"

and the V8 version used by your Node.js with:

 node -p process.versions.v8

Are Google Dropping the Ball with Android

I've been using Android phones for a while now. Lately however, it has been a pot of boil and trouble. Lollipop issues, Kit Kat issues, Hangouts and Chrome issues spring to mind. It's time to try something else as outlined below.

Nexus 4 Problems

I have a Nexus 4 which was running great on Kit Kat. I made a fairly early move to Lollipop and was hit by early mover issues like many others. Okay, this is somewhat expected with a new release.

As updates came for Lollipop, issues came and went. Sometimes it was even worse than before, with my phone randomly turning off etc.

Now that the Nexus 4 has been dropped off the Marshmallow update list, I am at the end of the road for Google updates. Problem is, my phone still randomly switches off during media playback, like video calls.

Hangouts seems to perform really poorly lately and is unusable when talking to someone with poor internet. The Line app handles this a lot better.

Hangouts also seems to have some issues on my desktop computers as well. Windows going missing, login issues. Sometimes it just needs killing and restarting.

Chrome browser on Android has also been having issues getting stuck in the search area and not wanting to do anything. This only seems to be solved by closing Chrome from the task manager.

I've talked to other people and they have seen similar issues with Chrome and Hangouts. A few also seem to be annoyed with their Android devices.

Motorola XT905

I also had an older device that is still in use, but was recently offered an update to Kit Kat. Not learning my lesson from Lollipop updates, I actually installed Kit Kat. Turns out I should have investigated more. Plenty of people seem to have the same issue of Wifi range halving, which means it is unusable in half of the house.

The Answer?

Well, I bought a MacBook, but I am not quite ready to saddle up for the iOS ride.

Microsoft Windows change their phone OS every 5 minutes. The last few people I knew with a Nokia Windows phone both ended up with bricks.

So I have installed CyanogenMod 12.1 on the Nexus 4. Good thing I am a developer and already had the necessary Android dev tools installed. After a couple of issues with the instructions I eventually got there.

Initially I downloaded the Cyanogen Recovery image that was associated with the CyanogenMod Build I downloaded. This didn't match the instructions I was using and seems less featured than the Team Win Recovery software I later installed.

CyanogenMod installation instructions for Nexus 4

Another issue I faced was the "stock" version of Open GApps was apparently too big to install. I used the "nano" version, which is probably nicer anyway as I can install what I need.

Too early to tell yet if the issue is solved, but we shall how it goes after some testing.

Update

Seems like a no go so far. One crash already. Maybe I will need need to try Kit Kat (CyanogenMod 11)!

Moving to a MacBook from Windows

Yes, MacBook to PC, or OS X to Windows makes more sense, but whatever you want to call it, I finally caved in and bought a MacBook (well a few weeks ago now).

Why?

Well every other developers seems to have one in all the videos I watch, so I decided I better have one too... just kidding. Well, kidding about the reason, but seriously, it is a sea of MacBooks in most online videos I watch.

I still have my older Windows notebook and I am going to try take both with me next time I travel. I still like Windows and there are some programs I still prefer that are only available on Windows.

The main reason that made me look was that you have pretty much have to have a MacBook if you want to make anything for OS X or iOS. I may go down that path, hence the MacBook.

I am also doing some Node.js development and whilst I have got along so far with Windows, it still feels like a second class citizen. Most people seem to develop for Node on a MacBook.

I'm also pretty keen to get a decent terminal. Babun and ConEmu made life a bit more bearable, but a Unix based system will be nice again.

Why Now?

I have been hanging out for an Intel Skylake processor for a while, but I'm currently in Australia and the price was recently increased here due to the poor Australian dollar. I managed to get a MacBook Pro 13 Retina on sale with the discount applied to the old lower price. I can also claim tax back when I fly out soon.

I'm also thinking they will do a major chassis update to the new Skylake MacBook, so it is a bit of a bummer. Anyway, I will have to wait and see if I made the correct decision or not. I figured I can always sell it and upgrade as MacBooks seem to hold their value very well. At least I managed to get a Broadwell CPU after all the waiting.

It may turn out better if they move everything to the new MacBook 12 inch keyboard, as that felt horrible, haha. Not that I thought I would like this keyboard, but more on that later.

How's it Going?

Well I have some more articles planned for that, so I'll update those soon.

I've never really liked Macs when I have used them before, so it was going to be interesting. I have been trying to keep an open mind and so far it is turning out better than I thought.

Install fails because module 'is-property' isn't installed

I was having some weird compile errors while trying to use node.js or io.js.

"Install fails because module 'is-property' isn't installed" was another one of them.

This git issue reports there are some bugs in the Windows version of io.js to do with paths of more than 259 characters.

After upgrading to io.js 2.3.1 I seemed to get around at least this issue.

Writing node.js on Windows so far feels like a bit of a battle!

npm Set Visual Studio Compiler Version

Node.js or io.js will sometimes require a C++ compiler to build packages for you. On Microsoft Windows you can use Visual Studio. The newer free Visual Studio Community or the older (and also free) Visual Studio Express editions should get you going if you don't have a commercial copy of Visual Studio.

To check the compiler npm is configured to use try:

npm config list

and check the msvs_version value.

You can specify a Visual Studio version for npm to use.

npm config set msvs_version 2013

or

npm config set msvs_version 2013 --global

Another option is to run

set GYP_MSVS_VERSION = 2013

You can use other Visual Studio version numbers like 2012, 2010 etc.

There is also a Visual Studio plugin called Node.js Tools for Visual Studio that is quite useful. It is free and open source.

Visual Studio 2015 RC Hanging on Android SDK install

My Visual Studio 2015 install was still going after about 3+ hours on the Android SDK. It seemed like it had hung.

To figure out what is going on, I looked in the %temp% directory and there is a file called AndroidSDK_SI.log. Opening this log I could see that the install was still happening. The problem was how long it was taking. It sped up significantly after I stopped Star Citizen updating!

The Visual Studio installer could really do with a better feedback mechanism to let you know that something is still actually happening. Some animated dots aren't very convincing after several hours. Even an advanced GUI option to display the output of the currently executing log file in a text box would be useful. The Android SDK log was quite useful as it showed percentage of the download, download speed and estimated times.

Anyway, check it out if your Android SDK install looks like it is hanging.

Another option is the kill the SecondaryInstaller.exe in Task Manager if you really think it is hung. This is what is running your Android SDK install. You can try repair Visual Studio later to make sure everything is okay.

Redirecting Users Based on their Country IP Address

I can't sleep, so it's time for a rant about redirecting users based on their country IP address.

Just because I am in a country, does not mean I want to be shown a site in that countries language! Okay, some of you might be thinking this sounds perfectly reasonable, because most people in country will be able to read that language. Well, I am here to let you know you are wrong ;)

So what is the correct solution to choosing which language to show your website visitors?

Answer: Web browser cultural settings!

Yes, your browser tells a web server your preferred language.

Examples of why you should check cultural browser settings and not redirect on IP address:

  • You may be a traveler who doesn't speak that language.
  • You may be a local person who prefers to use a different language. Some countries even have multiple languages, eg Switzerland as four national languages, 3 official languages at a national level. I'll leave you to go check Wikipedia if you don't know what they are.
  • There might be more, but the first one is the most important, because that is often me. Okay, the poor person in an Internet cafe or a local computer may end up out of luck, but that is why you also need a good solution for letting a person change the language. This also goes for a localized site you have sent them to.

Point in case. The other day I logged into the Origin site (a computer game store/publishing platform). For the life of me, I could not find how to change my language settings. Maybe it was there, but after searching for a few minutes I got fed up and quit. Origin seem to have a bad enough reputation as it is without adding more misery to their users.

So... on the landing page, you need to provide the user some options to get where you want to be.

Country flags are often nice. A flag stands out and is recognizable as a way to change a language. Even some text will do with an option to select a new language, especially if you support only two. At the top of the page is nice, although some sites make you hunt down the bottom of the page. Even an animation on entry might be a nice way to where to find the language options.

Another nicety would allow the user to go back to the site you redirected them from. Sometimes I really did want to go to blah.com and not blah.hm (you can look that domain extension up too, apparently it is barren, uninhabited and volcanic ;)

Last time I wrote a site that required multiple languages, I was using ASP.NET MVC. I even made some notes I just found.

Each HTTP request includes a header field "Accept-Language" and contains languages the user's browser supports, eg:

Accept-Language: en-us,en;q=0.5

ASP.NET will provide you with a Culture and a UICulture.

Culture will let you know preferred date, number and currency formatting, etc. This could even be used to decide a display currency, although I am not sure if this is the best option right now. I'm mainly ranting about languages right now.

CultureUI should be used to decide which resources to load. So this is where you should be deciding which language to display.

So go forth my minions and change all those websites that have been annoying me over the years. Rage against the IP language redirection!

You can use your IP checking for things like Amazon Affiliates program. For some horrible reason, Amazon make you sign up to each or their different countries and send the appropriate affiliate code and URL.