Skip to content

Instantly share code, notes, and snippets.

Avatar

Mikael Högberg mikaelnet

View GitHub Profile
@mikaelnet
mikaelnet / IPAddressExtensions
Created Apr 17, 2015
Extension methods for handling IPv4 addresses
View IPAddressExtensions
public static class IPAddressExtensions
{
/// <summary>
/// Tests if a given IPv4 address is within any of the private
/// IP address ranges, 10.0.0.0/8, 172.16.0.0/12 or 192.168.0.0/16
/// </summary>
/// <param name="address"></param>
/// <returns>True if the address is private, otherwise false.
/// Note: IPv6 address always returns false</returns>
/// <exception cref="NotSupportedException">For unknown address families (other than IPv4 and IPv6)</exception>
@mikaelnet
mikaelnet / EnumerableExtensions
Created Apr 17, 2015
Extension methods for enumerables
View EnumerableExtensions
public static class EnumerableExtensions
{
public static IEnumerable<T> ToEnumerable<T>(this T item, bool nullAsEmpty = true)
{
if (EqualityComparer<T>.Default.Equals(item, default(T)) && nullAsEmpty)
yield break;
yield return item;
}
public static bool None<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
@mikaelnet
mikaelnet / controller.js
Last active Aug 29, 2015
Node client for Raspberry PI Deployer
View controller.js
var argv = require('argv');
var https = require('https');
var xml2js = require('xml2js');
var inspect = require('eyes').inspector({maxLength: false});
var gpio = require('gpio');
var xmlParser = new xml2js.Parser();
var teamCityHost = 'your team city host';