Saturday, 16 March 2013

Adding a virtual host on mac

Quickly adding a virtual host on mac (10.6) assuming your adding the host name "test".
  1. Add your host name to your hosts file
    • Open a terminal and type: sudo nano /etc/hosts
    • Add "127.0.0.1 test" to the bottom of your hosts file, without the quotes.
  2. Enable apache vhosts file
    • open your httpd.conf 
    • in a terminal type: cd /private/etc/apache2
    • then: sudo nano httpd.conf 
    • find the line #Include /private/etc/apache2/extra/httpd-vhosts.conf
    • remove the # at the beginning of the line (if it has one, if not, your good to go)
  3. Add the folder you want the host to reference to the httpd-vhost.conf file
    • back in the terminal: cd extra
    • then: sudo nano httpd-vhosts.conf 
    • add the following to the bottom of the file, changing the DocumentRoot, directory paths and log file names appropriately.
    • <VirtualHost *:80>
          ServerAdmin webmaster@dummy-host2.example.com
          DocumentRoot "/User/patrickc/www/test"
          ServerName test
          ErrorLog "/private/var/log/apache2/test-error.log"
          CustomLog "/private/var/log/apache2/test-access.log" common
          <directory "/User/patrickc/www/test/">
             Options Indexes FollowSymLinks
             AllowOverride All
             Order allow,deny
             Allow from all
          </directory>
      </VirtualHost>
          
  4. Restart apache
    • in your terminal; sudo apachectl restart (on some setups it might be; sudo apache restart)
  5. Then open a browser and type http://test
  6. That should be it, if you get a permissions error check the value in  <directory  />


Wednesday, 20 February 2013

Focus/Blur event propagation

So I'm making a dynamic menu work better for keyboard users and just thought it'd take 10 mins to add device independent event handlers to the existing code. Did that, hit Ctrl+F5 a couple of times and nothing happend.

It turns out, not all events propagate, which when you think about it makes sense. I'm using YUI for this particular project so need the focus event module, if your hand rolling you'll need use the IE focusin/focusout events, and for everything else register your event listeners in the capturing phase, check it out on quirksmode.org.





 

Wednesday, 6 February 2013

Chrome extensions don't run on first use

Okay, so I'm having this problem with my chrome extensions. The user downloads and installs an extension, clicks on the icon and boom, nothing happens! The reason being, page loaded before your extension was installed don't contain the content scripts.

As yet, I haven't found a work around but, at least, using the following you can send an alert to the page and tell the user whats happening...
/* in the background.js */

chrome.browserAction.onClicked.addListener(function(tab){ 
    linkAudit.log('alert if not loaded'); 
    chrome.tabs.executeScript(tab.id, {
     code:'if(!window.linkAudit){alert("Please reload the page to run Link Audit")}'
    }) 
});
Investigate the Link Audit extension.

Thursday, 27 December 2012

IE7 and contentEditable

IE7 and contentEditable

Interestingly (I'm playing it rather loose and free with the term 'interestingly' here) I found that removing the contentEditable attribute from some elements cause them to become editable in IE7. The senario is this, HTML comes in, you don't know if it contains contentEditable attributes, but if it does you want to remove them. Run a function on the HTML to remove attributes. This was being done in jQuery.

$("*").removeAttr("contenteditable");

The effect of the above was some elements became editable in IE7, also list-items where missing their markers (common IE behaviour if contentEditable is true) running a function to set the attribute to false...

var els = document.getElementsByTagName("*");
for (var i = 0; i < els.length;i++){
    els[i].contentEditable = false;
}

... this will stop the content from being editable in IE7 but wouldn't fix the missing bullet markers. I still can't find a fix for this, so resorted to cleaning the HTML and stripping out the contentEditable attributes on the server before sending the HTML down to the client. (You can always rely on IE to give you something to do! : )

Also, interestingly *cough*, an embedded browser in a .NET app will use the oldest version of IE loaded on the machine, rather than the newest. So if your client is using IE9, it's still quite likely that they have something like IE7 in your .NET app. Worth setting the metadata X-UA-Compatible to IE=edge, this seems to have the effect to force the system to use the latest installed version of IE.

<meta http-equiv="X-UA-Compatible" content="IE=edge" />
As the above may cause validation errors, you might want to put this in your apache config instead...

Header set X-UA-Compatible "IE=edge"

Where ever you set this header, remember where it is, I have a nasty feeling it'll need editing at short notice at some point in the future!




Monday, 17 December 2012

Brr, it's cold in here...

It was the Crisis Mid-winder swim on Saturday which involves a quick dip in Brockwell lido. The water was crystal clear, blue and a sharp 4 deg C.



Creating an Ubuntu 12 launcher for Chrome to use a proxy-server.

To create a new launcher...
  1. Type 'menu' into the Dash dialogue (alt + F2) this should bring up the Main Menu manager
  2. Select Internet from Menus
  3. Highlight Chromium Web Browser and select Properties, leave that open so you can duplicate it 
  4. Create a new menu item and duplicate the existing menu item, call it something sensible though
  5. Add what ever options you require and close


That should be it, now you can search for your launcher in Dash. You'll need to close any open chrome browsers before launching a new one. Using this method means you don't need to change your proxy settings globally and you can set up a load of links using different proxies to run as and when needed.

Saturday, 24 November 2012

Quote of the day...

Angry work colleague...   "THAT'S WHY I HATE WINDOWS!"
Me... "Why?"
Angry work colleague...   "BECAUSE IT'S SHIT!"

Well thought out, considered opinion!

On an XSLT related issue, I had to count the number of items starting with a given letter or number for an A to Z. We can find all the items starting with any given character using starts-with(). In the cace of counting elements which start with a diget we need to do it slightly differently...

<xsl:param name="lcase">abcdefghijklmnopqrstuvwxyz</xsl:param>
<xsl:param name="ucase">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:param>
<xsl:param name="digits">1234567890</xsl:param>

<!-- return the number of books whose name starts with any given letter -->
<xsl:template name="alphabet_counter">
        <xsl:param name="letter" />
        <xsl:value-of select="count(/books/book[starts-with(translate(name,$lcase,$ucase), translate($letter,$lcase,$ucase))])"></xsl:value-of>
</xsl:template>

<!-- return the number of books whose name starts with a number -->
<xsl:template name="int_counter">
        <xsl:value-of select="count(/books/book[contains($digits, substring(name, 1, 1) ) ])"></xsl:value-of>
</xsl:template>

Saturday, 10 November 2012

Add Open terminal here to IntelliJ

Tip of the day, add "Open terminal here" to context menu in IntelliJ (11.1) running on Ubuntu (12).

If like me, your missing the option to open a terminal from the context menu, this can be added quickly by adding an external tool;

  1. File > Settings > External tools
  2. Add, opens an add/edit tool form
  3. Put in a suitable name, deselect the Synchron... and Open console checkboxes
  4. Select where you want it to show up in the 'Show in' section
  5. In the 'Tool Settings' section, add "gnome-terminal" as the Program and "$FileDir$" as the Working Directory
  6. Click OK 
That's it, you should now have the option in your right click context menu. Simples.

In Mac OS it's a little different, try putting "open" as the Program and $FileDir$ -a Terminal as the Parameters, worked for me on OSx 10.9.2



 

Note: the opinions on this page don't represent that of my employer in anyway. And, actually only vaguely represent my opinions on the date of publication. (Unlike Ms T, I am very much for turning)