Numbing the pain of VBScript with a generic logging-class

October 18th, 2011 FighterHayabusa No comments

VBScript is a pain the ass. However when working on Windows I’ve found it useful plenty of times since it’s the only scripting language supported out of the box by most Windows-flavors (although that’s changed now with PowerShell I suppose). There’s also the whole VBA-thing which crosses over into VBScript-territory in various applications. QlikView for example uses VBScript as an internal scripting language for macros and exposes a VBA-esque API for that purpose.

Anyway, the other day at work while hacking away at a humongous VBScript/VBA-macro I got tired of how much debugging my 600+ lines of VBScript-code sucked (mainly because of QlikView’s useless debugger) and threw together a simple generic logging-class that I thought I’d share. So here you go:

Class Logger

Private mLogFile
Private EFSO
Private EFP
Private mIsEnabled

Private Sub Class_Initialize()
'Do nothing
End Sub

Private Sub Class_Terminate()
If IsObject(EFP) AND TypeName(EFP) = "TextStream" Then
EFP.Close
End If
Set EFP = Nothing
Set EFSO = Nothing
End Sub

Public Default Function Init(pLogFile)
mLogFile = pLogFile
mIsEnabled = True
Call InitFileObjects
Set Init = Me
End Function

Private Sub InitFileObjects
If IsObject(EFP) AND TypeName(EFP) = "TextStream" Then
EFP.Close
End If
Set EFSO = CreateObject("Scripting.FileSystemObject")
Set EFP = EFSO.OpenTextFile(mLogFile, 8, True)
End Sub

Public Property Get logFile
logFile = mLogFile
End Property

Public Property Let logFile(pLogFile)
mLogFile = pLogFile
Call InitFileObjects
End Property

Public Property Get IsEnabled
IsEnabled = mIsEnabled
End Property

Public Property Let IsEnabled(pIsEnabled)
mIsEnabled = pIsEnabled
End Property

Public Sub doLog(pMessage)
If (mIsEnabled = True) Then
EFP.WriteLine(pMessage)
End If
End Sub

End Class

Not the hottest piece of code you’ll ever see but maybe somebody besides me will find it useful.

Simple iTunes “what’s playing?”-server with AppleScript and netcat

May 28th, 2011 FighterHayabusa No comments

I run a computer setup at home where I have a Linux-PC and a MacMini sharing a screen, keyboard, mouse and speakers through a KVM-switch. This particular switch has the neat feature that you can switch over everything except the speakers if you like. So I can be rocking the iTunes on the Mac while I’m burning through some code in Eclipse on the Linux-PC for example. Pretty useful since I keep almost all my digital music in iTunes on the Mac and do most of my coding and hardcore geeking on the Linux-box. The only problem is that if I wanna check what’s playing currently I have to switch the screen over to the Mac to see the track playing in iTunes. Well, I made a quick hack to solve this “problem”.

Netcat is a really useful tool for testing various network related things and it can also be used to set up a simple client-server connection. So I thought I could use it to push information from the Mac over to the Linux-PC without too much hassle, and I was correct. Combined with some AppleScript that reads the information about the song playing from iTunes I quickly had a “server” that would answer client-requests for this information. Here’s the code:

AppleScript (compiled and saved as itunescurrent.scpt):
tell application "iTunes"
try
if not (exists current track) then return
set this_artist to (get artist of current track)
set this_track to (get name of current track)
set this_album to (get album of current track)
end try
end tell
try
set track_info to this_artist & " - " & this_track & " (" & this_album & ")"
return track_info
on error err
display dialog err
end try

Server-script using netcat (saved as itunescurrent-server.sh):
#!/bin/bash
SERVERPORT=4321
while [ 1 ]; do
osascript itunescurrent.scpt | nc -l $SERVERPORT
done
exit 0

So I put those two files in the same directory, navigated there in a command prompt window and executed the server-script. What the server does then is simply hang in an infinite loop waiting for a client to request information from it.

The script running as the client is just as simple:

#!/bin/bash
SERVERIP=192.168.1.108
SERVERPORT=4321
CURRENTTRACK=""
ITUNESINFO=""
while [ 1 ]; do
ITUNESINFO=`nc $SERVERIP $SERVERPORT`
if [ "$ITUNESINFO" != "$CURRENTTRACK" ] ; then
clear
CURRENTTRACK=$ITUNESINFO
echo $CURRENTTRACK
fi
sleep 5
done
exit 0

