Monday, February 28, 2011

Fun with HTML 5

Flash had to make up the difference between what I wanted to do on a web page and what I could do before HTML 5 for two things:
1) Playing sound.
2) Drawing on a canvas.

I had the sound working with flash using a small utility called sound manager. It was a pain, difficult to get working and keep working, but it did work in the end. However, the HTML 5 audio tag makes things easy and straightforward. For example:


1 <audio controls="controls" src="http://www.ogresoft.com/Japanese/TortoiseSVN_error.ogg" tabindex="0">
2 Your browser does not support the audio element.
3 </audio>





 If your browser doesn't support HTML 5, then go download a new one.

I never got the drawing canvas working. I considered processingjs, but HTML 5 came along before I got bored enough to make it work.

Ogresoft Kanji Quiz

So you can draw the kanji for the specified English word, instead of just a multiple choice scenario. I'll trust you to grade yourself correctly.

But my stuff is boring and rudimentary. Here are a couple of sites that do it right with canvases and drawing:
Harmony
and
Sketchpad
and here's another:

http://juliamap.googlelabs.com/

Monday, February 14, 2011

Stuff that I only use once every 6 months: XPath

It became convenient to manipulate some XML inside of a field in Sql Server (2008 r2) recently.
I found the XML datatype and the modify function which operates using XQuery. XQuery is a superset of XPath and both are w3c standards.
The silly field wasn't the XML data type already, it was just an nchar stuffed full of Xml.
The query that I wrote looked something like this when I was done:

1 CREATE TABLE T(TheXml XML)
2 GO
3
4 INSERT T SELECT CAST(code as XML) FROM some_table WHERE name = 'that thing that I was looking for'
5 GO
6
7 UPDATE T SET TheXml.Modify('delete /Object/Object/Object[@name="That one name"]/../Object')
8 GO
9
10 DROP TABLE T
11 GO

Most of my time was spent in the act of realizing that I needed to look for help on XPath and not some weird microsoft thing. The syntax that I needed (in this case "..") was easily found once I googled XPath.

Saturday, February 5, 2011

World of Warcraft automation using powershell

I have some crafting that I do in World of Warcraft that is repetitive, lucrative, and boring. If I sit at the keyboard doing it, I'm essentially just executing a for loop in my head. Not my idea of fun, especially when it could be an opportunity to hone my 'leet programming skills.

I used to automate this activity with AutoHotKey (AHK). It worked great, however, it was a new pseudo-programming language that I had to learn, and a very specific one at that. I've done some neat things with AutoHotKey, but I would prefer to use something like powershell instead. Powershell has the advantage that it can be used in a much broader set of domains than AutoHotKey, and therefor more likely to be useful to me in the future for some as of yet unknown task. I had toyed with the idea of embedding AHK inside of powershell and executing AHK commands within a powershell script, but I have found a better solution.

Up until .net 4.0 I had considered making AHK commands embeddable in Powershell. But! .net 4.0 brings us the System.Windows.Automation namespace.

With this small bit of knowledge, I was able to craft the following sample:


Import-Module C:\Windows\Microsoft.NET\Framework64\v4.0.30319\WPF\UIAutomationClient.dll
$a  = [System.Windows.Automation.AutomationElement]::RootElement.FindAll([System.Windows.Automation.TreeScope]::Descendants, [System.Windows.Automation.Condition]::TrueCondition)
$wow = $a | Where { $_.Current.Name -eq "World of Warcraft" }
$pattern = $wow.GetCurrentPattern([System.Windows.Automation.WindowPattern]::Pattern)
$pattern.SetWindowVisualState([System.Windows.Automation.WindowVisualState]::Normal)
[System.Windows.Forms.SendKeys]::SendWait("{Enter}Hi{Enter}")

Making my character say "Hi", isn't terribly useful, but it illustrates how I could send any sort of command at all to Wow.

This uses .Net 4.0 which screws up in most default configurations of powershell and powershell editors. In order to configure your powershell environment to run on .net 4.0 and be able to run this script, add the following configuration file to your editor of choice.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0.30319" />
</startup>
</configuration>

A more thorough discussion of .net 4.0 and powershell.

That config file wasn't working with PowerGUI though. I had to resort to the registry keys:

New-ItemProperty -Name "OnlyUseLatestCLR" -Value 1 -Path "HKLM:\software\wow6432node\microsoft\.netframework\"
New-ItemProperty -Name "OnlyUseLatestCLR" -Value 1 -Path "HKLM:\software\microsoft\.netframework\"