Skip to content

Blog

How to save XDocument to xml and use single quotes for attribute values

I had to do this for AVBlocks xml licenses recently. It is not straightforward, but here is the C# code.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;

namespace Primo.LicenseBuilder.Xml
{
    public static class XmlExtensions
    {
        public static string ToSingleQuoteString(this XDocument xDocument, 
                                                    System.Xml.Formatting formatting = Formatting.Indented)
        {
            using (StringWriter sw = new StringWriter())
            {
                using (XmlTextWriter writer = new XmlTextWriter(sw))
                {
                    writer.Formatting = formatting;
                    writer.QuoteChar = '\'';
                    writer.WriteNode(xDocument.CreateNavigator(), false);
                    writer.Flush();
                }

                return sw.ToString();
            }
        }
    }
}

How to install and configure TortoiseHg on Mac

I finally got fed up with SourceTree and installed TortoiseHg on my Mac development machine. Read on:

Xcode Configuration

For best results make sure you have the latest XCode and Command Line Tools installed (XCode 5 and Command Line Tools September 2013 at the time of this writing). You can get them from the Apple Developer Downloads site.

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

1. Install / Update Ruby

ruby -v
should return something like:

ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.3.0]

You can skip the rest of this section if you have Ruby already installed.

Install the Ruby Version Manager and Ruby

curl -L https://get.rvm.io | bash -s stable --ruby
source /Users/yourname/.rvm/scripts/rvm

2. Install Homebrew

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Follow the instructions in the script. The installation will take a few minutes.

Verify your brew installation

brew doctor

This returned a few problems for me, but the output will vary depending on the existing system configuration.

Warning: An outdated version of Git was detected in your PATH.
Git 1.7.10 or newer is required to perform checkouts over HTTPS from GitHub.
Please upgrade: brew upgrade git

Warning: /Library/Frameworks/Mono.framework detected
This can be picked up by CMake's build system and likely cause the build to
fail. You may need to move this file out of the way to compile CMake.

Warning: You have MacPorts or Fink installed:
    /Users/yourname/.rvm/bin/port, /opt/local/bin/port

This can cause trouble. You don't have to uninstall them, but you may want to
temporarily move them out of the way, e.g.

    sudo mv /opt/local ~/macports

Warning: /usr/bin occurs before /usr/local/bin
This means that system-provided programs will be used instead of those
provided by Homebrew. 

Consider setting your PATH so that /usr/local/bin
occurs before /usr/bin. Here is a one-liner:
    echo export PATH="/usr/local/bin:$PATH" >> ~/.bash_profile

Warning: Your Xcode (x.y.z) is outdated
Please install Xcode a.b.c

The issues will depend on your specific installation. Use your best judgement about what to fix and what to ignore. Fixing one by one:

Warning: You have MacPorts or Fink installed
sudo mv /opt/local ~/macports
Warning: /usr/bin occurs before /usr/local/bin
export PATH=/usr/local/bin:$PATH
echo export PATH="/usr/local/bin:$PATH" >> ~/.bash_profile
Warning: An outdated version of Git was detected in your PATH.
brew upgrade git

or if you do not have Git at all:

brew install git
Warning: Your Xcode (x.y.z) is outdated

You can ignore this one.

Warning: /Library/Frameworks/Mono.framework detected

You can ignore this one.

3. Install Python packages

I had Python already installed before Homebrew, so I had to amend PYTHONPATH like so:

export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH  
echo export PYTHONPATH="/usr/local/lib/python2.7/site-packages:$PYTHONPATH" >> ~/.bash_profile

Then install PyQt (this also installs qt and sip):

brew install pyqt

Install QScintilla

brew install qscintilla2

Install Python Package Mananger (pip)

sudo easy_install pip

Install Pygments, iniparse and Mercurial Python packages. If you have Mercurial already, this will update it to the latest version.

sudo pip install -U Pygments iniparse Mercurial

4. Install TortoiseHg

Clone TortoiseHg repository using Mercurial:

hg clone http://bitbucket.org/tortoisehg/thg/ ~/Tools/TortoiseHg
cd ~/Tools/TortoiseHg/
hg update stable

Quick test. You should see TortoiseHg Workbench running:

./thg log

5. Install TortoiseHg Mac App

Clone thg-mac-app repository
hg clone https://bitbucket.org/skrysmanski/thg-mac-app ~/Tools/thg-mac-app
Set the TORTOISEHG_PATH variable
cp -p ~/Tools/thg-mac-app/tortoisehg-path.sh ~/

Edit ~/tortoisehg-path.sh so it points to ~/Tools/TortoiseHg. This is what ~/tortoisehg-path.sh looks like after the change:

``` bash

!/bin/sh

export TORTOISEHG_PATH=~/Tools/TortoiseHg ```

Install TortoiseHg.app

Option + Drag the TortoiseHg.app from ~/Tools/thg-mac-app to your Applications folder.

How to upgrade GCC to 4.7+ on Ubuntu 12.04

Note: This is only needed on Ubuntu 12.04. Ubuntu 12.10 already comes with GNU C++ 4.7 and above.

Install

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.7 g++-4.7

Update Alternatives

