Powershell on Rails -- MonadRail!
secretGeek .:dot Nuts about dot Net:.
home .: about .: sign up .: sitemap .: secretGeek RSS

Powershell on Rails -- MonadRail!

Okay -- i've been going on about powershell a lot lately. And you want to hear about other things. I can accept that. Even the people on the bus seem to pull faces when i start spontaneously talking about powershell.

(An old lady on the bus this morning, for example, just didn't get it. --A universal parser! I said, but did she even smile? Not a smirk.)

Well, the reason for the powershell obsession is that I'm currently reading "Powershell in Action" by Bruce Payette which is a cracker! It goes deep into the language, as deep as can be.

And I've been thinking about using Powershell for writing websites. Rails-style, no less.

Conveniently, one of the examples Bruce provides is a webserver implemented using powershell (download source code from the Manning website and see 'Invoke-Webserver.ps1' from chapter 11)(or for a similar example, see Vivek Sharma or this very dangerous example from soapy frog )

What got me thinking about a rail-style powershell server were Two things. One: in response to the hanselminutes on monoRail, and two because Mike Schinkel mentioned the concept of a powershell web programming in his hunt for a new language.

Mike S:

"[Jeffrey Snover said] that PowerShell can do web, and will be able to do it more easily in the future. [Mike feels that] webified PowerShell should be a url-based object-selector-and-invoker like Django or Rudy on Rails."

Which is a nice idea. Seemingly, the major limitation with using Powershell as a webserver, at the moment, is our old friend threading. A powershell webserver is just a polling loop that handles all requests synchronously. Hence, every client has to wait in line to have their request processed. Not good. Ideally it would instead receive request-events and handle each of them on new threads. This (multi-threading) is promised as a future feature.

Anyway -- looking at Bruce's example of a webserver -- it would be pretty easy to see how it could be given rails-like behaviour.

Note that I do *NOT* have the time to be thinking about this... so i just wanted to sketch the basic idea here and see if anyone is interested in taking over.

Basically Bruce's script waits for get requests and then looks for simple mathematical expressions, such a "2+2" -- which is evaluates and sends back to the browser. This is the relevant bit of code:

        $received = @($received -match "GET")[0]
        if ($received)  
        {
            $expression = $received -replace "GET */" -replace
                'HTTP.*$' -replace '%20',' '
            if ($expression -match '[0-9.]+ *[-+*/%] *[0-9.]+') 
            { 								

Well, instead of expecting a mathematical expression like that, we could look for a path that has:

Zero or more 'areas', followed by exactly one 'controller name', followed by exacly one 'action', optionally followed by one or more 'parameters'.

In honour of John Backus (r.i.p.), i'd love to express this in EBNF... but alas, the brain forgets.

Anyway, i'll just write it in DWIM: {/area{/area}}/controller/action{?paramname{=value}{+paramname{=value}}}

So once we've tokenized the path into areas, controller, action, params...

...we check that the relevant 'controller' exists in the specified 'area'.

Where a 'controller' is just a cmdLet or maybe a script, with specific parameters (action, params).

And an 'area' is just a sub-folder. Nothing more, nothing less.

We pass the action and the params to the relevant controller, and then.... either the controller takes over from there, or maybe it just returns some html for us to return to the client.

Go for it. You have one hour.

Oh, and the name I've got for this one is 'MonadRail' as a play on 'monorail' and 'monad' (the original code name for Powershell)





'Jeffrey Snover' on Sat, 24 Mar 2007 01:27:59 GMT, sez:

Dude! You are going to absolutely freak out when you see what we are working on for the next version. Even that old lady on the bus is going to be talking about it! I'm bursting to give the details but can't. We'll probably have something public this fall.

Jeffrey Snover [MSFT]
Windows Management Partner Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx



'Mitch Denny' on Sun, 25 Mar 2007 19:31:37 GMT, sez:

I've been thinking along exactly the same lines :)



'Serge van den Oever [Macaw]' on Wed, 28 Mar 2007 21:31:35 GMT, sez:

Same here! Would be great to have PowerShell as dynamic language for web site development. All this power at your fingertips... Rally looknig forward on what you are working on Jeffrey, any possibilities to get is the beta program for that?



'lb' on Tue, 10 Apr 2007 09:55:34 GMT, sez:

even brucey's sample web-server is very dangerous -- it's open to 'powershell injection!'

i just used it to create a directory on my machine (an example of a dangerous side effect... lucky i didn't try delete...)

i passed this to it:

http://127.0.0.1/get-date;dir;md f;1*5

and it executed all the commands (not just the 1*5)....

to fix this i changed the line with regular expression in it from:

if ($expression -match '[0-9.]+ *[-+*/%] *[0-9.]+')

to:

if ($expression.trim() -match '^[0-9.]+ *[-+*/%] *[0-9.]+$')

(three changes: added the trim(), added a ^ to the front of the regex, added a '$' to the end of the regex.)

much safer ;-)



'Richard C Haven' on Tue, 10 Apr 2007 16:30:24 GMT, sez:

Is this JAP (Just Another Perl) ?

And look what crimes against humanity people are doing with Perl...



'Mike Schinkel' on Wed, 02 May 2007 15:30:15 GMT, sez:

Very cool. I attended a Powershell ISV training event in Redmond a few weeks ago, and now I'm reading Bruce's book. I am actually getting more and more psyched about Powershell, and am seriously considering working on adapting Powershell to the web. I'd probably focus on IIS though, as that's make it easier to host the app at a web hosting service.



'Mike Schinkel' on Wed, 02 May 2007 15:32:13 GMT, sez:

BTW, why do you call the SoapyFrog example "dangerous?"



'lb' on Wed, 02 May 2007 22:37:18 GMT, sez:

@Mike
soapy frog's example is potentially dangerous because if you posted it up on a public-facing internet site, then anyone could come along and use it to run a command such as Delete *.* on your server.

regarding "adapting Powershell to the web" i'm waiting to see what the powershell do next -- because i think they're gonna do the hard work for us.



'Mike Schinkel' on Thu, 03 May 2007 01:16:32 GMT, sez:

lb> anyone could come along and use it to
lb> run a command such as Delete *.* on
lb> your server.

Ah...Doh! For some reason I asked that after reading several others and I got it confused with [1]. What do you think of [1] as a framework for calling "Powershell Server Pages" using the Powershell SDK? Would it scale? Bart wrote "Ignore the naive approach to threading in Main" but he's turned off comments so I can't easily ask him what he means.

And from your comments on [2]:

lb> i think that the powershell team are doing some tricky stuff
lb> for the next release to let powershell be webified more easily.

I asked Jeffrey when I was in Redmond a few weeks ago and he said it would be nice if someone did something Powershell for the web but they were instead focused on system managability for several years. :-(

lb> they ought to be involved in the DLR -- but weren't mentioned
lb> there as far as i could see.

DLR?

[1] http://community.bartdesmet.net/blogs/bart/archive/2007/02/22/httplistener-for-dummies-a-simple-http-request-reflector.aspx
[2] http://www.mikeschinkel.com/blog/commentview,guid,57a0f01e-167c-4d1d-8430-553e11cc79ef/



'Mike Schinkel' on Thu, 03 May 2007 01:17:19 GMT, sez:

Oh, and...

lb> regarding "adapting Powershell to the
lb> web" i'm waiting to see what the
lb> powershell do next -- because i think
lb> they're gonna do the hard work for us.

What do you think is needed?



'wow gold' on Tue, 04 Mar 2008 13:00:08 GMT, sez:

Cool, the post.

Thanks for the information.




name


website (optional)


enter the word:
 

comment (HTML not allowed)


All viewpoints welcome. But the right to delete any post for any reason is reserved. Don't make me do it. Aim for constructiveness. Comments may be republished, emailed to your loved ones or printed and used as toilet paper. Also, I get particularly nasty on comment spam. It's not worth even trying to post comment spam here -- your html is escaped, and your links are given a rel='nofollow'. By attempting to post a comment, you understand that if the comment is considered spam, at my absolute discretion, your IP address may be used as the target of a prolonged distributed denial of service attack. Your electricity might suddenly stop working. Your car tyres will go mysteriously flat. You will suffer permanent hairloss. Your dreams will be filled with terrifying monsters. And in any case I reserve the right to record and publish your IP address.

 

TimeSnapper is a life analysis system that stores and plays-back your computer use. It makes timesheet recording a breeze, helps you recover lost work and shows you how to sharpen your act.

 

NimbleText - FREE text manipulation and data extraction

NimbleText is a Powerful FREE Tool

Use it for:

  • extracting data from text
  • manipulating text
  • generating code

It makes you look awesome. Use it right now! Go on! Hurry! Don't walk, run!

 

Articles

Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion
Got CSV in your javascript? Use agnes. Got CSV in your javascript? Use agnes.
I went to write down a book name and founded an internet empire instead. I went to write down a book name and founded an internet empire instead.
NimbleText: Origins NimbleText: Origins
The Windows 8 Mullet The Windows 8 Mullet
Cosby: spontaneous striped background generator Cosby: spontaneous striped background generator
Slides from WDCNZ: Live Coding Asp.net MVC3 Slides from WDCNZ: Live Coding Asp.net MVC3
MVC 3, MVC 3, "Third Times a Charm" references
Custom Errors in ASP.Net MVC: It couldn't be simpler, right? Custom Errors in ASP.Net MVC: It couldn't be simpler, right?
Anatomy of a Domain Hijacking, part 2: The Website Who Came In From The Cold Anatomy of a Domain Hijacking, part 2: The Website Who Came In From The Cold
Anatomy of a Domain Hijacking, part 1 Anatomy of a Domain Hijacking, part 1
secretGeek.net domain has been stolen. The site may go down. secretGeek.net domain has been stolen. The site may go down.
Boring article: 'untrusted domain' issue with SQL Server. Boring article: 'untrusted domain' issue with SQL Server.
Coding While You Commute Coding While You Commute
Test Driven Dentistry Is A Good Thing Test Driven Dentistry Is A Good Thing
The 'less crashy' release of NimbleText The 'less crashy' release of NimbleText
Rethinking Toolbars in Visual Studio (or any IDE) Rethinking Toolbars in Visual Studio (or any IDE)
Where shall we have lunch? Where shall we have lunch?
Setting up email for your microIsv Setting up email for your microIsv
The NO Visual Studio movement: Compiling .net projects in Notepad++ The NO Visual Studio movement: Compiling .net projects in Notepad++
ZeroOne: the editor for programmers who think in binary ZeroOne: the editor for programmers who think in binary
Mercurial workflow for personal projects (with a .net bias) Mercurial workflow for personal projects (with a .net bias)
I see you're using vim. Let me fix that for you. I see you're using vim. Let me fix that for you.
The worst recruitment spam I've ever read The worst recruitment spam I've ever read
A thank you I forgot to say A thank you I forgot to say
My new product, NimbleText, is live My new product, NimbleText, is live
Grabbing the free songs of Jonathan Coulton (with Powershell) Grabbing the free songs of Jonathan Coulton (with Powershell)
Using NimbleSet to compare lists Using NimbleSet to compare lists
Wanted: Wiki Lists (dot org) Wanted: Wiki Lists (dot org)
DOS on Dope: The last MVC web framework you'll ever need DOS on Dope: The last MVC web framework you'll ever need
JSON Query Languages: 5 special purpose editors JSON Query Languages: 5 special purpose editors
What then, is b? What then, is b?
SQLike: A simple editor SQLike: A simple editor
Yet Another BizPlan Generator. Yet Another BizPlan Generator.
HOT GUIDS: A hot or not site for guids HOT GUIDS: A hot or not site for guids
How does life get better? One tiny hack at a time. How does life get better? One tiny hack at a time.
24 things to do, and 100 things *not* to do (yet) for building a MicroISV 24 things to do, and 100 things *not* to do (yet) for building a MicroISV
Venture capital won't kill Jeff Atwood, it will only make him Jeffer. Venture capital won't kill Jeff Atwood, it will only make him Jeffer.
A handy workflow image for newbie mercurial users A handy workflow image for newbie mercurial users
Fractal Feedback, a diversion into recreational programming Fractal Feedback, a diversion into recreational programming
Hump-Jumping: How the Education of Computer Science can be Saved, err, maybe. Hump-Jumping: How the Education of Computer Science can be Saved, err, maybe.
Suggested User Experience Improvements for DiffMerge Suggested User Experience Improvements for DiffMerge
SQL Style Extensions for C# SQL Style Extensions for C#
The Movie Hollywood (And My Wife) Doesn't Want You To See: Weekend at Jacko's The Movie Hollywood (And My Wife) Doesn't Want You To See: Weekend at Jacko's
Sysi: the ultimate administrators toolkit Sysi: the ultimate administrators toolkit

Archives .: secretGeek :: Complete Archives
TimeSnapper -- Automated Screenshot Journal TimeSnapper.com    
Version 3.3: true productivity boost

Next Action NextAction
Managing the top of your mind

NimbleText -- World's Simplest Code GeneratorNimbleText -- World's Simplest Code Generator, Text Manipulator, Data Extractor

25 steps for building a Micro-ISV 25 steps for building a Micro-ISV
3 minute guides -- babysteps in new technologies: powershell, JSON, watir, F# 3 Minute Guide Series
Universal Troubleshooting checklist Universal Troubleshooting Checklist
Top 10 SecretGeek articles Top 10 SecretGeek articles
ShinyPower (help with Powershell) ShinyPower
Now at CodePlex

Realtime CSS Editor, in a browser RealTime Online CSS Editor
Gradient Maker -- a tool for making background images that blend from one colour to another. Forget photoshop, this is the bomb. Gradient Maker


[powered by Google] 


How to be depressed How to be depressed
You are not inadequate.



Recommended Reading


the little schemer


The Best Software Writing I
The Business Of Software (Eric Sink)

Recommended blogs

Jeff Atwood
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Rhys Parry
Joel Pobar
Thomas White
OJ Reeves
Eric Sink

Aggregated Links

proggit
dzone
hacker news
dot net kicks

Human Link Machines

interesting finds
a continuous learner's weblog
arjan's world
weekly link post

LinkedIn profile
LogEnvy - event logs made sexy
Computer, Unlocked. A rapid computer customization resource
PC Smart Buys - Computer Hardware in Australia
 
home .: about .: sign up .: sitemap .: secretGeek RSS .: © Leon Bambrick 2006 .: privacy

home .: about .: sign up .: sitemap .: RSS .: © Leon Bambrick 2006 .: privacy