“Objects in System.Reflection are closer than they appear.”
by Greg McCoy

Posts Tagged ‘SOS’

SOS migration…

I’m currently in the process of pulling the content of two of my Blogger sites into my new WordPress installation. One of which is the SOS site.

If you’re trying to get to the SOS downloads and are not able to, please give me a bit of time. I’m doing a lot of reconstruction as is, and it may take me a while to update all of the links and move all of the files over.

SOS is not going away. Just a little bit of time is all I need. Thanks.

Installer vs. SOS.VSA

Here’s an interesting tidbit that I just learned. I’m not sure why, but the installer (as it is now) will not update the Visual Studio Add-ins if they already exist.

I was certain that I had included them in the newest installer, but installing here at work gave me a copy of the add-ins from 1/15/08 (or so I thought). I deleted the SOS.VSA.dll file, re-ran the installer, chose “Repair”, and the new version was right there.

I will need to investigate this further, but until then, you may need to do something similar if installing newer versions of the SOS.VSA. Sorry for the inconvenience, I will keep you updated.

Snippet: Rijndael Encrypt (and Decrypt)

Here is a pretty easy and useful little snippet to encrypt and decrypt in Rijndael (AES). Nothing fancy, but here it is nonetheless. Oh, and it uses your logged in Windows account name as the key, so you may want to change that to be your company’s domain, an MD5, your pet’s mother’s favorite teacher’s high-school sweetheart’s maiden name, etc… ;)

Download: Rijndael Encrypt and Decrypt (C#)

Sample Clear:

Sample Encrypted: (with “KEY”)

Installer v0.15/v0.4

I know I just put v0.14 out, but hey… it’s the weekend! So here’s the download, and the skinny on the v0.15/v0.4 changes…

Click here to download the Snippets on Steroids (S·O·S) Client/Add-in Installer (v0.15/v0.4)

SOS.Tray v0.15 (client) changes…
* Added web snippets (*.swb).
* Added snippet macros (*.smx).

SOS.VSA v0.4 (add-in) changes…
* Added support for new snippet types (*.scs, *.svb, *.swb, *.smx).

SOS.Setup v0.15 (installer) changes…
* Added file-type associations for new snippet types (*.swb, *.smx).
* Added five new “starter” snippets.

Example of a web snippet file (*.swb):


Example of a snippet macro file (*.smx):

Security\Rijndael Encrypt.scs
Development\URL Encode.scs

*** UPDATE ***
The SOS.VSA v0.4 that was supposed to be included in the installer now is. Sorry for the inconvenience.

SOS.Tray v0.14 + SOS.VSA v0.2 (Installer)

Wow! So much to say… No time. Must sleep.

Okay, so here’s the QnD overview. This installer has the latest build of the SOS.Tray client and the SOS.VSA add-in all bundled up. The enhancement report will come later, but the real kicker is that I migrated Michael’s Compiler snippet into the client as a dynamic snippet builder. Now you have three types of snippets— compiled (*.sos), C# (*.scs), and VB.NET (*.svb). Base classes sit in your “My SOS” folder, and get compiled (as ran) with the dynamic snippets. Also, these files are now associated to the SOS.Tray client, and will “pretend” a [Screen -> Screen] with the default input as whatever is on the clipboard.

Like I said, I’ll post more in an update. Until then, here’s the installer.

Click here to download the Snippets on Steroids (S·O·S) Client/Add-in Installer (v0.14/v0.2)

*** UPDATE ***

Changes in SOS.Tray v0.14…
* Snippet input is now streamed first, then again via argument if streaming returns nothing.
* Added dynamic C# snippets (*.scs) and base partial class at “My SOS\Base.cs”.
* Added dynamic VB.NET snippets (*.svb) and base partial class at “My SOS\Base.vb”.
* Associated snippets (*.sos, *.scs, and *.svb) with a [Screen -> Screen] input/output method.
* Snippet menu reloading now keeps active snippet in the tree menu.

Change in SOS.VSA v0.2…
* Snippet no longer “replaces” input if output matches. (Stops unnecessary check-outs.)

Snippet: Lipsum

I needed some Lorem Ipsum for a design that I’m working on. So I hit lipsum.com (as always), and it hit me; why in the world couldn’t I turn the lipsum process into a snippet? So here it is. It takes your input and generates replacement words (matching length, and capitalization) extracted from lipsum.com‘s official output (no injection). Now, they say that there are over 200 words in their dictionary, but I generated 100 paragraphs and only ended up with 186 distinct. Oh well. 186 is still pretty good looking. Have fun!

Click here to download the snippet: Lipsum

Sample Input:
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.

Sample Output:
Praesent et natoque libero, Curae Magna id dis aenean montes erat. In hac velit ad a morbi ac convallis Proin vestibulum nibh 45 ID, tempor ut quam 2000 fusce hac.

Visual Studio Add-in…

Whew! So here’s the deal… I’ve been killing myself for the past few days writing the Visual Studio (2005 and 2008) Add-in for SOS. After days of head-shaking, throat-clearing, knuckle-popping, and ear-ringing (listening to Kristin’s favorite music; what I call “angry-poppy-crap”), I have finally gotten to a point where I am in the last stages of testing. After I get some personal confirmation that it’s behaving as desired, I’ll be releasing here for you all. I’m hoping this only is another day or so out, but I really don’t want to give you all something that acts crazy, doesn’t load, or worse— gives you any of my aforementioned develo-phrenia symptoms.

A brief explanation of the Add-in is warranted, I beleive…

The Add-in adds your entire SOS menu (save for the Input/Output methods) in the context (right-click) menu of the code window. The item that shows directly on this menu is labeled “Snippets on Steroids”, and houses everything else (so to not clutter your context menu. Under the root menu item are your snippet categories and snippets, labeled and nested just as they are currently in the SOS.Tray client. An example of the menu structure would be “Snippets on Steroids > Translation > ROT-13“. When you click on a snippet, the text that is currently selected is simply fed to the snippet, then replaced by the output of it.

Developers— I know you can appreciate the simplicity of this one… How nice will it be to just select one of your long string literal SQL queries and run formatting or regex operations against it, take that same literal pasted into an XML document and HTML encode it in couple of clicks, or automatically encrypt your connection string with your company’s proprietary algorithm that you hate the tool for (sorry; I had to throw that one in there). ¦¬]

Like I said, only another day or two. If you want to try it now, leave a comment and I’ll shoot it over to you. I really think it’s stable now though, so it shouldn’t be long…

Wish me luck! (…and my testers; yikes!)

*** UPDATE ***

Click here to download the SOS Visual Studio Add-in (SOS.VSA) v0.1

Arguments on antidepressants…

I was coming into a few problems with backslashes and quotes not playing consistently nice for snippet input. So I set out to find out why. I ran across a few interesting facts about command line arguments while trying to figure out the best (most reliable) way to escape them for snippet input. The following is an excerpt from tenouk.com

  • For information, Microsoft uses Microsoft C Runtime (CRT) for C codes; that is Microsoft C version (mix of standard C and Microsoft C).
  • Microsoft C startup code uses the following rules when interpreting arguments given on the operating system command line:
  1. Arguments are delimited by white space, which is either a space or a tab.
  2. A string surrounded by double quotation marks is interpreted as a single argument, regardless of white space contained within. A quoted string can be embedded in an argument. Note that the caret (^) is not recognized as an escape character or delimiter.
  3. A double quotation mark preceded by a backslash, \“, is interpreted as a literal double quotation mark ().
  4. Backslashes are interpreted literally, unless they immediately precede a double quotation mark.
  5. If an even number of backslashes is followed by a double quotation mark, then one backslash (\) is placed in the argv array for every pair of backslashes (\\), and the double quotation mark () is interpreted as a string delimiter.
  6. If an odd number of backslashes is followed by a double quotation mark, then one backslash (\) is placed in the argv array for every pair of backslashes (\\) and the double quotation mark is interpreted as an escape sequence by the remaining backslash, causing a literal double quotation mark () to be placed in argv.

This is quite interesting. I knew there must be a better way, however. Fortunately, I was correct. I found the following frustration post on the MSDN forums shortly after. Here’s the juicy stuff…

The static System.Environment.CommandLine will provide the original untampered cmdline – should be straight forward to use this.
there is also System.Environment.GetCommandLineArgs() method but this is used to create the args parameter passed to main and suffers the same problem , I mention it because, when you use it the element 0 of the array contains the path to the excutable which you can use to strip the exe name from the System.Environment.CommandLine

Awesome! What this gives us is a good clean way to get all of our input directly from the command line call to the snippet. The biggest problem is that I (currently) can do nothing to eliminate this problem for you. I will however be trying to come up with a better answer than that. Until then, it’s the snippet developer’s job to be sure that the input being given to the snippet is clean. Here is a pretty decent GetInput() method that should do the trick. Oh, the code below also allows the snippet to be “piped”-to, so it really is a good idea to consider using it as your input standard. The key is making sure it’s implemented. ;)

