Browsing the archives for the Software category.


How to Uninstall Windows PowerShell 1.0

Software

Having problems upgrading your old PowerShell 1.0 installation to the 2.0 CTP? The CTP won’t install until you’ve uninstalled all previous versions of PowerShell, but lots of people are having problems figuring out how to uninstall v1.0.

The official docs tell you to click on the “Show updates” checkbox in the Control Panel Add/Remove Programs applet, but that didn’t work for me. “Windows PowerShell 1.0″ (or any variation thereof) didn’t show up.

A google search led me to look for installed service packs in the %WINDOWS%\$NtUninstallKB* directories that has the “PSCustomUtil.exe” file in them. Then go to the child /spuninst/ directory and uninstall the KB that way. I got a ton of warnings saying I would nuke my system back to the Stone Age should I attempt the treasonous act of actually uninstalling a KB patch, but I – being the renegade that I am – went ahead and did it anyway.

My search picked up two KB packs: KB926139-v2 (Windows PowerShell 1.0), and KB926141 (Windows PowerShell MUI).

Once I uninstalled both, I was able to successfully install the PowerShell v2 CTP3.

Hope this helps you too.

No Comments

Interesting REST API Decision

Software

Scenario: a database of images, with a REST API.

Get All is no problem: GET /images/
Get Single is no problem: GET /images/?id=12345
Add New is no problem: POST /images/ (header info)
Update is no problem: PUT /images/ (header info)

But what if I want to say to the API “I know you have an image, and I would like you to take that original image, make a copy, crop the copy to a dimensional size that I will provide to you, and then resize that cropped portion to a final size which I will also provide to you. Oh, and return the ID of the newly-created image.”

I guess technically I’m adding a new resource, but I’m not specifying the pure data for the new resource: I’m giving a set of transformations to apply to an existing resource.

Interesting conundrum. WWRFD?

No Comments

PowerShell 2.0 CTP: How to find static members

Software

This one stumped me for a minute – how do you find static members of a given type? Get-Member by default only shows the instance members.

The trick is to use the flag -static with Get-Member, to tell PowerShell that you want only static members.

Example:

[Convert] | gm -static

No Comments

PowerShell 2.0 CTP: How to get the types for a given namespace

Software

This handy little trick allows you to find out all the types that are defined for a specific namespace. If, like me, you’re using PowerShell to interact with custom DLLs, quite often you have hundreds of types defined. This script (and its variations) allows you to narrow down the list a bit when you’re searching.

var $dll = [Reflection.Assembly]::LoadFrom("$pwd\your.dll")
$dll.GetExportedTypes() | ? {$_.Namespace -eq "Your.Namespace" } | select Name, Namespace

No Comments

jQuery Plugin Tip

Software

I spent the better part of yesterday tracking down a jQuery plugin problem. I was trying to implement the Dialog plugin, which, on paper, looks to be as simple as it can get. However, I kept getting these stupid “$_.widget is not defined errors”, which made no sense. ui.core.js was included.

The upshot is that I was using a single mega-include to add all the plugins I neede for all the pages. I moved to a system whereby each page loads only those plugins it needs. I’m still not sure exactly why, but something about the loading of the 12 or 15 other plugins had stepped on the toes of the jQuery UI plugin.

Shorter: don’t use a single include for all your jQuery plugins. Add them as needed.

No Comments

PowerShell Community Extensions for PowerShell 2 CTP 3

Software, Uncategorized

PowerShell Community Extensions:

is aimed at providing a widely useful set of additional cmdlets, providers, aliases, filters, functions and scripts for Windows PowerShell that members of the community have expressed interest in.

Short answer: you want this, if you’re a PowerShell user. However, there are some initial gotchas that may cause you problems. I’m running Windows Vista Ultimate 32-bit, and had to do a bit of tweaking to get the install working properly. Here are the notes from my session:

First, go to the PSCX website to get the latest download (version 1.1.1 at the time of this writing).

Next, run the following script one time in the ISE:

$path = "$((get-pssnapin -r pscx).applicationbase)\typedata\filesystem.ps1xml"
$config = [xml](gc $path)
$config.Types.removechild($config.Types.Type[1])
$config.get_outerXML() > $path
update-typedata

Close the ISE and relaunch it.

You’ll see a bunch of errors like the following:

Set-Alias : Alias is not writeable because alias measure is read-only or constant and cannot be written to.

For some reason, some of the PSCX aliases are set to read-only and need the -Force parameter to get them to work.

