Querying the JC Decaux API using PowerShell

JC Decaux have released an official API that can be used to query the Dublin Bikes scheme as well as other schemes they manage, e.g. Dublin Bikes in Dublin (Ireland) & Cyclocity in Vilnius (Lithuania).
I threw together a quick and dirty PowerShell script for querying the API. If you'd like to play around, you'll need to register for an API key at https://developer.jcdecaux.com/


#
#	Title :: JC Decaux OpenData Client
#	Purpose :: Can be used to query city bike schemes managed by JC Decaux, e.g. Dublin Bikes
#	
#

## Variables
$api = "API KEY GOES HERE"

$contractsURL = "https://api.jcdecaux.com/vls/v1/contracts"
$stationsURL = "https://api.jcdecaux.com/vls/v1/stations"

## Functions
function invoke-jcdclient {
param (
		[string]
		$url,
		[string]
		$contract
)
	#
	
	$response = Invoke-RestMethod -Uri $url -Method Get -ContentType 'application/json'
	return $response
}

function get-jcdcontracts {
param(
		[string]
		$apikey
)
	#
	$response = invoke-jcdclient -url "$($contractsURL)?apiKey=$($apiKey)"
	return $response
}

function get-jcdstations {
param(
		[string]
		$apikey,
		[string]
		$contract
)
	#
	
	$response = invoke-jcdclient -url "$($stationsURL)?contract=$($contract)&apiKey=$($apiKey)"
	return $response
}

function get-jcdstation {
param(
		[string]
		$apikey,
		[int]
		$number,
		[string]
		$contract
)
	#
	#Write-Host "$($stationsURL)/$($number)?contract=$($contract)&apiKey=$($apiKey)"
	$response = invoke-jcdclient -url "$($stationsURL)/$($number)?contract=$($contract)&apiKey=$($apiKey)"
	return $response
}

## Runtime

# Get list of all 'contracts' aka JCD locations
$contracts = get-jcdcontracts -apikey $api

# Get all stations in 'contract' location, e.g. Dublin, Vilnius
# Output results to table
$stations = get-jcdstations -apikey $api -contract 'dublin'
$stations | ft -AutoSize

# Get specific station number in a specific 'contract' location
# e.g. Station 40 (Jervis Street) in Dublin
$station = get-jcdstation -number 40 -apikey $api -contract 'dublin'

$station
# Convert the milliseconds since epoch into DateTime
#([timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds((0 + $station.last_update)/1000))).DateTime

Windows To Go running on a MacBook Air (Mid 2012)

Update:

Unfortunately this method isn't working on a certified device. Won't boot past the BDE PIN entry screen. Have got it to work in VirtualBox though. Will try and blog this when I get a chance.

--------------------------------------

I've been testing Windows To Go in work lately and decided to try and get it running from my MacBook Air. Clearly stated as being unsupported by Microsoft in their Technet posts. :)

MBA

An initial test boot brings you to the Windows loading screen but fails to boot with a nice new BSOD. It won't hang around long but I was lucky enough to make out "INACCESSIBLE_BOOT_DEVICE" before the machine rebooted.

 

I decided to try and hunt down drivers for the MacBook Air's hardware for Windows. The easiest source of these is the Boot Camp Assistant in Mac OS X. 

BCA

 

For those of you who don't know, Boot Camp Assistant is designed to help create an alternate partition on your Mac where you can run a Windows environment natively by selecting it at boot. This does this by non-destructively partitioning the disk and then providing the user with a ISO image or a burned CD containing all the relevant drivers to get Windows up and running on Apple hardware. How convenient!

The next screen in the Boot Camp Assistant allows you to "Download the latest Windows Support software from Apple". This is the option we want!

BCA2

 

Next up gives you two options:

  • Burn to a CD/DVD
  • Copy to an external drive

I chose the first option. As I don't have a CD/DVD burner this created a folder called "WindowsSupport" that contains all driver files required.

BC3

 

Next up requires a Windows PC with 'dism' available. We need to load in the drivers into the Windows To Go drive:

