Tuesday 20 May 2014

SharePoint 2013 - Getting the last modified date of solutions

I'm slowly starting to use more and more powershell since moving from SharePoint 2007 to 2013. When deploying and updating multiple solutions in a SharePoint farm (especially with multiple developers working in the same environment), it can be useful to know when a solution was last updated. I put together the following little script to output the name and last changed date of all solutions in the farm to a text file:



Start-Transcript -path lastmod.txt -append
Get-SPSolution | ForEach-Object { Write-Output ($_.Name + " - " + $_.LastOperationEndTime) }
Stop-Transcript

Sunday 2 February 2014

CSS3 Responsive Menu Layout

I'm putting together a home automation / remote control system to run on my Raspberry Pi and allow me to control various devices around the house. I wanted to create a web interface that would work equally well on a laptop and phone which led me to put together a responsive web layout using CSS only which displays the navigation differently depending on the screen size.

Responsive Web Design is an approach to web development whereby a single dynamic layout provides an optimum experience regardless of the screen size or resolution it is being displayed on.

The viewport meta tag instructs mobile browsers to report a screen resolution proportional to the physical screen size. There is an excellent article on its use here.
<meta name="viewport" content="initial-scale=1.0;">
CSS3 media queries allow us to apply different CSS rules to elements depending on the screen size:

  /* mobile */
  @media screen and (max-width:540px)
  {
    .navmenu {
      text-align: center;
      margin: 0;
    }
  }
  
  /* desktop */
  @media screen and (min-width:540px)
  {
    nav {
      min-height: 200px;
      display: inline-block;
    }
  }

This allowed me to create the layout you can see here which displays a menu on the left hand side of the screen if the browser width is greater than 540 pixels and across the top of the screen for widths less than 540 pixels.

Desktop:


Mobile:


Thursday 16 January 2014

Yet Another Raspberry Pi Remote Controlled Socket

There are a few blog posts about using remote controlled electrical switches with the Raspberry Pi but I thought I'd share my experiences and code.

I bought this set of three sockets and a remote - http://www.clasohlson.com/uk/Remote-Control-Switch-3-pack/18-2035 and a cheap set of a 433Mhz transmitter and receiver from eBay. The manual refers to the sockets as EMW200R.

I came across this link which was trying to achieve the same thing and suggested attaching the receiver to the sound card on a PC and recording the signal sent by the remote control using audio software such as Audacity to identity pulses being sent and their length. Originally my recordings seemed to show audio waves instead of on/off pulses until further reading mentioned that the receiver must be connected to a line in socket instead of a microphone input. After making this change I could clearly see the pattern of hi/low pulses and measure their length.

This similar link mentions that commands are made up of the socket group, socket number, command and sync. Each of these is made up of a series of high and low pulses. I found that my sockets used the same series of pulses for each of these with the exception of a different sync command and the pulse lengths being slightly different.

I put together some python code to control the sockets by passing command line arguments of the pin number (1 - 26), the socket group (A - D), the socket number (1 - 4) and the command (On or Off). Because it is using the GPIO port, the code needs to be run as root (using sudo).

To get the code to run using RASPBMC I needed to install the following:

sudo apt-get install python-dev
sudo apt-get install python-pip
sudo pip install rpi.gpio

The code is as follows:



I then wanted to set up a cron job to turn a lamp on at 5PM every day and off at 11PM. To do this I needed to enable cron in the RASPBMC settings (not required for other distributions) and then edit the root cron table using:
sudo crontab -e -u root
I added the following lines to turn a socket on daily at 5PM and off at 11PM:

0 17 * * * /usr/bin/python /home/pi/EMW200R.py 11 A 1 On
0 23 * * * /usr/bin/python /home/pi/EMW200R.py 11 A 1 Off