Add GCC 4.7
sudo update-alternatives --remove gcc /usr/bin/gcc-4.6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
Make sure GCC 4.7 is the default alternative
sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc)

Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/gcc-4.7 60 auto mode
1 /usr/bin/gcc-4.6 40 manual mode
2 /usr/bin/gcc-4.7 60 manual mode

Press enter to keep the current choice[*], or type selection number: 0

Verify

gcc --version
gcc (Ubuntu/Linaro 4.7.3-2ubuntu1~12.04) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Configuring PHP / CURL root certificates on Windows Server

This post is about configuring PHP/CURL root certificates for a WordPress installation running on Windows Server 2008 R2 / IIS 7.5.

Yesterday I was trying to add an RSS feed to the AVBlocks Wiki Site and I got this error:

``` text WP HTTP Error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

In my case the [feed](https://groups.google.com/forum/feed/avblocks-support/msgs/rss.xml?num=3) was coming from the [AVBlocks Group](https://groups.google.com/forum/#!forum/avblocks) on Google. However, the Google Groups feeds are served via secure https:// protocol and that requires SSL for server-to-server communication. The problem is that WordPress uses *php\_curl*, and on a standard PHP installation of WordPress, *curl* does not come with the root certificate authorities installed.

Here is how to fix it:

1. You need to be running PHP 5.3.7 or later.
2. Download [mk-ca-bundle.vbs](https://raw.github.com/bagder/curl/master/lib/mk-ca-bundle.vbs) from the [Curl](https://github.com/bagder/curl/tree/master/lib) repository on GitHub.
3. Open a Command Prompt as Administrator and go to the directory in which you downloaded `mk-ca-bundle.vbs`.
4. Run `mk-ca-bundle.vbs`. Accept the default filename and do not include the text information for each certificate.
5. After running this you will end up with a file `ca-bundle.crt`.
6. Copy that to a known location, e.g. `{path}/ca-bundle.crt`.
7. Add `curl.cainfo={path}/ca-bundle.crt` to php.ini. See [PHP Runtime Configuration](http://php.net/manual/en/curl.configuration.php) for more details: 

``` ini
[PHP]

;;;;;;;;;;;;;;;;;;;
; CURL Settings ;
;;;;;;;;;;;;;;;;;;;

curl.cainfo={path}/ca-bundle.crt
8. Restart the IIS web site

Setup Google Analytics for a Bitbucket repository

The idea is to create a new Google Analytics property for Bitbucket and then have a separate Google Analytics profiles for each repository. That way I end up with one profile per repository neatly grouped under the Bitbucket property. In the profiles, I also use filters to include only the traffic for the corresponding repository.

This post is about myself setting up Google Analytics for our AVBlocks-Samples repository, so in the steps below I use the “AVBlocks-Samples” name and the corresponding URL. Needless to say, when going through the steps, you will use the name and URL of your own Bitbucket repo. OK, here it goes:

Create a new Google Analytics property called Bitbucket

  1. Go to Google Analytics and login into your account.
  2. Click on the Admin link at the top right corner.
  3. Click on the property drop-down list and then select the New Property at the bottom.
  4. Select “Classic Analytics” for tracking method.
  5. Under Website Name, type “Bitbucket”.
  6. Under Web Site URL, select “https://” and type “bitbucket.org”.
  7. Click [Get Tracking ID]

2013-08-19-19_30_38-google-analytics 2013-08-19-19_52_18-google-analytics

Add the Tracking ID to the Bitbucket repository

Google Analytics will generate a new tracking ID for you, something that looks like “UA-123456-78″.

  1. Copy the Tracking ID that Google generated
  2. Go to the repository admin page on Bitbucket
  3. Paste the Tracking ID into the “Google Analytics key” field.

2013-08-19-19_55_54-avblocks-samples-bitbucket

## Update the Google Analytics profile

  1. Go back to Google Analytics admin page
  2. Select “Bitbucket” for property
  3. Select “All Web Site Data” for profile
  4. Click “View Settings”
  5. Update the Website’s URL with the full URL of your bitbucket repository.
  6. In my case I put “https://” and “bitbucket.org/primosoftware/avblocks-samples”.
  7. If you plan to have multiple repo profiles under the Bitbucket property, I recommend changing the View name to something other than “All Web Site Data”. I my case, I named my property “AVBlocks-Samples”.
  8. Click Apply.

2013-08-19-20_06_28-google-analytics 2013-08-19-20_12_10-google-analytics 2013-08-22-06_27_20-google-analytics

Setup a profile filter

  1. Go back to Google Analytics admin page
  2. Select “Bitbucket” for property
  3. Select “AVBlocks-Samples” for profile
  4. Click “View Settings”
  5. Click “Filters” and then on the +New Filter button.
  6. Type “AVBlocks-Samples” for Filter Name
  7. Select “Predefined filter” for Filter Type
  8. Select “include only”, “traffic to subdirectories”, “that begin with”
  9. Type “/primosoftware/avblocks-samples/” for Subdirectory
  10. Select “No” for Case Sensitive
  11. Click Save

2013-08-22-07_00_25-google-analytics 2013-08-22-07_15_04-google-analytics 2013-08-22-07_15_47-google-analytics