rulururu

post Bravery or just stupidity?

December 29th, 2008

Filed under: Uncategorized — Kai @ 6:26 pm

No comment.

Bravery or Stupidity?

post Python Trick: Check for Substring

December 26th, 2008

Filed under: Python — Kai @ 7:36 pm

Today I’d like to show you a quick hint that might be obvious, but it took me quite some time of Python programming to figure it out.

You probably know that you can test if a list, tuple, or dict contains an item by testing the expression “item in list” or “item not in list”. I never realized that this would work for strings as well.

I was always writing code like:

string = 'Hi there' # True example
string = 'Good bye' # False example
if string.find('Hi') != -1:
   print 'Success!'

It’s kinda ugly code but it didn’t mind at all since I found otu that it is completely equivalent to do “if substring in string”:

string = 'Hi there' # True example
string = 'Good bye' # False example
if 'Hi' in string:
   print 'Success!'

Much cleaner and simpler. Might be obvious to 99% of the population, but I wish I’d known about it sooner.

post Why I hate Christmas that much

December 23rd, 2008

Filed under: Uncategorized — Kai @ 1:51 pm

Last year on 21st I expressed my contempt for Christmas briefly. With the hope that I don’t recur myself I’d like to write some lines also this year.

The lack of understanding really feels bad when outing yourself to be kinda “christmas-hater”, it’s elusive but true ;-)

I hate the way it makes people behave. I hate the shallow, fake little advertisements I see every damn place I go that tell me how by going into endless debt to buy shit for my family and friends I’ll somehow be a better person. I hate the lines in the stores, I hate how the decorations go up mid-October under the guise of “Holiday Spirit”. And I hate the people that buy into that sort of thing. They want your MONEY, you fools!

While we’re on the subject, I really hate how people can love Christmas and go all out. I hate how everyone remembers poor people and homeless people for two weeks and then promptly forgets about them again.

I’m in no mood for Christmas - I’m sick, sick, sick, of all the superficial cutsie little raindeer, snowmen, Santa Clauses, jingle bells, etc. Oh, excuse me just a moment while I wretch. I mean, driving by some houses looks like the light monster walked by and threw up all over the place. A very few are done well and are attractive but the vast majority are gaudy and asthetically unbalanced.

I vehemently resent all the expectations and demands placed on me at Christmas. I’m not poor but I’m not rich either, and I have bills to pay. There is an endless list of things I am expected to spend my money on - gifts for everyone, tips for all my service providers, food, Christmas Cards, interior and exterior decorations, lights, etc, etc, etc. It is financially irresponsible to buy gifts for everybody at the same time.

Instead of enjoying a few days of holiday everybody uses up an unbelievable amount of time and money on Christmas stuff. To me it’s just overwhelming crass commercialization and a waste of my time and money.

Fear

P.S.: Hey kids, Santa was the invention of Coca-Cola’s 1930s advertising campaign… HE’S NOT REAL!!!

post VBS-Battle: command line for output

December 10th, 2008

Filed under: General Programming, Windows — Kai @ 2:04 pm

From time to time I have battles with Visual Basic Script, which I usually avoid using.

I wanted console output because the process I’m starting should be unattended, rather than clicking through a bunch of MsgBoxes.

Typically, one prints in VBscript using a Wscript.echo("Hello, world!") line or some variant thereof. If you do not invoke with a cscript hello-world.vbs, you get a GUI/pop-up MsgBox, which I wish to avoid. I just wanted something to go right to the command line for output, without putting cscript at the beginning.
Wscript.StdOut.WriteLine dies, of course, if not also invoked with a cscript.

For different reasons I didn’t want to permanently set my default scripting host to cscript, either.

Probably the best solution to solve that problem is a simple stub in the script that will be called when it starts, which detects how the script was started, and re-starts it explicitly using cscript.exe if needed. It makes use of the wscript.fullname property (which is the path to the running host executable, either c:\windows\system32\cscript.exe or wscript.exe). If the script is running as wscript.exe, it will simply re-launch the script using cscript.exe and exit.
This way, if the local machine has wscript as the default host, it will immediately launch, detect that it was launched via wscript, and re-launch itself using wshell.run as a cscript. The local host doesn’t need to be reconfigured for this to work.

'this is at the start of your script
CheckStartMode
 
' This is somewhere else in your script
Sub CheckStartMode
     ' Returns the running executable as upper case from the last \ symbol
     strStartExe = UCase( Mid( wscript.fullname, instrRev(wscript.fullname, "\") + 1 ) )
 
     If Not strStartExe = "CSCRIPT.EXE" Then
          ' This wasn't launched with cscript.exe, so relaunch using cscript.exe explicitly!
          ' wscript.scriptfullname is the full path to the actual script
 
          set           oSh = CreateObject("wscript.shell")
          oSh.Run "cscript.exe """ & wscript.scriptfullname & """"
          wscript.quit
 
     End If
End Sub

The only disadvantage of that solution is that it closes the console window it opens as soon as the script is finished. I went through all of the options for intWindowStyle in the Run method of the WshShell object and none of them kept the spawned console open for more than a flash. Maybe there’s a hack for it, too.

post Yahoo is out of choices and wants Microsoft

November 7th, 2008

Filed under: Internet — Kai @ 4:44 pm

Balmer, Steve

Just a few months ago, the blogosphere was exploding over the possibility of Microsoft and Yahoo joining up to become an online powerhouse. But after a lengthy deliberation, political jockeying, and pleas for help, Microsoft walked away after Jerry Yang did everything he could to kill the deal.

But the story didn’t quite end there. Since then, Microsoft and Yahoo have gone back to the table twice. First, Microsoft entertained the possibility of acquiring Yahoo’s search for $1 billion and a buyback of Yahoo stock for $8 billion. After that deal fell through, we once again thought it was over. But now, they’re back to talking about a full buyout and Jerry Yang, not Ballmer, is starting to look like the CEO who really wants to get the deal done.

So how does the plan address the major issues Yahoo is currently facing? Shareholders are calling on Jerry Yang to either sell the company to the highest bidder or move aside, the stock price continues to fall, and as more executives jump ship, more people are getting the sense that something quite awful is going on behind the scenes.

All the while, Microsoft is sitting back and watching events unfold. With zero debt on its books and quarterly profit of more than $4 billion to boot, it’s in the best position to save Yang from himself and finally satisfy Yahoo’s long-suffering shareholders. Whether or not it will is another story.

But at this point, Yang has little choice but to go to Microsoft with his hat in hand and ask for a buyout.

The Microsoft-Yahoo soap opera started with Ballmer wanting Yahoo to ensure that his company plays a major role in the online world going forward. Since then, Ballmer’s desire for Yahoo has dwindled and Yang, the once-obstinate CEO, is left wanting Microsoft and hoping that Microsoft will want him back.

post Empty blocks

October 27th, 2008

Filed under: C++ — Kai @ 10:54 am

A tricky loop I’d like to show you.

First of all a quick explanation of the two functions I use.

  • log2 computes the base-2 logarithm of x.
  • ceil rounds, it returns the smallest integral value that is not less than x.
/* compute the ceil(log2(x)); i,x are unsigned; x is not 0 */
for( i = x>>1, n = 0; i != 0; i >>= 1, n++ ) {
}

In C we can have loops that have nothing in their body. You should use braces around an empty body. This allows you to expand the body if necessary. Further it gives us a visual clue that something out-of-the-normal is going on.

ruldrurd
« Previous PageNext Page »
Powered by WordPress, Content and Design by Kai Bellmann
Entries (RSS) and Comments (RSS)