Thursday, 3 October 2013

Add 'Open command prompt here' option to Windows Server 2008


Add 'Open command prompt here' option to Windows Server 2008

Eeek, we need to dive into the registry for this!



1 Find the key:

HKEY_CLASSES_ROOT\Drive\shell\cmd

Rename the key Extended to Extende-Orig


2 Find the key:

HKEY_CLASSES_ROOT\Directory\shell\cmd

Rename the key Extended to Extende-Orig


That should work immediately.

Wednesday, 17 July 2013

Mongo quick start

So I thought I'd jot down how to get started with MongoDB quickly so I don't have to look it all up again next time I have to install it.

These instructions are for mac, tweak as necessary!

Install it

In a terminal
brew update
brew install mongodb

Start it

Then open a terminal and start it
mongod

Open it

Open another terminal and open a mongo shell
mongo

Query it

You should now be in a mongo shell, to view dbs, collections etc... type
show dbs
use whicheverdbyouwant
db
show collections
To find out where the logs, db and config is type in...
db.getSiblingDB("admin").runCommand({getCmdLineOpts:1})
And for basic query, presuming you have a users collection, count all users starting with S
db.users.find( {"userName": /^S/ } ).count()

Find out more

All the above and much, much more... http://docs.mongodb.org/manual/contents/

Friday, 24 May 2013

Unreadable gibberish

*
My biggest achievement this week was undoubtedly to convert a perfectly good webpage into gibberish!

Wb rukdist anwiinojort tcas hium mes etduentidfp te luqmibt e jenkuptyj waid cahbofu ubti godwerash!

The reason you might want to do this, is when you need to focus on some other aspect of the page/prototype/design other than the content. Or if you want to use screenshots but don't want potentially sensitive content to be visible.

This little method adds 'gibberish' to a context object e.g. window, then you can run gibberish.go( element ); where element is a dom node e.g. document.getElementsByTagName('body')[0] .

Check it out...
http://clanceyp.github.io/gibberish.js/

Monday, 13 May 2013

Edit navigator userAgent in Chrome

I keep needing to do this and forgetting, so here we go...
  1. Open the developer tools 
  2. click on the settings icon bottom right 
  3. click on the Overrides menu 
  4. edit the User Agent setting field

Saturday, 20 April 2013

Simple XML to JSON

I needed to convert an xml document into json and went for the most simple implementation which just loops though the node tree and creates json object. Because the expected xml is nice and simple (nodes don't have both a text value and child nodes, they are either one or the other) I didn't really need to use anything complicated.

There was an issue though, it transpires I do need to preserve the attributes. The standard way to do this would probably be to make the attributes children of the current node and add a '#text' child to capture the original text value.


So for example the following xml...


<root>
    <item>
      <title>Porro est qui</title>
      <link>http://boom.shakalack</link>
      <author id="123">Jasmine Smith</author>
    </item>
</root>

would produce something like this...

{
  "root":{
    "item":{
      "title":"Porro est qui",
      "link":"http://boom.shakalack",
      "author": {
        "#text":"Jasmine Smith",
        "-id":"123"
      }
    }
  }
}

or this...

{
  "root":{
    "item":{
      "title":"Porro est qui",
      "link":"http://boom.shakalack",
      "author": {
        "#text":"Jasmine Smith",
        "@attributes":{
         "id":"123"
        }
      }
    }
  }
}


This kind of formatting is not going to work for me though, the fact that if an attribute is added to a xml node which didn't have one before, your json format will change makes this too risky to use. Also the issue that on some nodes you can use the value directly and on others you need to go down a level to find the child '#text' node, make this a rather messy solution.

After thinking about it I settled on a, not ideal, but fairly simple solution, appending the attribute to the current named node at the same level, so given the same xml the output becomes....

{
  "root":{
    "item":{
      "title":"Porro est qui",
      "link":"http://boom.shakalack",
      "author":"Jasmine Smith",
      "author@id":"123"
    }
  }
}

This format you can now access these attributes, for example in a mustache template you might use the following...

{{#item}}
  <details>
 <summary>{{title}}</summary>
 <div><a href="/authors/{{author@id}}/show">{{author}}</a></div>
  </details>
{{/item}}

This works quite well for me, it's simple and easy to read. One has to keep in mind that the presence of an @ symbol means you can't use dot notation though, e.g. item.author@id will not work you have to do this item["author@id"] instead, as I mentioned, not ideal!


view the xml to json javascript on github

Simple XML to JSON


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.
 

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)