dism /image:<path\to\WTGDrive> /add-driver /driver:<DriveLetter>:\WindowsSupport\Drivers /recurse

This command should inject all of the drivers present in the Boot Camp generated support file into the WTG media, in my case, 161 drivers were loaded.

When complete, remove the driver and test boot into the Apple! Now that the USB 3.0 controller driver is loaded in it can finally contact the boot device and load the OS. Occasionally when booting I got a BSOD but this seemed to disappear on the second boot attempt.

NewImage

 

 

WTG MacBookAir 1

Office 365 : Reclaiming licenses

Migrated to Office 365? Running low on licenses and want to do a review of existing license assignments?

In work, we recently had to do a reclamation of licenses from users who had left the company but had somehow managed to retain their licensing status in Office 365.

To help with this I created a powershell script that would get a list of disabled Active Directory accounts who had a UPN (UserPrincipalName) that was formatted for use in Office 365 and cross reference that with the list of licensed users in Microsoft Online Services. Surprisingly Microsoft haven't included something like this in the existing views. I'm sure it'll be added in an upgrade...

Behold the results! Make sure you change the UPN value being queried below as I'd be surprised if ye're using DOMAIN.COM! All comments and suggestions on improvements are welcome. I'm relatively new to Powershell.

Import-Module ActiveDirectory
Import-Module msonline

Connect-MsolService -Credential (Get-Credential)

#$ErrorActionPreference = $SilentlyContinue

# Create counter and results array
[int]$i = 0
$results = @()

# Query AD for all accounts with UPN needed for Office365 that are disabled and save to array
$disabledUsers = Get-ADUser -Filter ({UserPrincipalName -like "*@DOMAIN.COM" -AND enabled -eq $false}) | select UserPrincipalName

# For all entries in $disabledUsers, query their licensing status on MS Online and save to $results
for ($i=0; $i -le ($disabledUsers.count-1); $i++) {
	$results += get-msoluser -UserPrincipalName $disabledUsers[$i].UserPrincipalName -ErrorAction SilentlyContinue
}
# For all $results where isLicensed is TRUE, output the DisplayName and License status
for ($i=0; $i -le ($results.count-1); $i++){
	if ($results[$i].isLicensed -eq "True"){
		$results[$i] | select DisplayName, IsLicensed 
	}
}

Clean out old items from your Downloads folder using find & crontab

I got a bit lazy when it came to cleaning out my downloads folder. Old .DMG files, installer files and other detritus were bloating my Download folder so that the stack view in my Dock was becoming a pain to use.

I decided to adopt a bash script we run in the office at home to aid me in my quest for a tidy Downloads folder! By leveraging the find command in bash, a user can create a script that can find any files in a directory that match certain criteria, e.g. type, file name and date created/modified.

In my case, once found, the files will be deleted. Instead of using -mtime to determine age, you can also use -atime or -ctime. I'll leave it up to yourselves to read about that though! For a downloads folder and maybe for different file types,  -atime may be more appropriate for some of you. However, since I'm dealing with installer files, -mtime will suffice!

Once the script has been created, apply to your user crontab at whatever interval you so desire!

#!/bin/bash
#
#       Delete files older than 21 days in Downloads.
#
echo "Deleting (M)PKG, DMG and ZIP files that are older than 21 days in Downloads."
 
# Delete all (M)PKG's older than 21 days
find ~/Downloads/ -name "*.pkg" -type f -mtime +21 -delete
find ~/Downloads/ -name "*.mpkg" -type f -mtime +21 -delete
 
# Delete all DMG's older than 21 days
find ~/Downloads/ -name "*.dmg" -type f -mtime +21 -delete
 
# Delete all ZIP's older than 21 days
find ~/Downloads/ -name "*.zip" -type f -mtime +21 -delete

Ruby Script: Remaining Mobile BB Data Allowance

I recently changed to Three.ie as my mobile broadband provider. They provide a nice handy way of checking remaining monthly data allowance via their "my3.three.ie" service. Signing in is handled automatically on their side based on the network you're using. Handy!

