rulururu

post Yahoo rejects Ballmer’s offer

February 10th, 2008

Filed under: Internet — Kai @ 2:18 pm

Yahoo’s administrative board recently announced that they are not willed to accept Microsoft’s $44.6 billion takeover bid. After a last-minute meeting yesterday, Yahoo’s board is said to have rebuffed the offer from Microsoft believing that the Windows developer is acting out of opportunism.

Although the offer of $31 per share is significantly higher than Yahoo’s stock value at the time of the proposal, the search engine firm’s executives reportedly believe that this offer is undervalued and are waiting for a bid of $40 per share or more, which could raise the worth of the bid to $56 billion.

As a result of the decision, Yahoo may still be willing to consider a Google alliance or a similar deal to sour the prospects for Microsoft.

Finally I think the move signals Yahoo management may be preparing for a long battle for control of the company.

post AndAlso instead of And keyword

February 8th, 2008

Filed under: .NET, C++ — Kai @ 5:01 pm

At first consider this:

if(array[i] != NULL && array[i+1] == 2) {
 //do something
}

As well in C# a typical check that you might see is something like this:

if ((Bunch["Key"] != null ) && (Bunch["Key"].Length > 0) {
//do something
}

Similarly in VB.Net you’ll find

If Not IsNothing(Bunch.Item("Key")) And Bunch.Item("Key").Length > 0) Then
' do something
End If

In both examples C++ as well C# the second condition would not throw a NullException because if the first condition fails the second (and also further ones) are not accessed.
But in the VB.Net example, if the first condition isn’t met both conditions will be evalutated either way. As you know, this will cause an NullReferenceException if for “Key” does not exist in the the Bunch collection.

A better choice would be to use the AndAlso keyword.

If Not IsNothing(Bunch.Item("Key")) AndAlso Bunch.Item("Key").Length > 0) Then
' do something
End If

This will cause the statement to stop executing if “Key” is null in the Bunch.Items collection.

post Lambda in C#

February 7th, 2008

Filed under: .NET — Kai @ 10:47 pm

Λ is more than the 11th letter of the Greek alphabet.

C# in .NET 3.0 got a number of handy new language features, but the one I’m enjoying the most at the moment is the addition of the => operator (otherwise know as lambda). While this operator does not add any new functionality to the language, it is a great piece of syntactic sugar.

In .NET 2.0, writing anonymous functions inline was a very verbose process, you might often had a hard time reading them ’cause they were looking kinda ugly.

To show you what I do mean I created a simple function. It takes a delegate that should take in 2 integers and return an integer value. Additionally it takes a list of intergers (params is used here). Finally it returns a single integer.

public delegate int expo(int x, int y);
 
public int SomeFunc(expo f, params int[] list)
{
  int r = 1;
  foreach (int i in list)
    r = f(r, i);
  return r;
}

This function is pretty clear, but the usage is ugly:

int n = SomeFunc(new expo(
      delegate(int x, int y) { return x * y; }), 55, 33, 223, 31);

also that is not even better:

int n = SomeFunc(delegate(int x, int y) { return x * y; },
      55, 33, 223, 31);

But now have a look at that great solution:

int n = SomeFunc((x, y) => x * y, 55, 33, 223, 31);

That’s an example of a lambda expression. Lambda expressions are always of this form:
parameters => expression
You no longer need to use the word delegate, you no longer need to declare the types of the parameters to the function.

This is just the basic use of the new lamdba operator in C#. So far, lambdas don’t appear to offer anything I didn’t already have with anonymous methods besides a different syntax. However, they turn out to be able to do something that anonymous methods cannot.

Indeed most of the new C# 3.0 languages features have been added on LINQ’s behalf, although none of them is inextricably bound to LINQ.

LINQ (Language Integrated Query) defines a standard way of performing queries against various types of data in a way that can be tightly integrated into a language. I wrote about that earlier.

Consider the following code which is very common:

DataContext dc = new DataContext("...");
Table<Cars> cars = dc.GetTable<Cars>();
Table<Brands> brands = dc.GetTable<Brands>();
 
var q = from c in cars, b in brands
        where b.Name == "BMW" && (c.ID == b.ID)
        select new { b.Date, c.CarHolder, c.Street, };
 
foreach (var item in q)
{
    Print(String.Format("Date: {0} Belongs to: {1} at {2}",
        item.Date, item.CarHolder, item.Street));
}

The way I’d prefer when using lambda is:

var q = cars.Where(b => b.Name == "BMW").SelectMany(
    b => brands.Where(b => c.ID == b.ID).
            Select(b => new { b.Date, c.CarHolder, c.Street }));

Deferred execution allows the language extensions for XLinq, DLinq, LINQ, or any other Linq extension that comes after to process the logic represented by the expression tree before execution so that optimizations can take place.

If you are planning on doing anything with LINQ, you should know what a lambda is, how to use it in real terms.

post Makros for detecting compiler version

February 6th, 2008

Filed under: C++ — Kai @ 7:13 pm

In C++ you sometimes need switches for parts of code for different compilers or you just need to verify that the function you’re using is compiled with the right version of compiler.

I mostly tell you about GCC, but I also didn’t forget about MS Visual Studio and Borland Builder.

The common predefined macros are GNU C extensions. They are available with the same meanings regardless of the machine or operating system on which you are using GNU C. Their names all start with double underscores.

__GNUC__
__GNUC_MINOR__
__GNUC_PATCHLEVEL__

