PowerShell is just awesome

I’ve known for a while that PowerShell is useful but I never got myself to take that two hours to learn to actually use it. Today I did just that. And it’s simply awesome!

Tasks like reading a remote RSS feed can be done with just few lines of code. However the cool part is that these small programs (or cmdlets) can be easily used together.

Maybe the most powerful feature of PowerShell is it’s ability to pipe any collection of objects to an other program as they are. No need for parsing string streams. I would really like to see a portable version of that kind of piping shell — that works on *nix as well as in Windows!

Here’s my test application. It takes an URL for RSS feed as an argument and will return items from it.

param ([string]$url)
$wc = New-Object Net.WebClient
[xml]$resp = $wc.DownloadString($url)
$resp.rss.channel.item

Then you can use it like:

.\rssreader.ps1 http://www.jhh.me/blog/feed/

The raw output from this command to the console is quite detailed since it includes everything:

console

You can pipe the results to Out-GridView to get more graphical presentation of it:

.\rssreader.ps1 http://www.jhh.me/blog/feed/|Out-GridView

Notice that the table is formatted nicely. That’s because the piping is done with real objects instead of outdated string streams.

gridview

Maybe one reason why PowerShell takes time to learn is that it has quite strict security model by default. For example you cannot just write and run that example on your system without signing it or changing default security model. Read more about it from an article Running Scripts at TechNet.

PS: I bought also an ebook of O’Reilly’s PowerShell for Developers. I think it’s much softer crash course to PowerShell than most online articles.

Fork me on GitHub
Posted in Programming, Software, System Administration, Web development & design | Leave a comment

Setting up HTTP server on Windows with Node.js

Some years ago I dreamed about running JavaScript applications on Windows systems as easy as it was on Linux. It seems the future is here.

Today it’s really easy to setup Node.js and install NPM apps on Windows systems. Here’s a guide how to setup a HTTP server. No programming skills required! (Basically it’s the same process for any OS!)

  1. First you must install NodeJS.
  2. Open the command prompt to run following commands.
    • Windows 7: Open Start and write cmd into the search and press enter.
    • Windows XP: Open Start and select Run and write cmd and press enter.
  3. Run this command to install a HTTP server: npm install http-server -g
  4. And start the HTTP server: http-server /path/to/docroot with a path to the folder you want to share. Your folder must have some files before it works.
  5. Now just open http://localhost:8080/ in your browser.

I wonder if there is a GUI for NodeJS/NPM yet. However I don’t think running some simple commands is so hard thing to do.

NPM isn’t just for installing HTTP servers. There’s a lot of apps and libraries available and ready to be installed with APT-like interface. You can even publish your own software there!

Posted in Programming, Software, Web development & design | Tagged , , , , , , , , | Leave a comment

HBO started at Finland

This month great things happened. HBO launched HBONordic.com for customers at Finland.

That’s great improvement because we haven’t been able to watch these series instantly (not legally at least) before now — without waiting months or years for a DVD release or until our national TV stations bought those series — if they had enough money or interest to do so. Now we can pay directly to the source and watch them (almost) instantly — HBO is promising to publish their own series within 24 hours of US premiere.

We got Netflix some months ago, too, and I also have account there. However biggest problem with Finnish Netflix is that there isn’t much new content available and most of it is really old. Most content is so old that even our national TV stations have newer content. Of course that’s also a good thing — some of those are hard to find from elsewhere. (And yes, I know about the trick to watch US Netflix here but I don’t count it nor support doing that.)

Last week I got my invite to HBO. Of course there isn’t as much content as Netflix has but there certainly is newer content to watch — especially HBO’s own series.

Here’s a list of content available at HBO Nordic. Please note that it might have some mistakes because I made it with automated scripts.

HBO Nordic Series

HBO Nordic Movies

Posted in Movies, Series | Tagged , | Leave a comment

NKO 2012 — two days left!

I am participating in NKO once more this year.

We have a four member team and we’re planning to make a website with some hopefully interesting features.

I hope we get the first version of the site up before Saturday 8:00 UTC so we can get feedback from users before the competition ends Monday 0:00 UTC.

I took Monday free from the military so I can fully invest in the competition and recover from it.

Posted in Programming, Software, Web development & design | Leave a comment

I’m In The Army Now

So I have been in the Finnish Defence Forces in the basic training as a rookie a month now.

For you international readers I must state that it’s mandatory civil service in Finland from 6 to 12 months depending on type of training.

So far it’s been (almost) fun and we have more free time than I thought. However it’s obvious that I don’t have as much of it as I had in civil job(s) — don’t be alarmed if it will take time to reply to issues.

Posted in Programming | Leave a comment

PHP’s json_decode behaving badly

Funny thing with PHP’s json_decode…

$ php
<?php echo var_export(json_decode("true ", true), true) ?>
NULL

(Press ctrl-d after you write “?>”.)

The same using node.js:

$ node
> JSON.parse("true ")
true
> exit

Of course it could be argued that it’s a good feature to not ignore leading white spaces.

However most text editors are going to write at least one line break at the end of files — and that kind of line break was the problem of my bug at the moment.

Original available as gist #2353872.

Posted in Programming, Web development & design | Leave a comment

CSS Anti Spam Trick with content attribute

Some time ago I stumbled upon a simple way to add email addresses on web pages – that are not easy to read by bots – using only CSS.

First you add new class .email with your domain into your style sheet:

.email:after {
content:attr(title) "@example.com";
}

..then use it inside HTML code like this:

<span class="email" title="info"></span>

First part of the email address is written inside a title attribute and the content should be left empty.

Resulting HTML code looks like this:

Update: Look also CSS support for content. (It’s not supported in IE7 and older.)

