Skip to main content

Posts

Concatenate lines in a file into a single line with PowerShell

Assuming you have a input file in.txt with following lines:a b cand you'd like to concatenate these 3 lines into a single line to a file out.txt i.e.abcYou can use the following PowerShell command:-join (cat in.txt) | out-file out.txtBasically, the cat in.txt is executed first and returned the content of in.txt as an array of strings. The -join cmdlet then joins the lines together into a single line, which is then piped (|) into the out-file cmdlet to produce the out.txt file.
Recent posts

Replace xscreensaver in CrunchBang Linux 10 "Startler"

Deep down in my heart I am a minimalist and to me CrunchBang Linux has the right balance between minimalism and usefulness. However, one thing I've always struggled with it is the choice of xscreensaver for the simple lock screen task because it also does monitor power management, which has to be turned off to avoid conflict with xfce4 power manager.Last week I finally decided to bite the bullet and replaced it with much simpler slock and here's how I did it.Step 1 - Remove xscreensaver and install the screen locker of your choiceTo remove xscreensaver simply:sudo apt-get purge xscreensaverNext, you'll need to install xautolock to lock screen automatically after certain idle time (mine's set to 1 minute):sudo apt-get install xautolockNow you have to choose a screen locker. I use slock, which is probably the simplest screen lock ever because all you get is a blank lock screen. There's also xtrlock, which is installed by apt automatically when I installed xautolock a…

Enable PowerShell Remoting

On the remote machine, start a Administrator PowerShell session and run following commands:Enable-PSRemoting cd wsman: cd localhost\client set-item trustedhosts *Just answer "Y" for any prompt.To start a remote Powershell session, on your local PowerShell session, enter:Enter-PSSession <the-remote-machine-hostname&gtFor some reason, Enter-PSSession can't seems to resolve DNS aliases (CNAME records) and you'll get the following error if you used it instead of the hostname.Enter-PSSession : Connecting to remote server failed with the following error message : WinRM cannot process the request. The following error occured while using Kerberos authentication: The network path was not found.

Running CrunchBang Linux 10 "Statler" on HP mini 1000

I was a big Ubuntu fan until they decided to use Unity in netbook remix and moved windows border icons to the left. I then switched to LinuxMint, it was alright but I'm a Chrome user and I hate the fact that they won't let you remove firefox (the package manager forces you to install "abrowser", which is still firefox but with brand removed).Now CrunchBang Linux is my new favorite Linux distro. I hesitated before puting it on my HP mini 1000 netbook because the latest version "Statler" is based on debian, which is famous for being "Pure Open Source" and hence lack of proprietary drivers. However, I was totally wrong, nearly all hardware worked out of the box for me except for the usual wireless driver, network port and bluetooth.WirelessTo be fair the b43 driver did work but it was fairly unstable and disconnects randomly. The solution turns out is pretty simple, all you have to do is to enter:options b43 pio=1 qos=0in the following file:/etc/mod…

AOP with Enterprise Library Policy Injection Block

I used to think aspect oriented programming (AOP) is not a very useful idea because quite often it only saves few keystrokes but requires a massive configuration file. I only came to realise the true value of AOP recently when we have to convert 4+ million lines of legacy COBOL code to .NET with Microfocus’ Visual COBOL compiler. Manually adding exception handling and logging code to these existing COBOL subroutines will not only take a lot of time but also makes code merging task much harder later. I started experimenting with the policy injection block in the Enterprise Library to see if it will make this job simpler. I tried to google for AOP and Enterprise Library tutorials but I found most tutorials on the web are either old (most were done using Enterprise Library 3) or over-complicated. Especially many of them use the Enterprise Library Logging Block to demonstrate the policy injection concept, which requires lots of configurations itself.The policy injection in Enterprise Libr…

COBOL Tutorial 00300 – Edited Fields

As I have mentioned in the last tutorial, you use edited fields in COBOL to format data fields into human-readable display strings. Let’s start with a numeric field:01 NUMERIC-FIELD PIC 999999V99.and some COBOL code that set and display the field value:MOVE 1234.5 TO NUMERIC-FIELD. DISPLAY NUMERIC-FIELD: ' NUMERIC-FIELD.As we’ve demonstrated in the previous tutorial, unused digits are padded with ugly zeros:NUMERIC-FIELD: 001234.50Let me put my C# programmer hat on again (apologies to Java, ruby, python, C/C++, assembly and many other programmers who don’t like C#), when we have to format a variable for display, we often use the string.Format method with a formatting string containing special formatting characters, which is “0,0.00” in the following example:// returns 1,234.50 string.Format("{0:0,0.00}", 1234.5)Now let’s come back to COBOL, an edited field is basically a normal COBOL data field with a formatting string in the picture clause instead of the “A”, “X” or “9”…

COBOL Tutorial 000200 – Data Fields

Variables are called Fields in COBOL and definitions of variables are declared in the Picture clause (can be abbreviated with PIC). Why is it called the Picture Clause? According to the book Sams Teach Yourself COBOL in 24 Hours, this is because it “paints a picture of how a field looks by defining every details and characteristic of the field”, still doesn’t quite make sense to me but anyway.Let’s start by talking about what data fields (variables) look like in C#. When we declare a variable, the first thing we have to think about is the data type, which determines what kind of data can it hold. Normally we wouldn’t worry about the number of digits or length of the string unless we know their values can get ridiculously large or long.int integerVariable = 12345678; string stringVariable = "abcd1234"; decimal decimalVariable = 1234.5678m;In a COBOL world, however, the size does matter and you have to specify both the type and the size for each data field at the same time wit…