Instructions for fixing each of the issues:

C:\Program Files\PowerShell Community Extensions\Profile\GenericAliases.ps1
Line 8
Set-PscxAlias measure MeasureObject -Force

C:\Program Files\PowerShell Community Extensions\Profile\PscxAliases.ps1
Line 28
Set-PscxAlias start Start-Process -Force

C:\Program Files\PowerShell Community Extensions\Profile\Debug.ps1
Line 72
set-alias gcs Get-CallStack -Option AllScope -Description "PSCX function alias" -Force
Line 89
set-alias ebp Enable-Breakpoints -Option AllScope -Description "PSCX function alias" -Force
Line 103
set-alias dbp Disable-Breakpoints -Option AllScope -Description "PSCX function alias" -Force

No Comments

Rhino Mocks Arg<T> Error

Software

In hindsight, this one was easy to predict.  Running a test with the following lines in record mode:

rd.LogMessage(Arg<MessageImportance>.Is.Anything, Arg<string>.Is.Anything);
LastCall.IgnoreArguments().Repeat.Any();

I got the error:

Failed    Execute_1    Cornbread.MSBuild.Tasks.Test    Test method Cornbread.MSBuild.Tasks.Test.RestoreDatabaseTest.Execute_1 threw exception:  System.InvalidOperationException: Use Arg<T> ONLY within a mock method call while recording. 2 arguments expected, 4 have been defined..

The obvious problem: I’m using Arg<T> when I should be using NULL to indicate “don’t care” parameters to the expected call:

rd.LogMessage(MessageImportance.Normal, null);
LastCall.IgnoreArguments().Repeat.Any();

No Comments

Excellent PowerShell ISE functions

Software

If you’re looking for a good set of prebuilt functions with which to extend your PowerShell v2 ISE environment, check out this excellent collection of PowerShell file, function, and module functions by Josh Einstein. It includes:

Open-File (opens a file in the ISE editor)
Open-Profile (opens your profile(s) in the ISE editor)
Open-Module
Open-Function
Close-File

http://einsteintech.spaces.live.com/Blog/cns!89E05724AF67A39E!724.entry?wa=wsignin1.0&sa=177582322

No Comments

Locavore – See What’s In Season

Reviews, Software

I think that Locavore is a great idea. This little app for the iPhone tells you what foods are in season depending on your geography. It only works in the U.S., but I’ll definitely want to use this when the spring-through-fall farmer’s market season starts up in Seattle.

Locavore is developed by Buster McLeod, a Seattleite and founder of the much-missed McLeod Residence, and is available for $2.99 USD on the iTunes App Store.

No Comments

Twilio Demo #3: Appointment Reminder using the REST API

Software, Web

My last Twilio demo showed how you could call Twilio and retrieve information from a web application you’ve built.  This demo shows the reverse scenario: you use a web application that calls out to Twilio, which in turn calls out to a given phone number.

This will be a pretty straightforward translation of Twilio’s existing Appointment Reminder demo, which is written in Ruby.

WARNING: Use this power only for good.  For example, you wouldn’t dream of rickrolling anyone, would you? :)

Let’s get started.  Our web app will be written in ASP.NET/C#, and, unlike the previous example, has no database backend, for simplicity’s sake.  In a real-life application, you would pull these reminders from a database on a schedule; but here we’ll bypass that part.

Before you get started, you’ll need to download the C# REST helper library from the Twilio website. This contains some code that wraps the messy network communications.

Add the file twiliorest.cs to your web application project.

You’ll need two ASPX pages: a page that captures the phone number you want Twilio to call, and a page that Twilio uses to decide what to do based on the callee’s responses.

Here’s the web form to capture input. Put this in your <form> tag in a new web form page called default.aspx:

<h1>Twilio phone reminder demo</h1>
<h3>Enter your phone number to receive an automated reminder</h3>

Here’s the code-behind in default.aspx.cs:

using System;
using System.Collections;
using TwilioRest;
 
namespace Twilio.Web.appointment
{
    public partial class _default : System.Web.UI.Page
    {
	protected const string ACCOUNT_SID = "SSSSSSSSSSSSSSSSSSSSSSSSSSSSS";
        protected const string AUTH_TOKEN = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        protected const string API_VERSION = "2008-08-01";
        protected const string CALLER_ID = "NNN-NNN-NNNN";
 
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            string phoneNumber = Server.HtmlEncode(this.PhoneNumberText.Text);
            this.MakeTwilioCall(phoneNumber);
        }
 
