Tuesday 24 May 2011

Setting up Mercurial on IIS

I have just set up a Mercurial server using IIS to serve the requests. I found that the following blog post was a great step by step guide to setting it up http://blog.schuager.com/2010/03/how-to-setup-mercurial-server-on.html. However I had a few issues that were not covered in the blog post: The first was that I was getting a "DLL load failed" error for several modules. The reason for this is that I had installed the standalone version of Mercurial and that it could not reference the compiled C versions of the python modules. I fixed this by copying the pure python modules into the lib directory. You can find the pure python modules for the 1.8.3 version of Mercurial at http://selenic.com/repo/hg/file/3cb1e95676ad/mercurial/pure The second issue was that IIS refused to serve cs files, as the Request Filtering feature was enabled. I disabled this for the whole repo by adding the following to the web.config at the top level of the IIS hg app.
<configuration>
    <system.webServer>
        <security>
            <requestFiltering>
                <fileExtensions>
                    <clear/>
                </fileExtensions>
            </requestFiltering>
        </security>
    </system.webServer>
</configuration>

Simple Python Command to generate a random GUID

Every so often I need to generate a GUID for a MS Proj file. The simple python command will create one for me:
python -c "import uuid;print uuid.uuid4()"
Changing that to a emacs function so I can insert them where ever I need we get:
(defun genUUID ()
  "Generates a UUID"
  (interactive)
  (shell-command "python -c \"import uuid;print uuid.uuid4()\"" t)
)

Tuesday 12 April 2011

Remember to just read the code

The problem that I had was that I needed a repeating Timer object in python. I googled, but the answers that I found didn't sit right, and then I remembered that I could just read the code for the threading module and see how the Timer object was implemented, then just use that. Below is the code I came up with.

But the moral of the story is that having the source code for your language's core libaries around is a good thing.

class RepeatingTimer(threading.Thread):
    """Call a function after a specified number of seconds, it will then repeat again after the specified number of seconds
       Note: If the function provided takes time to execute, this time is NOT taken from the next wait period

    t = RepeatingTimer(30.0, f, args=[], kwargs={})
    t.start()
    t.cancel() # stop the timer's actions
    """

    def __init__(self, interval, function, args=[], kwargs={}):
        threading.Thread.__init__(self)
        self.interval = interval
        self.function = function
        self.args = args
        self.kwargs = kwargs
        self.finished = threading.Event()

    def cancel(self):
        """Stop the timer if it hasn't finished yet"""
        self.finished.set()

    def run(self):
        while not self.finished.is_set():
            self.finished.wait(self.interval)
            if not self.finished.is_set():  #In case someone has canceled while waiting
                self.function(*self.args, **self.kwargs)

Friday 11 March 2011

Installing org-googlecl.el on Windows

Here is how I installed org-googlecl.el (found at http://www.emacswiki.org/emacs/org-googlecl) onto my Windows 7 box at work.

  • I droped the el file into my emacs extentions directory
  • I added the following to my .emacs
(setq load-path (cons "C:/emacs/org-googlecl" load-path))
(require 'org-googlecl)
(setq googlecl-blogname "Technology and Me")
(setq googlecl-username "my google username")
(setq googlecl-footer "") ;;Add no footer
(setq googlecl-blog-exists t) ;;Ask me if the blog exists before posting
(setq googlecl-list-regexp "\\(.*\\),\\(http.*\\),?\\(.*\\)$") ;;update the reg-ex for listing (see below)
python c:\python\26\Scripts\google %*
  • Once the google command was working I found that the org-googlecl-list-blogs was not running.
    • The problem was that the regex was wrong as I had not added any tags to my posts. So I updated the googlecl-list-regexp to account for the missing ,
  • The final tweek is that the quoting was wrong for windows on some of the commands so I changed it to match the windows style within org-googlecl

Testing org-googlecl


Just installed the org-googlecl emacs module. Hoping it will mean that I will blog more than once a year :)