1. This is my second attempt at writing up my DOS tricks. I changed jobs, just like the original post said, but found the original tricks were woefully inadequate in real world use. Consider this as my first attempt at 'pro' tricks. I'll start with the basics from the command-line.
     
    C:\Users\YzOrg>echo %date:~10,4% %date:~4,2%
    2010 11

    C:\Users\YzOrg>echo hi >  %date:~10,4%%date:~4,2%.txt

    C:\Users\YzOrg>dir *.txt
    Volume in drive C has no label.
    Volume Serial Number is B8EE-D08D

    Directory of C:\Users\YzOrg

    11/24/2010  09:32 AM                 5 201011.txt
    10/01/2010  10:40 AM               210 SDK.txt
                   2 File(s)            215 bytes
                   0 Dir(s)  199,100,514,304 bytes free

    C:\Users\YzOrg>set line=0123456789 ABCD 0123456789 ABCD0123456789 ABCD0123456789 ABCD0123456789

    C:\Users\YzOrg>echo %line:~10,8%
    ABCD 01

    C:\Users\YzOrg>echo hi > demo%date:~10,4%%date:~4,2%%date:~7,2%.log & dir demo*.log
    Volume in drive C has no label.
    Volume Serial Number is B8EE-D08D

    Directory of C:\Users\YzOrg

    11/24/2010  09:50 AM                 6 demo20101124.log
                   1 File(s)              6 bytes
                   0 Dir(s)  199,100,379,136 bytes free

    C:\Users\YzOrg>set /?
    Displays, sets, or removes cmd.exe environment variables.

    SET [variable=[string]]

    ...<SNIP>

    Pitfalls with using %DATE% and %TIME% in filenames

    Time and date from OS can have spaces.  So put the log filename in its own variable and use
        SET MYVAR=%MYVAR: =0%
    

    to replace any spaces from %DATE% and %TIME% to 0.

    I recommend you follow this guidance, put StdErr redirection at the end of the line.

    Here is the final snippet for use in scripts:

    Code
    set LOG_TIMESTAMP=%date:~10,4%%date:~4,2%%date:~7,2%-%time:~0,2%%time:~3,2%.JobName.log
    set LOG_TIMESTAMP=%LOG_TIMESTAMP: =0%
    echo starting at %date% %time% with log %CD%\log\%LOG_TIMESTAMP%
    

    Output
    starting at Tue 02/13/2011  8:26:57.99 with log C:\Users\YzOrg\log\20110213-0826.JobName.log
    

    Other CMD Tricks

    Use %~dp0 to get the full path of the current batch file.  %0 is the scriptname argument, '~dp' are modifiers to get the drive and path of that argument, %~dp0.

    Rule: always turn off 'echo' in batch files using this first line:
    @if not defined _echo echo off
    

    Use 'set _echo=1' before calling the script to debug it (it will echo every command) References: set /?, call /?, for /?, setlocal /?
    0

    Add a comment

  2. The post I wrote for GreenShot used a configuration file to tell the app to use the CLR and .NET FX that is already installed on Windows 8.  The same hack works for the Metro UI Tweaker tool from The Windows Club (which I found via winsupersite.com).

    So grab the configuration file I used for GreenShot but this time name it "Metro UI Tweaker.exe.config".
    0

    Add a comment

  3. How to run Greenshot on .NET 4.5 (Windows 8).  Greenshot is an OSS alternative for SnagIt (screenshot tool).
    Don't install the Greenshot installer. It will refuse to install without .NET 2.0, even though it seems to run fine on .NET 4.5.

    1) download the zip file and extract it to C:\Program Files\Greenshot. 
    Note: On Win8 you'll need to be running a process with Admin privileges to create the directory and extract the files.
    2) create Greenshot.exe.config to tell .NET to run Greenshot on .NET 4 with a couple of compatibility options.  https://gist.github.com/1223509
    0

    Add a comment

  4. I'm thinking about how to take some of the middle-tier parallel concepts like #RxNet and apply them in a little OSS GUI app I've been thinking about.  I quickly found this gem, ReactiveUI PDF .  A couple of quotes that stoked my interest:
    "What’s in this library
    ReactiveCommand - an implementation of ICommand that is also a Subject whose OnNext is raised when Execute is executed. Its CanExecute can also be defined by an IObservable which means the UI will instantly update instead of implementations which rely on RequerySuggested."
     ...
    "Some philosophy
    A lot of examples of the Reactive Extensions make its domain appear really constrained, like the only thing it’s ever useful for is either handing web service requests and implementing drag-and-drop. However, here’s the key thing to realize - a property change notification is an event.Once you realize that Reactive Programming applies to any time an object changes state, Rx suddenly becomes  far more applicable to any programming domain - really, Rx is a library to model state machines that are context-free with respect to threading."
    And, I can use all the high-level composition that I've been using in the middle tier.  Like Merge() to join streams of events, and Throttle() to do in one line that takes a half-page of code with other frameworks.  This looks promising.  One glitch.  The author of the library recently moved from Microsoft (Office team) to GitHub.  Uh-Oh.  But too promising to ignore it.  At least I hope he still works in C#, maybe he can help with the Windows OSS clients, like Git Extensions, which is written in C# (but not hosted on github).


    nRoute is another MVVM framework that leans on Rx for event streams.  It's author is French.  Hmm.


    It's good to have choices, unlike 18 months ago.

    0

    Add a comment

  5. I was thinking about how to rewrite an old (2009) WCF middle-tier service, and have been thinking about George Tsiokos's recent TPL vs. RxNet post.
    I think a middle-tier service is perfect to illustrate how I see the strengths and weaknesses of these two.  Specifically the scenario:

    Complex Middle-Tier:  Startup vs. Message Handling

    TPL might be great for startup tasks.  There is one 'global' task, Initialize, that has many sequences and chunks (in TPL these could be child tasks) that can have different degrees of parallelization.  It also requires global 'command and control' and 'top-down' composition and error handling (a type of event correlation).  If any critical part of startup fails then tear-down the service (cancel outstanding parallel tasks) and exit the service quickly.  So global handling and command-control programming style (root of the call hierarchy has all control).

    Once everything is initialized you want bottom-up event correlation and error handling.  The function at the top of the callstack has no control (usually a WCF operation or I/O completion callback).  You only want global state to be touched when absolutely necessary, not touched by ignorable infrastructure errors, and not by errors that are ignorable according to business rules.

    Startup, large complex top-down composable work:
    TPL

    Streams, composable business logic (streams that include error/end):
    RxNet

    With .NET 5 the TPL dataflow libraries might change things again, but for now I much prefer RxNet for composing and routing 'messages' between layers.  We recently used it in a project and when you have to correctly handle error scenarios it shines.  Imagine a WCF callback for a business operation that is completely async, where business logic has to fire if the notification fails (delivery of the data to the client).  The code isn't pretty in either case, but is better and can be handled at the right level of the lego blocks with RxNet.
    0

    Add a comment

  6. I’ve written this trick every new job or position I miss out on the old standby, using batch script to capture command-line output to a dated log file.  This post is so I’ll never have to reproduce it again.

    C:\Users\YzOrg>echo %date:~10,4% %date:~4,2%
    2010 11
     
    C:\Users\YzOrg>echo hi >  %date:~10,4%%date:~4,2%.txt
     
    C:\Users\YzOrg>dir *.txt
    Volume in drive C has no label.
    Volume Serial Number is B8EE-D08D
     
    Directory of C:\Users\YzOrg
     
    11/24/2010  09:32 AM                 5 201011.txt
    10/01/2010  10:40 AM               210 SDK.txt
                   2 File(s)            215 bytes
                   0 Dir(s)  199,100,514,304 bytes free
     
    C:\Users\YzOrg>set line=0123456789 ABCD 0123456789 ABCD0123456789 ABCD0123456789 ABCD0123456789
     
    C:\Users\YzOrg>echo %line:~10,8%
    ABCD 01
     
    C:\Users\YzOrg>echo hi > demo%date:~10,4%%date:~4,2%%date:~7,2%.log & dir demo*.log
    Volume in drive C has no label.
    Volume Serial Number is B8EE-D08D
     
    Directory of C:\Users\YzOrg
     
    11/24/2010  09:50 AM                 6 demo20101124.log
                   1 File(s)              6 bytes
                   0 Dir(s)  199,100,379,136 bytes free
     
    C:\Users\YzOrg>set /?
    Displays, sets, or removes cmd.exe environment variables.
     
    SET [variable=[string]]
    ...<SNIP>
     
    Use %~dp0 to get the full path of the current batch file.  %0 is the scriptname argument, '~dp' are modifiers to get the drive and path of that argument, %~dp0. 
     
    Interesting FOR commands in cmd.exe :
    FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
    FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
    FOR /F ["options"] %variable IN ('command') DO command [command-parameters]
     
    Rule: always turn off 'echo' in batch files using this first line:
    @if not defined _echo echo off
    Use 'set _echo=1' before calling the script to debug it (it will echo every command)
     
    References: set /?, call /?, for /?, setlocal /?

    2

    View comments

  7. iPod

    I recently bought a 4th gen iPod and man do I love it. Don't have to pay a data plan, and with a few bucks for good software can really make use of the GB of
    flash storage and the fat bandwidth over WiFi. Exactly what my old Windows Mobile 6.X phone sucked at. Great battery, great podcast playback (2x play, remembers where I left off, etc.).
    The only thing I was missing was Podcast subscription (on device, no iTunes on Windows please) and automatic WiFi sync for podcasts. There's an app ...

    iOS Apps

    DownCast: $0.99 app to sync podcasts over WiFi. My Features: Multitasking (background play), subscribe to podcasts, sync to iPod via WiFi, 2x speed, good jump buttons (back 30, back 15, forward 30, forward 2:00). Bonus features: can sort a playlist by podcast name instead of date, so can see the three 'good'
    weekly podcasts first (instead of listening to the daily podcasts first, which tend to be filler.  I also found out too late that it can import an OPML from a URL (I was adding them one at a time, good time saver.)

    Microsoft OneNote: free. My Features: (sync to Live/SkyDrive/OfficeLive, whatever they're calling it today). Love that it syncs my notes to all my devices + web.
    So I can start gathering notes and thoughts for a blog post on the laptop, research it on the desktop, and pull it up on my pocket device (iPod in my case) to solicit feedback from a co-worker.
    Leave it to Apple to help make OneNote useful enough to finally start using it instead of email.

    StackOverflow + Google

    The work Google is doing to reduce spammers and content farms seems to be working - SO rank has recently improved dramatically in my recent programming searches.

    For similar technology searches a few weeks ago I was getting spam/content farms of stackoverflow.com duplicated content for most of the results, with SO 3rd or 4th (obviously the content farms were gaming the SEO ranking).  Not scientific by any stretch, but getting better.
    0

    Add a comment

  8. JSON / Diagnostics

    Pretty Print JSON via JayRock
    New JSON library for .NET, JayRock

    WPF and INotifyPropertyChanged

    http://code.google.com/p/notifypropertyweaver/
    http://stackoverflow.com/questions/671968/retrieving-property-name-from-lambda-expression
    http://msdn.microsoft.com/en-us/library/ms229614.aspx
    http://caliburn.codeplex.com/wikipage?title=Asynchronous%20Actions
    http://stackoverflow.com/questions/834632/bind-any-xml-document-to-wpf-treeview

    IoC / Autofac

    Nicholas Blumhardt: AutoFac and object Lifetime (summary: mind your 'unit of work' pattern)
    0

    Add a comment

  9. Microsoft's devs and testers write great little specialized utilities but far too often they never see the light of day. They write it for their team, and sometimes have time to post it internally, but all too often they're too busy to publish it outside the company.

    This is one of those gems, and fortunately it is public.

    My Scenario

    I had a NY to FL file copy operation that was taking about 10 minutes with xcopy and pre-Win7 robocopy. The files weren't that big, but lots of small files, and one-at-a-time file copy performed horribly. Win7 introduced the /MT argument to allow 'multiple threads' to copy file simultaneously, which is exactly what I needed. But I'm not using Win7 (yet). Even better, the Win7 robocopy.exe won't run on older versions of Windows (both properly licensed). Nice. RichCopy to the rescue.

    RichCopy is a graphical application for Windows and will run on Windows XP and Windows Server 2003. It also has (cryptic) command-line options for all of the various copy options like filter by name, filter by date, and copy file attribute. RichCopy really shines when copying huge files, but if you seriously raise the threading you can also get a boost when copying lots of small files (like source code files or in this case PowerShell scripts).

    I've used robocopy a lot over the years, so while its options are cryptic I found RichCopy's options even worse. To save myself time I wanted to document the options I'm using.

    RichCopy.exe source destination /TD 64 /TS 32 /SC 64 /FEF *.7z

    Get it here. http://blogs.technet.com/ken/

    Gotchas / Caveats

    1. I was looking for a command-line tool, and this is a windows application. You can wait on the windows application (which does exit properly when given correct command-line options) using PowerShell's 'Start-Process -Wait RichCopy.exe' or in cmd.exe 'start /wait "" RichCopy.exe'.
    2. I wasn't getting any command-line output when passing bad command-line arguments, and while it has logging options I didn't get them to work after a couple of tries.
    3. RichCopy comes with a chm (compiled help) which explains all the options. But I get the feeling the author's first spoken language isn't English because the wording is clumsy. (Not that my blog writing is any good, ahem.)

    Sample PowerShell

    I was using RichCopy to copy my PowerShell profile to my DEV servers. It includes code to call robocopy (if found via Get-Command) and if not found fall back to RichCopy (XP / Server 2003 only). If planning to compare the tools a good addition would be to make this a script parameter instead. The code is available at PoshCode: PoshCode 2468

    1

    View comments

  10. After 9 months of use, SB Studio left 670MB of temporary files.  Thanks StreamBase!  In all fairness this might have something to do with SB Studio being built in/with Eclipse.  They all start with .sb, which makes me feel better about casting blame.


    Friendly poking aside, SB is critical to my current role.  It's been a fun ride learning event-based programming, time-window aggregates, and getting back into Java.  Eclipse perspectives need to be brought to Visual Studio.

    Also an old but good article which makes the case for CEP.  
    0

    Add a comment

Blog Archive
Contributors
Contributors
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.