        protected virtual void MakeTwilioCall(string phoneNumber)
        {
            TwilioRest.Account account = new Account(ACCOUNT_SID, AUTH_TOKEN);
 
            // create the URL at Twilio to post to
            string postUrl = "/{0}/Accounts/{1}/Calls";
            postUrl = string.Format(postUrl, API_VERSION, ACCOUNT_SID);
 
            // create the variables to pass in to the POST
            string reminderUrl = Page.Request.Url.GetLeftPart(UriPartial.Authority) + "/appointment/reminder.aspx";
            Hashtable vars = new Hashtable(3);
            vars.Add("Caller", CALLER_ID);
            vars.Add("Called", phoneNumber);
            vars.Add("Url", reminderUrl);
            try
            {
                string response = account.request(postUrl, "POST", vars);
            }
            catch (Exception exc)
            {
                this.MessageElement.InnerText = exc.Message;
            }
        }
    }
}

What we’re doing here is simply handling the button click event and then using the Twilio helper library to make the RESTful call to the Twilio servers. Of course you need to put your own values in for ACCOUNT_SID, AUTH_TOKEN, and CALLER_ID, which you can get from your Account page on the Twilio website.

Twilio will call the phone number you enter in the text box, and use a new page /appointment/reminder.aspx (which you have to create) as the “controller” for the outbound call.

Your reminder.aspx page should be blank (since you will be writing XML output, not HTML). Here’s the code-behind for reminder.aspx:

using System;
using System.Collections;
using System.Xml;
 
namespace Twilio.Web.appointment
{
    public partial class reminder : System.Web.UI.Page
    {
        protected string Url = null;
 
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Response.ContentType = "text/xml";
            this.Url = Page.Request.Url.GetLeftPart(UriPartial.Authority) + "/appointment/reminder.aspx";
 
            if (Request["Digits"] != null)
            {
                DoAction(int.Parse(Request["Digits"].ToString()));
            }
            else
            {
                this.WriteReminder();
            }
        }
 
        protected virtual void DoAction(int digit)
        {
            switch (digit)
            {
                case 3:
                    {
                        WriteGoodbye();
                        break;
                    }
                case 2:
                    {
                        WriteDirections();
                        break;
                    }
                default:
                    {
                        WriteReminder();
                        break;
                    }
            }
        }
 
        protected virtual void WriteGoodbye()
        {
            this.WriteXmlToResponse("goodbye.xml", null);
        }
 
        protected virtual void WriteDirections()
        {
            this.WriteXmlToResponse("directions.xml", new string[1] { this.Url });
        }
 
        protected virtual void WriteReminder()
        {
            this.WriteXmlToResponse("reminder.xml", new string[1] { this.Url });
 
        }
 
        /// 
        /// XML helper method
        /// 
        protected virtual void WriteXmlToResponse(string fileName, string[] values)
        {
            System.Xml.XmlDocument doc = new XmlDocument();
            string path = Server.MapPath(Page.Request.ApplicationPath) + @"\appointment\" + fileName;
            doc.Load(path);
            string xml = doc.OuterXml;
            xml = string.Format(xml, values);
            Response.Write(xml);
        }
    }
}

We’re using the same WriteXmlToResponse() helper method we created in our last demo. There are three output functions: WriteReminder(), WriteDirections(), and WriteGoodbye(), which correspond to the three choices the user can make when they receive the phone call.

Also note that we set the MIME content-type to “text/xml” in the first line of Page_Load().

Not much to it, is there?

To make this demo work, you’ll also need three XML files that contain the content to read to the user:

reminder.xml

 
			Hello this is a call from Crowdify.  You have an appointment tomorrow at 9 AM.
 
			Please press 1 to repeat this menu. Press 2 for directions.	Or press 3 if you are done.

directions.xml

 
	Your appointment is located on the top of Mount Everest.
	{0}

goodbye.xml

 
	Good bye.

Note that in the first two XML files we are using the same String.Format() placeholders as in our previous demo.

That’s it – an end-to-end demo of using the Twilio REST API. The helper library that Twilio provides makes it really easy to get going in no time at all.

UPDATE: I’ve zipped the source (which includes code for all three recent Twilio demos) and saved it at http://thepursuitofalife.com/wp-content/uploads/2009/01/twilio-demo.zip.

Technorati Tags: ,,

4 Comments
« Older Posts