Select Page

Best way to check for internet connection in cross-platform Xamarin projects

I’m working on a multi-platform project built on Xamarin and C#. We retrieve a lot of data from the internet, and we check for an internet connection before we do so we can notify the user if we had problems getting the data they’re looking for. However, the way we checked for the connection across the different projects wasn’t consistent and kind of depended on which developer needed the functionality and where he needed it.

This project has been in the works for quite some time now, and I was recently tasked with abstracting as much logic as possibly out of the various platform-specific projects and into one common logic layer, and this connection checking logic I mentioned was one of the first things I found to refactor. I created a new class in the common project and began implementing it, but I ran into a road block.

The method we were using previously required the WebClient class in the System.Net namespace, but that class is apparently not accessible from PCL projects (which is what my common layer is).


I googled for several hours and read way to many stackoverflow threads over and over, vainly trying to find an answer. Finally, I asked my own stackoverflow question. My tendency is to shy away from asking questions there because I feel like I won’t get a response for weeks, and when one does come in it’ll be no good, but this time I got an answer in less than 5 minutes.

And it was a good answer too. It turns out that someone else already encountered the problem I was having, and had build a NuGet package to fix it. I installed the plugin, and while I had to make a few changes to get everything working (I removed this whole module from the shared logic layer and implemented the plugin directly in each of the platform-specific projects), after a few short minutes of work with the no-nonsense properties exposed by the plugin I’ve removed all of my tedious custom implementation, and the codebase is that much more streamlined.

Hopefully this post can help someone else before they spend 4.5 hours digging for a solution like I did :). Let me know if you have any questions, thoughts, or if the plugin solved your problem in the comments!

Resolved: “Error: Cannot find module ‘serve-static'” in Node.js

More Node.js troubles, would you believe it?! But there’s always a solution.

I’m finally getting to the more interesting part of my Node.js Lynda course (Node.js First Look) where we’re actually building http servers. It’s really pretty amazing and exciting that running a js script from the command line can suddenly make your computer serve you data at whatever port you specify, and I’m really looking forward to being able to use this stuff in the real world.

Screen Shot on 2016-01-20 at 08-07-47We’re using the Connect Node module to simplify web server creation (even though it’s ridiculously simple already), but Mr. LeBlanc was writing for an older version of Connect while I was using the current one, and that of course caused problems that made node throw errors every time I tried to run my server script:
Error: Cannot find module 'serve-static'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:289:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object. (/Users/jonathanmccormick/Google Drive/Projects/Learn NodeJS/server/server.js:2:19)
at Module._compile (module.js:435:26)
at Module._extensions..js (module.js:442:10)
at Object.nodeDevHook [as .js] (/usr/local/lib/node_modules/node-dev/lib/hook.js:43:7)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
[ERROR] 07:58:51 Error

As always, a quick Google search turned up a solution. Apparently newer versions of Node (3.x) have moved the static middleware to it’s own module, so you’ll need to install it separately in addition to the regular connect module. Simply run npm install serve-static in your project’s folder and then require it in your code. Now my code looks like this:
var connect = require('connect'),
serveStatic = require('serve-static');
var app = connect()
.use(function (req, res) {
res.end("Oops, couldn't find it :/");
HAHA!! It works.

What is " in WordPress?!?!

I’m wrapping up a boatload of WordPress site migrations, and the latest one has a strange quirk that I don’t recall running into before. After moving wp-content and pulling the database, some of the post names have " in them. Example: My awesome "post"

This caused both me and my client some concern, but it’s a simple issue. It appears that " basically means the double quote character (“), so simply replacing " with ” should get everything back to normal. So the example post title above would be My awesome “post”. I’m not sure why this happened, I guess there was some fluke in the database migration that messed some things up. Anyway, hopefully that helps! Please hit me up in the comments if you have any questions or additional insights.

WordPress Fix: “unexpected end of file in header.php”

WordPress Fix: “unexpected end of file in header.php”

Parse error: syntax error, unexpected end of file in /home/ubuntu/workspace/wordpress/wp-content/themes/[theme-name]/header.php on line 248

I got this error today while working on creating a staging site. The site had WordPress installed in a subfolder, and this had already caused a whole slough of problems that I had spent most of my morning working on and slowly annihilating, but this problem was unrelated to that.

The Fix:

slack-imgs.comHere’s the solution that I found on the WordPress forms: the issue was caused by php syntax that worked on the production server where the site was built for some reason, but wasn’t working on the staging server where I was trying to set up the development sandbox. There was an opening php tag toward the end of the theme’s header.php that was incorrect (see the image). I changed it to <?php and the error went away and the site loaded.

Hope that helps! If you have any questions or thoughts to add please leave them in the comments.

Node.js Troubles (and a solution)

My AngularJS journey as brought me to the MEAN stack (MongoDB, Express, AngularJS, Node.js), and I now know enough Angular to be frustrated by the fact that I’m stuck with reading data I create in my js files, so I’m learning Node with the hopes of being able to actually build some sort of real and semi-useful application that can do something with a database.

I installed the current stable version of Node (4.2.4) and everything has been smooth sailing for the last couple of days. But I’m taking this Lynda course, and I came to the video on updating modules in Terminal, and naively followed the instructions to sudo update everything Node on my system to the latest version.

Rookie error. I typed the next command, and…

throw err;
Error: Cannot find module 'npmlog'
at Function.Module._resolveFilename (module.js:326:15)
at Function.Module._load (module.js:277:25)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at /usr/local/lib/node_modules/npm/bin/npm-cli.js:20:13
at Object. (/usr/local/lib/node_modules/npm/bin/npm-cli.js:76:3)
at Module._compile (module.js:398:26)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)

Now every single npm I type is greeted with the same grim message, over and over and over. I’ve been googling and trying solutions for the last 45 minutes, and I’m not totally sure if I should be nervous about the files I’m deleting.


Hey! A fix!! Super simple… I guess I should have tried this first. After deleting all the node files and folders I could find in usr/local/lib/ and surrounding I just downloaded and installed the latest STABLE version from, and voila!!