Several people have blogged about using the Google charts api from PowerShell, but everyone seems to be using the “simple” numerical encoding, so I figured that as the first step of my own google chart api wrapper module I would start out by writing up a simple encoder. I’m not posting this to the script repository until I’m done with it — this is just the number encoding function.
But I figured I’d blog it here in case it will help anyone else write the full wrapper module “for” me before I get around to it
In any case, remember this doesn’t encode numbers higher than 4095, so if you have a bunch of numbers and some of them might be larger than that, you’ll still need to normalize them so they are within that range. I’ll post the function to normalize a series of numbers later this evening, because for some reason I can’t find it right now, but I’m sure I already wrote it
.
That’s the whole thing … it’s really only about three lines of code (including the definition of $ody), but the rest is necessary to make it handle parameters or pipeline values.
Oisin (x0n) Grehan wrote a module for PowerShell 2 which uses the WMI ManagementEventWatcher and the new event-handling features of PowerShell 2.0 to automatically run scripts whenever you plug in or unplug a removable drive …. specifically, the AutoMount module runs New-PSDrive whenever you plug in a removable, and Remove-PSDrive when you unplug it.
The bottom line is it works great (at least on Vista), and I think I’ll add it to my “AutoModules”
... sadly, it’s not on PoshCode yet :/ but you should go- check it out, it’s a great example of how to work with events in PowerShell, both consuming and creating them (incidentally, x0n’s PSEventing snapin would let you accomplish this in PowerShell v1). [new] x0n’s posted it on PoshCode, so you can Get-PoshCode 525 if you have the module or script installed, or download it from the embed link below:
This is just a short note to let you know that after much persuasion from various of her friends, my wife has started her own blog to write about parenting, being a stay-at-home mother of preschoolers, saving money by shopping smarter, and in general … all the many things she does.
It’s called Helpful Mom and if you’re a parent of preschoolers, you should check it out!
For this edition of my Power User tips for PowerShell, I’m going to share my (heavily annotated) prompt function. Feel free to to copy useful pieces or just place the whole thing in your profile script
I’m not going to say anything more, I’ll let the comments speak for themselves.
Edit: Someone just pointed out that I forgot the bit of my prompt that sets my current path into the window title, and I realized I also forgot the bit that puts (Admin) in the title if you’re running “elevated” on Vista.
[new] Edit: Ok, how many people noticed that I incorrectly used the Environement.CurrentDirectory when I set the WindowTitle (meaning it would only work right in FileSystem drives)? Fixed now.
Well, Microsoft promised these releases would come “this summer” so I guess it’s no surprise that Visual Studio 2009 2008 SP1 is out this week, following closely on the heels of SQL Server 2008
It should go without saying that my favorite feature is the performance increases of between 205 and 45% for WPF-based applications — without having to change any code (or indeed, even recompile, just get your end users to download SP1 for .Net 3.5 ). The improved designers, extra controls, ADO.Net Entity Framework, and so on are well worth the download of SP1 for Visual Studio 2008 (or the upgrade for the Express Versions). It’s really hard to understand how they figure this is a “Service Pack” ... when it seems clear that they should have just waited until now to launch VS 2008 together with SQL Server. Imagine what it would have been like if they’d held off Vista and Server 2008 too … [o.O]
Well, time to go install some upgrades. Hopefully Silverlight 2.0 will come out of beta really soon too, and I’ll finally be out of this ridiculously extended period of using beta software for everything. (Well, ok, I’ll still be using a CTP of PowerShell to take advantage of my new superfast WPF toys, but nevermind). Hopefully I’ll find some time to play with this stuff sometime this week in-between finishing my Master’s paper…
I recently decided to bite the bullet and try using code-generating ORM in my projects instead of manually writing my own data access layer (DAL) with custom SQL and everything … and felt that after careful research into the current state of Linq-to-SQL and ADO Entities, etc. I should use NHibernate …
Everything went ok at first, my first “pretend” project worked, and I feel like my design is definitely more flexible, and using ORM allows me to be more agile with regards to changing customer requirements, because I have less work to do to adjust the data-access layer of my app. However, I’m now trying to apply this to my first real-world problem, one which I consider actually rather trivial, and which I have in fact written a custom DAL for this in the past, but I cannot figure out if it’s even possible to do this in NHibernate.
I’m hoping someone can help me figure out the mappings for this, but failing that, I’d accept suggestions for a alternate design for the database that will make it work for NHibernate. Let me show you my current design and explain it a bit.
First, a basic overview of the application. This is a statistics app, and uses the generic terms of Model, Factor and Level to talk about experiments. For the sake of this example, lets talk about experiments on photocopiers
. A Factor is a variable, in the sense of photocopiers, something like paper size or color. Each Factor has a set of Levels which represent the possible values for it — to use our previous example, sizes like ’8.5 × 11” Letter’ and ‘Tabloid’ or colors like “White” and “Ivory.”
The most important thing to understand is that in our application, all of the Models in a specific instance of the database are presumed to be experiments of the same basic type, so all of the Factors could apply to any experiment model. However, in a given experiment, not all of them will be used, and of those which are used, not all of the possible Levels will be used.
As you can see, the database design is fairly simple, there is one table for each basic type of data, and a fourth table which essentially stores the specific makeup of a given Model. The idea is that when you create an experiment Model, you choose a few Factors and for each of those you choose a few Levels. We simply store which levels you’re interested in for this experiment, since we can trivially determine the Factors based on that. For the sake of completeness, here’s some pesudo-code of the database setup script (leaving out constraints and such, for the sake of clarity).
create table [Factor] (
[Id] int IDENTITY not null,
[Name] varchar(250) not null,
primary key ([Id])
)
create table [Level] (
[Id] int IDENTITY not null,
[Name] varchar(250) not null,
[Factor] int not null,
primary key ([Id])
)
create table [Model] (
[Id] int IDENTITY not null,
[Name] varchar(250) not null,
primary key ([Id])
)
create table [ModelLevels] (
[Model] int not null,
[Level] int not null
)
The C# classes are equally simple, but remarkably different. In an object-oriented design we model collections, rather than belonging. So while the database stores which Factor a Level belongs to, in the application we want to represent which Levels are in a Factor.
The firs major problem is that what I would like is to be able to represent the “Factor” object as a derived type of List<Level>, like this:
This would allow me to iterate the levels as foreach(Level lev in aFactorVariable){...}, and other such niceties of grammar. But NHibernate doesn’t seem to have any idea how to deal with this, so I’ve resigned myself to representing the levels as an IList<Level> member of the Factor class, like this:
This brings us to our second problem. I can’t find any way to explain to NHibernate the relationship between a Model and a Factor. I need my Model to be represented something like this:
However, I can’t find a way to explain to NHibernate how to determine which Factors should load into the Model (based on the ModelContents table which maps Levels). I could create a view or a stored procedure in the database which shows the Model-to-Factors mapping, but I can’t see how to make NHibernate handle the updates by adding the Levels to this ModelContents table. I could hypothetically use SQL Server’s updatable views and INSTEAD OF triggers, but I’m not honestly sure it would work, and I don’t particularly like that it would lock me into SQL Server.
If someone can riddle me that one, I have one other issue: that is, how do I limit the Factor object that is based on a specific Model so that it only has Levels in it which belong to that specific model (that is, that are present in the ModelContents table for this model)? Of course, the idea is for the user interface to present to the user an “Add Level” dialog which shows them all the Levels which exist for that Factor, and allows adding them to the model (as well as adding new Levels), but lets tackle one problem at a time, shall we?
I’m going to post this question (and this url) to the various Alt.Net and NHibernate discussion groups, and I’ll post back here any answers I get which seem to lead in the right direction …
I can post my current NHibernate mappings if anyone wants to see them, but there’s nothing special about them, and they certainly don’t work correctly as I’ve described above.
Fast on the heels of the Chinese government, the Orwellian Department of Homeland Security has officially announced that it is claiming new police powers this week: to seize travelers’ laptops, cell phones, cameras, PDAs, iPods, video tapes, books and even magazines … without any suspicion or probable cause and keep them as long as they like without any specified process for returning them whatsoever.
DHS claims that business data will be protected, and that all data will be destroyed when the review is completed if no probable cause exists to keep the information — but bear in mind that there was no probable cause to start with, so there’s actually no incentive for them to ever declare the review complete and destroy the data.
It’s important to note that these policies apply to anyone entering the country — including citizens and foreigners, tourists and visiting businessmen. If you leave the country, you suspend your rights to privacy and property at the border upon your return along with everyone else. I wonder how we would have reacted if France started seizing laptops, cameras, cell phones and books from every American who entered their country? What about if this had happened in 1984? or 1999, for that matter?
Remember: no matter how much the authoritarian “security” forces would like you to think you live in a different world now than we did 10 years ago — the Constitution and your Civil Rights have not been suspended yet — if you don’t think the government should have the right to take your things, and root through your photos, phone calls and emails whenever they like for no reason whatsoever… you should write your representatives in Washington and let them know that you hold them personally responsible for this ridiculous power-grab by our so-called homeland security department.
Here’s the letter I sent to my representatives, maybe you’d like to do the same: Read the rest of this entry »
Someone earlier today was gushing about how neat Evernote is … it’s a OneNote-like application which features add-ins for browsers and email clients to let you clip text and images, or record voice, take notes in handwriting, etc … and it’s cross-platform and has a version for Windows Mobile and iPhone! I thought it sounded interesting, although the key feature of sharing all your notes automatically across all your clients made me a bit suspicious, so I went online to check it out.
By now, those of you who have previously read my rants about software licenses know to avoid Evernote. But let me tell my story anyway. I downloaded the installer and ran through it, noting that the click-through license displayed in the installer is for the software only, and references possible additional terms for a “service” ... So far, so good, the most annoying thing I noticed while scanning was:
9. Monitoring and Removal of information. ... Evernote Corporation and its designees shall have the right to refuse or remove any information that violates this Agreement or is otherwise objectionable, in Evernote Corporation sole judgment…
I didn’t particularly like that in a software license, but it wasn’t enough to get me to stop installing the software. However, I have to say, the license it is ridiculously huge:
Nobody should be expected to put up with this. Let me say this for the record:
This will allow people like me to read the license before we download the software and possibly save us the trouble. Pretending you think people will read something like that in the tiny little window is a cruel joke.
So, there’s a few new features in the latest version of the PoshCode script module, and a few new features in the repository itself, including an embed feature, which I will demonstrate by embedding one here. Notice that the scripts on the site have an embed code, and it will normally embed the full height of the script, but you can add a height parameter as I did here to force the height and cause vertical scrolling.
The latest version of both the v1 compatible PoshCode script (you have to dot-source it) and the v2 CTP2 compatible module support an -Upgrade parameter to the Get-PoshCode script, so you can call Get-PoshCode -Upgrade and it will retrieve the latest version of the script (whether you need it or not).
The New-PoshCode script has been fixed so you can use it to submit to other pastebin sites (particularly, the temporary one we use for support on IRC).
The searches now return items with the same “probability” of being correct in date order, so newer versions of scripts show up at the top — this also affects the cmdlets, and the integration with apps such as PowerGUI. Note, however, that if an older version of the script fits your search-terms better, it may still show up at the top — I’m working on this.
The PoshCode site now supports wrapping by other community sites — if you want to wrap our site in yours, let me know, and I can give you a custom subdomain and allow you some control over the display, as I did for PowerShell Community …
I finally fixed the problem with logging that my host was having, so I have a week’s worth or so of logs which Webalyzer informs me show that we average about 600 visits a day, and a surprising number of subscribers to our RSS feed…
I have three new features planned for the next couple of weeks or so: finishing the browsing feature, implementing better version-tracking, and adding tagging. The key feature missing from the brownsing is the ability to go to the “next page” of results (right now you can only see the first page of scripts for the site or for authors) — we should have that fixed soon.
The version tracking feature (which is mostly a matter of cleaning up some db queries) will result in being able to build a visual history for a given submission, including branching, etc. and should allow users to easily retrieve “the latest” version of a given script.
Tagging will improve searching and browsing by providing a way to categorize scripts and browse by tags, but I’m a little nervous about it because it seems that to be useful it will need to allow tags to be added by users who didn’t create the original script, and this is complicated since we have not so far created a login/authentication system.
I’m still debating how to properly do this, but I think that ultimately we’re going to have to use a login system with support for OpenID so that authors can identify themselves with their blog URLs, etc … and can use the same identity on the PowerShell Community site once that site gets their OpenID implementation working properly.
The alternative that I had been considering: using signed scripts as the only authentication, seems to fail in the instance of tagging — it would basically require you to make up a PSD1 file specifying the script id and the tags you want to apply and then sign it and submit it. I think you’ll agree that’s way too much work for the end users, even if it was automated — and it would also require the server to validate the signature and parse the script!