Since I've been messing around with Ruby a bit I figured I'd try and make a ruby script that would check my remaining data for me! My efforts are below!

Please comment on any improvements that you think I can make. Especially relating to the instance vs. class variables!

I use this script in combination with a bash script to display data on my desktop using GeekTool. The bash script attempts to ping the mobile gateway's IP address. If it is available, the ruby script is executed. Simples!

 

 

#!/bin/bash
#
#	Pings once to see if my Huawei B260a mobile gateway is reachable
#	if yes, execute Ruby data allowance checker
#	else, exit
#
ping -c 1 -t 2 192.168.4.1 >/dev/null
if [[ $? == 0 ]]; then
	ruby ~/Programming/Ruby/MyStuff/threeMobileBroadband.rb
else
	exit
fi

 

 

#!/usr/bin/env ruby
#
require 'rubygems'
require 'mechanize'

class ThreeMobileBroadband

@@baseURL = "https://my3.three.ie"
  
def login
  @agent = Mechanize.new

  # First Single Sign On page
  @landing1 = @agent.get 'https://my3.three.ie/myaccount/postPayFreeUnits.do'
  @landing2 = @agent.get @landing1.links[0].uri
  # Then click the continue button presented to get to account options section
  @@usagePage = @agent.post("#{@@baseURL}#{@landing2.forms[0].action}")
end

def getRemainingData
  # Parse for remaining data table
  @usageValue =  @@usagePage.parser.xpath('//div/div/div/div/table/tbody/tr/td').to_s
  # Get the data, and sub out HTML, then sub out whitespace, then split into array at a close bracket
  @data = @usageValue.gsub(/<\/?[^>]*>/, "").gsub(/\s+/, "").split(/\)/)
  return @data[1]#.inspect
end

def remainingDataAsOf
  # Parse for caption containing the date & time the remaining data was checked
  @asOfDate = @@usagePage.parser.xpath('//div/div/div/caption/span').to_s.gsub(/<\/?[^>]*>/, "").gsub(/\*\s+/, "")
  return @asOfDate
end

end

three = ThreeMobileBroadband.new
three.login

puts "3 Mobile Broadband Pro"
puts "-----------"
puts "#{three.getRemainingData} MB remaining\n"
print "#{three.remainingDataAsOf}\n"
puts "-----------"

Troubleshooting: Cisco 877 on Eircom ADSL2+

During the actual configuration of the Cisco 877s 2 weeks ago some issues arose which needed some debugging! All commands shown below were entered via global configuration mode.

 

Cisco 877 with a Linksys WAG160N on top!

DNS lookups and SSL connection issues:

Initially we had some issues with DNS lookups and connections to SSL secured services like HTTP and IMAPS. It turned out that I had failed to alter the MTU values! I didn't actually think that I had to! My bad!

 

The internal VLAN interfaces needed their maximum segment size (MSS) values  adjusted to compensate for the 8 extra bytes needed by the PPPoE header.

int vlan1
ip tcp adjust-mss 1452
exit

The GRE tunnel interfaces also needed some adjustment. This presented as being unable to access services on the other end of the VPN. Again, the MSS values needed to be lowered to account for the GRE header and IPsec headers.

 

int tun0
ip tcp adjust-mss 1300
exit

 

ADSL2+ sync problems

There was also some issues getting DSL sync and proper downstream/upstream speeds. Initially, with the ATM interface set to automatic, it was only getting 7meg down. To achieve the full speed I set the DSL operating mode explicitly to ADSL2+.

 

Still no joy though! I lost DSL sync. This was countered by setting the DSL sync mode to ANSI on the ATM interface. Once that was done, the DSL sync'd and proper speeds were achieved.

Below are the commands used on the interface.

int atm0
dsl sync mode ansi
dsl operating-mode adsl2+
exit

Configuring a Cisco 877 Integrated Services Router on Eircom Business Broadband

I decided to finally go ahead and get some Cisco gear!

To start off nice and easy, I elected to get some devices that would prove useful at home. To that end, I decided to get two Cisco 870 Series Integrated Services Routers. These would allow for me to experiment more with IOS out of college as well as providing some more security related services for Dad. Namely, a site-to-site VPN linking home with the office.