I think it’s pretty self-explanatory.

So now I can read what’s playing on my Mac in a terminal window on my Linux-PC instead of having to waste precious seconds switching back and forth and checking iTunes. Problem solved! And anyone who wants to can grab the code from the Downloads-page.

Vilken nytta gjorde FRA i lördags?

December 15th, 2010 FighterHayabusa No comments

Jag tycker att det är intressant att mitt i allt detta ståhej om den klantiga bombmannen i Stockholm är det ingen som ifrågasätter varför detta dåd inte kunde förutspås och förhindras av övervakande instanser som FRA eller Säpo? Var det inte just sånt här som FRAs snokande i hela Sveriges befolknings privatliv skulle förhindra? Är inte detta ett utmärkt tillfälle att ta upp debatten igen, utvärdera och (förhoppningsvis) tänka om? Det enda FRA verkar göra bra är att leverera privata uppgifter om oss till USA och det var väl ändå inte det som sades vara dess uppgift va?

Inte heller är det speciellt många som lägger ihop ett och ett och listar ut att en stor anledning till att Sverige nu är ett lockande mål för de av media kallade islamistiska extremisterna är att den svenska regeringen sitter i fickan på USA – det USA som hejdlöst krigar i åtskilliga muslimska nationer och skänker stöd i miljardklassen till Israel – och tar order från Vita Huset och amerikanska ekonomiska intressen istället för att tjäna befolkningen i landet de påstås regera i.

Det finns inga ursäkter eller förlåtande omständigheter för terrordåd och de begås enbart av fullständiga galningar men det är ändå hög tid att fler börjar följa sambanden och pekar ett anklagande finger på nickedockorna och förrädarna i vår regering och riksdag, för de är inte oskyldiga de heller. De är i alla fall oändligt mycket mer skyldiga än alla de fullständigt oskyldiga muslimer boendes i Sverige som av mindre vettiga personer nu kommer att betraktas som potentiella terrorister och beskyllas för både det ena och det andra.

Låt er inte sköljas med i den rasistiska och islamofobiska vågen som spolar igenom Sverige. Dra inte alla över en kam. Och låt inte kräken som försöker montera ner demokratin inifrån vinna poäng på det här.

To all citizens of the EU, sign this now!

October 7th, 2010 FighterHayabusa No comments

Say NO to internet censorship and pointless blocking of child pornography websites and at the same time YES to striking at child pornography in a way that actually works!

Deletion, not blocking!

Go here now and sign the petition: http://www.deletion-not-blocking.eu/sign.html

It’s Bacon Day! Meal three: Dinner

September 4th, 2010 FighterHayabusa No comments

For dinner I decided on a bacon burger, always a delicious choice. But for extra deliciousness I slapped on an extra meat patty, cheese and some fried red onions.

Once again, bacon frying

Once again, bacon frying

Frying the red onions

Frying the red onions

Meat! Gooood!

Meat! Gooood!

The finished bacon burger in all its glory

The finished bacon burger in all its glory

It’s Bacon Day! Meal two: Lunch

September 4th, 2010 FighterHayabusa No comments

The bacon feast continues. For lunch I made a nice chicken salad with cherry tomatoes, cucumber, corn, maché salad, grilled chicken, mushrooms and, of course, bacon.

Lovely bacon frying

Lovely bacon frying

The salad before adding the bacon

The salad before adding the bacon

Bacon added

Bacon added

Nom nom nom

Nom nom nom

Praise the divine bacon! See y’all back for dinner!

Categories: Posts in English Tags: , , ,

It’s Bacon Day! Meal one: Breakfast

September 4th, 2010 FighterHayabusa No comments

To celebrate that’s it’s Bacon Day today I’ve decided to include bacon in all of my meals of the day. First out: breakfast!

For breakfast my girlfriend requested pancakes, so pancakes it is but I decided to stuff mine with cheese, arugula and bacon.

Check out the pictures!

Making the pancakes

Making the pancakes

The delicious bacon

The delicious bacon

Soon the feast will be ready...

Soon the feast will be ready...

Bacon stuffed pancakes, ready to eat!

Bacon stuffed pancakes, ready to eat!

Eating the pancakes

Eating the pancakes

And yes, it was absolutely delicious! See you in a couple of hours for lunch. With bacon!