Posted in Programming, Web development & design | Tagged , , , | Leave a comment

Configuring Bitlbee with everything

This is a guide how to setup irssi and Bitlbee with support for Skype, Google IM, Facebook, Twitter, Jabber, and SMS for Android-based mobile phones.

It has been few days since I actually did this so I might not remember everything right. Feel free to comment if something is out of order.

Compiling Bitlbee

To make things simpler I compiled and installed Bitlbee on my own shell account. That way I’ll get all bleeding-edge features. It’s also quite likely that Bitlbee has to be upgraded in case if the service APIs are changed (like Twitter or Facebook).

Download bitlbee-3.0.5.tar.gz or newer:

wget http://get.bitlbee.org/src/bitlbee-3.0.5.tar.gz

…then unpack it:

zcat bitlbee-3.0.5.tar.gz|tar xf -

…and compile it:

cd bitlbee-3.0.5
./configure –prefix=$HOME/opt/bitlbee –skype=1 –ssl=gnutls
make
make install

You should also install default configurations on the first time with this command (Note! It will install over any changes you might have made under opt/bitlbee!):

make install-etc

Finally you might need to add $HOME/opt/bitlbee/bin and $HOME/opt/bitlbee/sbin in your path to make bitlbee and skyped commands working.

For Bash you can do it by adding these lines to .bashrc:

export PATH=”$PATH:$HOME/opt/bitlbee/sbin:$HOME/opt/bitlbee/bin”

Configuring Bitlbee

Bitlbee has to be configured before first start.

First I will make my own configuration directory for Bitlbee:

mkdir etc/bitlbee
cd etc/bitlbee

Next copy the default configuration file from opt for bitlbee:

cp $HOME/opt/bitlbee/etc/bitlbee/bitlbee.conf .
chmod 600 bitlbee.conf

Modify from the configuration AuthMode as Registered unless you want to setup a public Bitlbee. You should also change AuthPassword and OperPassword.

Next create a text file named start-bitlbee.sh with these lines:

#!/bin/sh -x
bitlbee -n -v -P $HOME/opt/bitlbee/var/run/bitlbee.pid \
-c $HOME/etc/bitlbee/bitlbee.conf \
-d $HOME/opt/bitlbee/var/bitlbee

..and change permissions:

chmod 700 start-bitlbee.sh

Please note: you should configure Skype before starting Bitlbee first time.

When ready you can start bitlbee by running it in screen:

screen -S bitlbee ./start-bitlbee.sh

I am running bitlbee in screen since it’s easier to read debug messages and I did read about some Skype related bugs that didn’t exist by running it that way — but I’m not sure if those are already fixed.

Setting up Google IM

I followed these instructions when configuring my Google Apps accounts to Bitlbee. However I couldn’t make it work precisely as advised there. I used oauth instead and it’s much more secure anyway.

account add jabber jhh@sendanor.com
account jabber set tag g
account g set oauth on
account g set ssl true
account g set server talk.google.com
account g set port 5223
account g on

Setting up Skype

Skype is the most tricky to get working with Bitlbee — mostly because you actually need to run Skype as GUI application (on shell server!). For that you will need a VNC server. I am using tightvncserver since it doesn’t have much dependencies and was easy to install on my shell server.

Good news is that skype-plugin has been in Bitlbee since version 3.0.4.

First I installed Skype for Linux from skype.com. That was quite easy to do on my own shell server but required root access.

Then I followed these instructions to configure it.

Update: If you need to receive files, please note that Skype API doesn’t support accepting them. However you can enable auto-accept feature in Skype GUI.

Setting up Twitter

For Twitter I followed HowtoTwitter at wiki.bitlbee.org. However you don’t need to use your password since Twitter supports oauth, too.

Just configure it by this command:

account add twitter yourusername

..and follow the link to authorize your access.

Setting up Facebook

Facebook’s jabber support isn’t very good. Unlike with Twitter you cannot see anything else but private messages so it’s not as useful as Twitter. As usual I followed
HowtoFacebook at Bitlbee wiki.

GTalkSMS

GTalkSMS is an Android app that allows you to send/receive SMS and control your Android smartphone using Gtalk/XMPP. Since Bitlbee supports XMPP it also means you can control your smartphone with irssi!

Guides to setup GTalkSMS are available at GtalkSMS’s wiki on pages Setup and HowToSetUp.

Setting it up was quite easy but there seems to be some kind of bug when configuring settings for GTalk. First it didn’t work even when I had all settings right but then it started working after I cleared data for GTalkSMS and configured it again. For the second time I didn’t change anything except what needed. For example, I didn’t write “@” characters again since I suspected there might be some kind of character set problem.

Posted in Other things, Software | Tagged , , , , , , , , | Leave a comment

Setting up Google Apps for domain -account on Bitlbee 3.0.5

I configured today Bitlbee to use Skype, Facebook, Twitter and Google Apps.

Skype may have been the most laborious of these — it has to be ran using VNC server when on a remote server — but Google Apps took more time for me since I didn’t find updated documentation for it.

It’s configured like this on Bitlbee 3.0.5:

account add jabber jhh@sendanor.com
account jabber set tag g
account g set oauth on
account g set ssl true
account g set server talk.google.com
account g set port 5223
account g on

After this you just need to follow the link Bitlbee will provide for you to authenticate using oauth.

Posted in Programming | Leave a comment

Blogging about Freeciv and longturn games

This week I started blogging about Freeciv and longturn games at freecivbook.com.

It’s actually a blog for my work-in-progress book about Freeciv. If it will be successful, I might really write a book about Freeciv. Until then I’ll write articles one at the time and publish them there.

Posted in Games | Leave a comment