OpsView/Nagios check for Blacknight.ie Status Page

As part of my placement, we monitor websites hosted by Blacknight.ie.

If Blacknight are having issues we tend to get alerts messages about "Connection Refused" which tend to cause some consternation!

To cut down on the amount of clicking, I've wrote a small bash script that can be run by OpsView/Nagios that will check the Blacknight Status Page and return a count of the number of times that the "NOTOK" image is shown!

 

If that number is more than one, Blacknight's servers are reporting problems!

#!/bin/bash
#
#       Nagios Check Plugin for Blacknight.ie
#       Displays message if Blacknight are having technical issues with any of their servers
#
NOTOK=`curl --silent "http://www.blacknightstatus.com/server_monitor.php" | grep -E "http://blacknightstatus.com/statusmon/images/notok.gif" | wc -l`

if [ "$NOTOK" -eq "0" ] ; then
{
echo "Plugin failure: Information not found, log incident with N&S";
exit 1;
}
elif [ "$NOTOK" -eq "1" ] ; then
{
echo "All OK";
exit 0;
}
elif [ "$NOTOK"  -ge "2" ] ; then
{
echo "Blacknight Status Page reporting issues";
exit 2;
}
else
{
echo "Plugin failure: Unexpected output!";
exit 2;
}
fi

Recovering a corrupt LDAP DB on OS X Server

This weekend a problem arose with the OS X Server back home. I initially noticed it when I couldn't gain SSH access to the machine.

Using verbose output the SSH connection would reach the status of "entering interactive session" but would proceed no further.

When a user attempted to log on locally to the machine, even though the password and username were correct it would still display a logon failed message.


Using the local administrative account I determined that slapd wasn't starting up.

My MiFi!

Update!! After repeated charging cycles I noticed the battery began to swell. Apparently this is an issue that affects both the 2352 and the 2372. See here more for info :: http://www.umpcportal.com/2010/05/official-info-on-the-mifi-2372-battery-issue

---------------------

This week I took delivery of a Novatel 2352 MiFi device. MiFi is a concept whereby a mobile broadband connection is shared to a limited number of clients via 802.11 wireless technology.

Here's my experience so far!

Connecting an Apple computer to the IT Sligo WiFi

Recently I met some people who said that Computer Services was unable to help them get their Mac OS X computers onto the student WiFi network in IT Sligo.

In this day and age, why isn't a college computer services dept. able to cater for Macs...

Anyhow, here's a PDF I've thrown together to instruct a user in how to do it. Leave me a comment if you need any help or more information.

Click here to download/view the PDF!

Checking your IT Sligo Studentmail whilst avoiding webmail!

Recent changes to IT Sligo's mail setup has made this guide obsolete.

Tired of using webmail to check your IT Sligo Studentmail? I know I am. Ideally they'd upgrade to Exchange 2007 and give us all nice access to our mail AND the college global address list. I think that sounds like it makes too much sense though. For now, you have to be content with IMAP/POP access.

If this sounds interesting to you read more!!

HTML Scraping + Presentation for iPhone

Currently I'm working on an app that, like many, borrows its data from a 3rd party. In my case, I'm parsing the HTML from a website.

I had such parsing working from within the app itself using TFHpple, an XPath parser. However this meant that the iPhone would be doing all the work. Also, if the site that I'm scraping ever changed it's layout, my app would immediately stop working and my app would be out of action for at least 10 days!

To that end, on the recommendation of many fine XCakers, I began into coding a middle-man script. This script would be passed an identifer and would then go and parse the HTML generated by using that identifier. It would then return the wanted data in the form of a JSON string.

@iPhoneAppSchool

Last week I attended iPhone App School in the Castleknock Hotel in Dublin. This course is one of many courses offered by SQT Training Ltd. in Limerick and was organised by Daniel Heffernan, Patrick Collison and Damien Mulley.

The aim of the course is to teach “developers everything they need to produce their own apps—from writing their first lines of Objective-C to publishing their app in the iTunes App Store.”