The most boring video you’ll ever see

August 2nd, 2010 FighterHayabusa 1 comment

Don’t say I didn’t warn you… ;-)

To anyone who actually gives a hoot, that’s my HTC Hero receiving the officially sanctioned Eclair-update from HTC (rather than the hacked HTC Legend Eclair ROM I’ve been running the past couple of months).

Time for Android to step up its game

July 21st, 2010 FighterHayabusa No comments

The past couple of weeks I’ve been playing with mobile apps development, both for Android and for iOS (meaning iPhone and iPad in layman’s terms). Being an open source kinda guy and very familiar with Java I immediately felt very comfortable with the Android SDK and the platform as a whole. It really is a great platform and very viable for creating great apps and experiences for mobile devices. However, there are a couple of key issues that I believe need to be fixed in order to push Android to the next level.android-robot-logo

First and foremost, paid apps are still not available everywhere. Only users in a few select countries can download apps from Android Market that cost money and, even worse, developers in even fewer countries can publish non-free apps for people to buy. As a mere users there are ways around this but if you’re – like me – a Swedish developer there’s no way to get paid for your efforts. This is a really big deal since developers outside of the nine supported merchant countries also need to eat and pay the bills or whatever it is you use money for. Sure, one might claim that true hardcore developers will develop awesome apps anyway and give them away on Android Market because digital creativity is in our nature and this is true to some extent. But at the end of the day money is one of the best incentives out there and the fact that many potential Android developers can’t charge for their apps is most surely causing a lot of app-awesomeness from happening and keeping the platform from experiencing the kind of “gold-rush” that iOS is having.  It may even be driving some developers to the iOS-platform instead since they might reckon that if they can’t paid why should they bother with the platform anyway?

I don’t see what the frackin’ hold-up is here really. So Google, get off your asses and make this happen sooner than later. Market needs to have paid apps and developers getting paid everywhere, OK?

Another thing that is painfully obvious when you look at the variety of Android devices out there is that the hardware companies that sell them, companies like HTC, SonyEricsson and Samsung, care only about selling new devices. They have very little interest in delivering software updates for devices that customers have already bought. I mean, it took HTC a full year to push out an OS-upgrade for the HTC Hero and SonyEricsson is at this moment selling Android 1.6 devices with the plan to update them to 2.1 around New Year. Meanwhile, FroYo (Android 2.2) devices are starting to hit the market and the specs for 3.0 are already out there.

I fully understand that it may not be easy for these companies that are primarily manufacturers of hardware to wrap their business models and brains around the fact that these days, with mobile phones becoming more and more like “real” computers, software matters more than hardware. A mobile phone will become obsolete a lot faster due to an old OS than due to year-old hardware. So something needs to be done about this. HTC and others need to take care of their customers and push out the updates a lot quicker because not everybody wants to (or can) buy a new $500 mobile phone every three months just to get the latest software. Maybe Google should set up some sort of centralized repository that the makers of Android phones could use to make sure they’re all in sync with each other and with what’s new? I don’t know, but something should be done to keep the platform from fragmenting any further.

And finally one other thing that I think can be a real game-changer is Flash-support. Yes, there is Flash-support in FroYo, I haven’t experienced it first-hand myself though so I don’t know how well it works. But my point here is that since Apple is taking a serious stand against Flash on devices running iOS there is a chance for Android (and Adobe naturally) to shine here. Make Flash work flawlessly on all contemporary Android devices and you will have a feature on the platform that the main competition can’t and will not match, which naturally is a great advantage.

These are the major points that bother me at the moment and I believe them all to be more or less critical for the growth of Android. I want to underline here though that although there are flaws – every platform has them – I believe a great deal in Android and will continue to submerge myself in the platform with great joy.

So Google and everybody else involved, time to step it up a notch OK? I’ll be watching you ;-)

Section 3.3.1 and Steve Jobs’ “Thoughts on Flash”

May 1st, 2010 FighterHayabusa 4 comments

No one that follows tech-news can possibly have missed that Apple have whipped up a shitstorm of sorts with it’s changes in Section 3.3.1 of the iPhone Developer Program License Agreement resulting in the prohibition of the use of third-party tools for developing iPhone apps. This is what Section 3.3.1 used to look like:

3.3.1 — Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs.

And this is what Section 3.3.1 looks like now:

3.3.1 — Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs. Applications must be originally written in Objective-C, C, C++, or JavaScript as executed by the iPhone OS WebKit engine, and only code written in C, C++, and Objective-C may compile and directly link against the Documented APIs (e.g., Applications that link to Documented APIs through an intermediary translation or compatibility layer or tool are prohibited).

Clearly this is a move that Apple has made in order to even further increase their control and hold over the development done for their mobile platform and shut out any and all apps that are not developed in a manner blessed by Apple. This includes 3D-games developed with Unity3D, all apps that could be built with Flash CS5 and many more.

As a developer I take great offense to this and I consider it to be a real dick-move by Apple. Further, I believe it to be a move that clearly demonstrates that the people making the decisions have completely lost any understanding of what it is to be a software developer and how we developers think and operate.

Some people seem to believe that it’s a good thing that all iPhone OS development is being streamlined into a single set of tools all under the control of the platform-owner (i.e. Apple). Anyone believing this doesn’t get it either and is clearly not a developer themselves. Let me explain.

Developers don’t like being told exactly how to operate and what roads to travel on when on the path to solving a problem or task. There’s always multiple solutions to any given software development issue. There is no such thing as the ultimate tool-set or the IDE to end all IDEs. This is why we like having the freedom to chose what tools to use and how to use them to build software. By putting restrictions on what tools are “allowed” for iPhone OS development Apple is pulling a move with multiple bad consequences.

Firstly, it pisses developers off. Like I said, we don’t like being told how to work and think. In fact, there’s no group of creative people that enjoy that. Can you imagine if MOMA said to all artists that if you want your art displayed in our facilities you have to buy all your supplies in a specific store and hold your brush/chisel/whatever in a specific way? Same thing here. And yes, I’m saying that software development in many ways is an artform. If I want to use a third-party set of tools or some other exotic methods not previously imagined by Apple in order to create an awesome iPhone-app I should be able to do that. If the way my brain works makes this, to me, the most natural path of development, why restrict me and forbid me to do it? It’s ludicrous and any real developer will tell you the same thing.

Sure, I can get behind the idea that Apple want to set up some rules for what apps are allowed into their AppStore (even if the AppStore acceptance process is utterly broken…). Telling developers what to build is sort of OK, but telling them how to build is definitely not OK. It’s bullshit, plain and simple.

Secondly, this dick-move of Apples is ruining business for the companies/people developing these third-party tools as well. Sure, Apple has no responsibility to ensure the business of any other company but this is none the less a really bad side-effect of the changes to Section 3.3.1. People may lose their jobs and companies may possibly go out of business thanks to a really moronic and completely unnecessary change in the iPhone Developer Program License Agreement

The main target here, however a company not very likely to go out of business, is obviously Adobe and their product Flash which currently dominates when it comes to video and other multimedia content on the web. The changes to Section 3.3.1 followed swiftly after Adobe announced that the next version of Adobe Creative Suite would include tools that enabled Flash-developers to build Flash-apps that would run on the iPhone and iPad. That means that developers could use CS5 to create apps that were truly multi-platform and with very little hassle. They wouldn’t have to maintain different simultaneous versions for multiple devices, just one version that they could then deploy on iPhone OS, Android or whatever OS they wanted. One version of the app but multiple markets for it to exist in, which consequently means more business for the developers and, once again, all without having to deal with the mess of having multiple versions of the code. Now imagine how happy that would’ve made all of the world’s Flash-developers! Naturally, Apple couldn’t have that.

So that’s the third reason Section 3.3.1 bites, it causes unnecessary problems for developers that don’t want their apps to be exclusive to the iPhone OS, and what developer really wants that? Even if Apple may have the goal that 100% of the smartphones of the world are iPhones, it is never going to be a reality. Naturally software developers want a shot at pushing their apps and consequently make money in more markets than one, and, if at all possible, with minimal hassle. Clearly that’s not something that Apple wants.

What Apple wants for all the apps running on the iPhone OS is for them to be exclusive for their platform. They don’t want multi-platform development anywhere near their products and this was made even more clear by the open letter from Steve Jobs entitled “Thoughts on Flash” that was published on Apples website a couple of days ago.

In his letter The Steve lists six reasons why Apple hates Flash and wants it to die rather than run on the iPhone OS. Some of these reasons are actually somewhat valid, however most of them are complete and utter hypocritical nonsense. Let’s run through them quickly:

Reason one: Adobe Flash is 100% proprietary and Apple is a supporter of the “open web” having created WebKit and pushing HTML5, CSS, JavaScript and other open standards.
Hello pot, calling the kettle black much? This just makes me laugh. Apple is one of the most proprietary companies in the tech-industry. Their levels of secrecy and unwillingness to give away so much as an ounce of their secret sauces is legendary. Just because you’ve successfully pushed one open source project it doesn’t make you Richard M. Stallman. Get off your high horse. Flash is a well publicized standard and going by your own standards that should be good enough for you. Also, when Apple is pushing the very proprietary video standard H.264 as hard as they are (continue reading and you’ll see that they absolutely love H.264) they really shouldn’t be yapping about who is or isn’t being “open”.

Reason two: Adobe’s claim that Apple’s devices can’t deliver “the full web” since they don’t run Flash is caca because plenty of big websites have video in H.264 now and as for Flash-games there are loads of games on AppStore you can play instead.
There is some truth to this but it is still not valid in my opinion. Just because a long list of Apple-approved sites deliver video in H.264 instead of or as well as Flash it doesn’t mean every website does. It will still cause frustration when you run into that site with that video you wanna watch just have Flash – which is currently the dominant way to show video on the web. As for the games argument, it’s just laughable and shows that Steve isn’t a gamer himself. It’s like this: if I wanna play my game, I wanna play my game NOT another game. So if my game doesn’t run on the iPad it is no consolation at all that there are loads of other quality games available. I still can’t play the game that I wanted to play.

Reason three: Flash has lots of security flaws and the number one reason Macs crash.
I have no idea if the first claim is true or not so I’m not gonna argue against it. I’ve never had any of my Macs crash because of Flash but I’m not gonna argue the second claim either since I have no way to know what the truth is here. If Apple have statistics, which I assume they have, saying this, then it probably is true.

Reason four: Flash eats twice the battery life that H.264 with hardware acceleration does.
Again, whether this is true or not I don’t know but even if it is true I don’t think it’s a valid reason for shutting Flash out. Let the users themselves decide what to spend the juice of their batteries on. What’s next? Blocking games that are CPU-intense and thus eat “too much” battery. It’s just ridiculous. If customers want Flash, and they obviously do, let them have it even if it eats the batteries of their iPads and iPhones. Let people make their own choices.

Reason five: Flash was designed for PCs using mice, not for touch screens using fingers. You can’t “hover” or “rollover” on a touch screen.
This is true, but it is still an invalid reason simply because the controls of an app are up to the developer. It has nothing to do with the technology itself. Don’t you think Flash-developers targeting the iPhone would’ve thought of not to use controls that require “hovering”? Enough said.

Reason six: Apple knows from experience that all software developed using third-party tools suck and are inferior to software developed specifically for a particular device and/or operating system. Relying on third-party tools is also always a bad thing because then you’ll have to wait for the tool-developers to include new OS-features in their product and that can take a long time.
This part of Steve’s letter is so full of stupidity and claims that are in no way backed up by hard facts it’s laughable. What “experience”? Where are the statistics or surveys to prove this? Nowhere is where they are because it’s bullshit, plain and simple. It’s just a vague claim made like it’s the truth just because The Steve said so. Also, I find it amazing that Steve Jobs has taken it upon himself to save developers from using “bad tools”. I’ve said it several times already but I’ll say it one final time: Developers want freedom and choices! Let us decide for ourselves what tools we use and how we use them! We can take responsibility ourselves for our choices. We don’t need Steve Jobs to make them for us. Let us code and develop any way we want. Period.

So in closing all of this is just another scheme of Apple’s to lock people to their platforms attempting to create a sense of exclusiveness for their products in the process. The very same things they’ve in the past scolded Microsoft for. But what differs from previous ploys of theirs is that this is a tremendously nasty move that really benefits nobody, not even Apple themselves in my opinion. I think it is really sad and I don’t like the way Apple has been developing since releasing the iPhone – I think that’s where it all started to go downhill. I love Apple’s products – the hardware, OS X, iLife, all of that good stuff – but the company policies are pissing me off more often than not these days. Steve and his underlings need to step back and take a good look at themselves, the company’s past and the path their currently marching onwards on before it’s too late and Apple really becomes the new Microsoft or IBM. Nobody wants that, least of all me.