These macros are defined by all GNU compilers that use the C preprocessor: C, C++, and Objective-C.
Their values are the major version, minor version, and patch level of the compiler, as integer constants. For example, GCC 3.2.1 will define __GNUC__ to 3, __GNUC_MINOR__ to 2, and __GNUC_PATCHLEVEL__ to 1. They are defined only when the entire compiler is in use; if you invoke the preprocessor directly, they are not defined.__GNUC_PATCHLEVEL__ is new to GCC 3.0; it is also present in the widely-used development snapshots leading up to 3.0 (which identify themselves as GCC 2.96 or 2.97, depending on which snapshot you have).

If all you need to know is whether or not your program is being compiled by GCC, you can simply test __GNUC__.
If you need to write code which depends on a specific version, you must be more careful. Each time the minor version is increased, the patch level is reset to zero; each time the major version is increased (which happens rarely), the minor version and patch level are reset.

If you wish to use the predefined macros directly in the conditional, you will need to write it like this:

//Test for GCC > 3.2.0
              #if __GNUC__ > 3 || \
                  (__GNUC__ == 3 && (__GNUC_MINOR__ > 2 || \
                                     (__GNUC_MINOR__ == 2 && \
                                      __GNUC_PATCHLEVEL__ > 0))

Another approach is to use the predefined macros to calculate a single number, then compare that against a threshold:

#define GCC_VERSION (__GNUC__ * 10000 \
                                   + __GNUC_MINOR__ * 100 \
                                   + __GNUC_PATCHLEVEL__)
              ...
              //Test for GCC > 3.2.0
              #if GCC_VERSION > 30200

I think this form is easier to understand.

Those are the important markos for detecting a specific compiler version:

  • __GNUG__
    The GNU C++ compiler defines this. Testing it is equivalent to testing (__GNUC__ && __cplusplus).
  • __BORLANDC__
    In Borland C++ Builder, the __BORLANDC__ identifier provides information about version number. Those are the versions of C++Builder that correspond to each value of __BORLANDC__:

      0×0520 ———- C++Builder 1
      0×0530 ———- C++Builder 3
      0×0540 ———- C++Builder 4
      0×0550 ———- C++Builder 5
      0×0560 ———- C++Builder 6
  • _MSC_VER >= x
    Use _MSC_VER to guarantee the right version of Visual Studio.

    #if _MSC_VER >= 1500
       // this is Visual C++ 2008 (Orcas)
    #elif _MSC_VER >= 1400
       // this is Visual C++ 2005
    #elif _MSC_VER >= 1310
       // this is Visual c++ .NET 2003
    #elif _MSC_VER > 1300
       // this is Visual C++ .NET 2002
    #endif

    For example you can disable a warning that just occurs with VS2005 compiler:

    #ifdef _MSC_VER_VS2005
    # pragma warning(disable:4927) 
    #endif
  • It should be mentioned that this approach doing switches is mostly not annotated ANSI C standard, but often used for porting applications to other platform.
    It’s also often necessary when programming on a project for a long time period so that compiler versions change that much that some older parts of the source might not get compiled well anymore.

post All you’d know about Google

February 5th, 2008

Filed under: Internet — Kai @ 1:48 pm

The following pdf gives you a great overview of the possibilities to use the Google search.

Google Cheat Sheet.pdf

Hope it helps ;)

post Making a audio-cd the easy way

February 2nd, 2008

Filed under: Linux, Music — Kai @ 4:35 pm

Almost everybody know that situation only too well - you quickly have to burn an audio cd (e.g. for a party) and need all the tracks on cover.

I used to burn the cd with K3b or Brasero and then made a screenshot which I quickly edited to a fitting size with gimp and finally printed it.

Yesterday I found a better way when coming accross cdlabelgen, a great console-tool for making printable cd covers.

Usage can for example be:

cdlabelgen -c "Led Zeppelin" -s "Mothership" -o cover.ps

with parameter -f you can point to a file containing the tracknames.

cdlabelgen -c "Led Zeppelin" -s "Mothership" -f tracklist.txt -o cover.ps

I generate this file with a really short python script which I do pipe and writing the stream into a textfile:

ls -l | ./tracklist.py > tracklist.txt

#!/usr/bin/env python
from fileinput import input
import re
for line in input():
        s = line.find("- ")
        if s >= 0:
                line = line[s+2:line.find(".")]
                print line

Combination of all this to a small bash script gives you a great solution that saves a lot of time:

  • Generate tracklist
  • Get cd-title
  • Generate printable cover (postscript file)
  • Convert mp3 files to wav
  • Burn tracks using e.g. cdrecord

The script might look similar to this:

#!/bin/sh

#get title folder name
title=`${1} | awk 'BEGIN {FS="/"} {print $NF}'`
#generate list
ls -l ${1} | ./listfiles.py > tmp.txt
#generate label
cdlabelgen -c "`echo $title`"  -f ./tmp.txt -o ~/Desktop/label.ps
#delete list
rm tmp.txt
#convert mp3 to wav and burn
for i in *.mp3; do mpg123 -v -w "${i%mp3}wav" "$i"; done
cdrecord -dev=ATA:1,0,0 -eject speed=4 -pad -audio *.wav

If your printer is able to print postcript you can print directly like this:

cdlabelgen <args> | lpr -P<printername> -o Resolution=None -o PageSize=A4

You can add much more to your cover like images, date, etc. just have a look at the manpage.

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