private static String GetInput(){   System.IO.Stream stream = Console.OpenStandardInput();   System.IO.StreamReader reader =      new System.IO.StreamReader(stream);   String input = reader.ReadToEnd();   if (String.IsNullOrEmpty(input))   {      String application = Environment.GetCommandLineArgs()[0];      input = Environment.CommandLine         .Substring(            Environment.CommandLine.LastIndexOf(application)            + application.Length + 2)         .Trim().Trim('\"');   }   return input;}

Snippet: Compiler

Here’s a little snippet (from a friend; thanks again, man!) that will allow you, out of the box, to compile and execute C# code from your SOS input. The results of that code are returned as your response. I’m sure all of the C# coders out there can appreciate this one. One (pretty big) added bonus is the fact that this snippet compiler is not bound to C#. It’s not even bound to .NET! Within the configuration file, there are settings that will allow you to specify your own compiler, switches, and base code.

Click here to download the snippet: Compiler

Sample Input:
String text = "Hello World!";
foreach(Char c in text)
   String format = "[{0}:{1}] ";
   String character = c.ToString();
   String ascii = ((Int32)c).ToString();
   Console.Write(format, character, ascii.PadLeft(3, ‘0’));

Sample Output:
[H:072] [e:101] [l:108] [l:108] [o:111] [ :032] [W:087] [o:111] [r:114] [l:108] [d:100] [!:033]

SOS.Tray v0.11

Based on some excellent feedback, I’ve fixed a few issues I had not even noticed along with some enhancements that I had slated for later, but now realize were more crucial than I had originally anticipated.

Here is the change log for v0.11…

* Input/Output text fields in the GUI are now resizable.
* Input/Output text fields now have a font selection dialog.
* Input/Output text fields now have persisting properties (fonts and colors).
* The GUI’s [x] (Close) button now hides the GUI, instead of closing it.
* The GUI’s [_] (Minimize) button now minimizes the GUI, instead of hiding it.
* File system monitor now updates snippet menus and GUI tree automatically.
* Recent input tracking implemented. Currently tracks your last ten input items.

Click here to download Snippets on Steroids (S·O·S) v0.11

Get a free book about code review best practices.