Archive for April, 2008

OSX Leopard Leo4All on my PC

Since the appearance of the Leopard version of the OSX operating system, I’ve been dying to install it on my PC.

At the time I had an old Athlon CPU and I decided to get a cool new processor that would support the new OSX.

In about a week I put together a nice little computer with Intel E6850 + Intel DG33BU + GeForce 8600GT + 2 GB DDR2.

It took me months of testing and hacking and testing and crying and pulling my hair in my quest for Leopard. Finally, about 3 days ago I got my hands on Leo4All Leopard DVD ISO and that made my dream come true. Everything works like a charm (and that means the things REALLY work, fast and glamorous).

I am no professional tester, nor do I use some complicated testing tools, yet, IMHO Leopard beats the crap out of Vista in many ways. Now I can understand those MAC junkies from various forums and blogs, bragging and pretending theirs is the best OS out there. I do not know about the “best” part, but they do have a point on the looks, speed and feeling. Leopard provides all that to the fullest.

As a programmer though, I find Leopard to be unequipped by default with any programming tools (I mean there is not even a decent text editor). I tried to find a FREE text editor but I only found commercial ones. Finaly I got TextMate and it does the job just fine.

As a conclusion, I find Leopard to be a fine piece of software but definitely not targeted towards IT geeks but more to the home user segment. For those of you spending night after night in front of the computer trying to make things work I would recommend Ubuntu (either server or desktop).

Here are some Screen shots :

Applications Folder

Amazing Leopard graphic performance

iTunes

About this mac

  • Share/Bookmark

Tags: , , , , ,

Friday, April 25th, 2008 Internet 1 Comment

How can we import data in MySQL from CSV file

Run this SQL script either from a mysql console or from your favorite scripting language (PHP, PERL…)

LOAD DATA LOCAL INFILE ‘/path-to-file/dump_file.csv’
INTO TABLE table_name
FIELDS TERMINATED BY ‘,’
LINES TERMINATED BY ‘\n’
(Field_1, Filed_2, Field_3);

I believe the syntax is more than clear so I won’t bother explaining too much.

  • Share/Bookmark

Tags: , , , ,

Tuesday, April 22nd, 2008 MySQL, PHP No Comments

How can we export MySQL data as CSV

IN PHP:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$table2dump = 'table_name';
$file_content = '';
 
$sql = "SHOW COLUMNS FROM " . $table2dump ;
$res = mysql_query($sql);
while ($row = mysql_fetch_assoc($res)) 
{
	$file_content .= $row['Field'].',';
}
$file_content = substr($file_content, 0, -1)."\n";
 
$sql = "SELECT * FROM " . $table2dump ;
$res = mysql_query($sql);
while ($row = mysql_fetch_assoc($res)) 
{
	$file_content  .= implode(',', $row)."\n";
}
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv; filename=" . date("Y-m-d") . "_" . $table2dump . ".csv; size=".strlen($file_content));
echo $file_content;
exit;
  • Share/Bookmark

Tags: , , , , , ,

Tuesday, April 22nd, 2008 MySQL, PHP No Comments

How can you import(restore) a MySQL database from an SQL file

From the shell command prompt type:

mysql -p -h SERVER_NAME DATABASE_NAME < BACKUP_FILE.sql

where:
- SERVER_NAME – is the database server name (usually localhost)
- DATABASE_NAME – is the name of the database to be restored
- BACKUP_FILE – is the name of the file (usualy the name of the database plus the backup date)

  • Share/Bookmark

Tags: , , , , , ,

Monday, April 21st, 2008 MySQL No Comments

How can you dump a MySQL database

from the shell command prompt type:

mysqldump -h SERVER_NAME DATABASE_NAME > BACKUP_FILE.sql

where:
- SERVER_NAME – is the database server name (usually localhost)
- DATABASE_NAME – is the name of the database to be dumped
- BACKUP_FILE – is the name of the file (usualy the name of the database plus the backup date)

  • Share/Bookmark

Tags: , , , , ,

Monday, April 21st, 2008 MySQL No Comments

.NET Form Transparency

A little tip on the .NET Form Transparency.
The following code shall provide a simple way to adjust the form transparency using the mouse wheel button.

//=== in the initialization section insert this:

this.MouseWheel += new MouseEventHandler(TransparencyHandle);

//=== in the form’s class :
private void TransparencyHandle(object sender, MouseEventArgs e)
{
if (e.Delta > 0)
{
this.Opacity = this.Opacity + 0.05;
}
else
{
this.Opacity = this.Opacity – 0.05;
}
}
This should do it.

  • Share/Bookmark

Tags: , , , , ,

Friday, April 11th, 2008 .NET No Comments

.NET TEXT-TO-SPEECH example

Some methods to implement text-to-speech in a .NET application:

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
public void Sing(string vMessage)
{
    BackgroundWorker bw = new BackgroundWorker();
    bw.DoWork += new DoWorkEventHandler(bw_DoWork);
    bw.RunWorkerAsync(vMessage);
}
 
private static void bw_DoWork(object sender, DoWorkEventArgs e)
{
    SpVoice voice = new SpVoice();
    voice.Speak(e.Argument.ToString(), SpeechVoiceSpeakFlags.SVSFDefault); 
}
 
Sing("Hello");
  • Share/Bookmark

Tags: , , , , ,

Friday, April 11th, 2008 .NET No Comments

.NET DataSet Creation

private void GetData(string selectCommand)
{
try
{
// Specify a connection string. Replace the given value with a
// valid connection string for a Northwind SQL Server sample
// database accessible to your system.
String connectionString =
“Integrated Security=SSPI;Persist Security Info=False;” +
“Initial Catalog=Northwind;Data Source=localhost”;

// Create a new data adapter based on the specified query.
dataAdapter = new SqlDataAdapter(selectCommand, connectionString);

// Create a command builder to generate SQL update, insert, and
// delete commands based on selectCommand. These are used to
// update the database.
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);

// Populate a new data table and bind it to the BindingSource.
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
bindingSource1.DataSource = table;

// Resize the DataGridView columns to fit the newly loaded content.
dataGridView1.AutoResizeColumns(
DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
}
catch (SqlException)
{
MessageBox.Show(“To run this example, replace the value of the ” +
“connectionString variable with a connection string that is ” +
“valid for your system.”);
}
}

  • Share/Bookmark

Tags: , ,

Friday, April 11th, 2008 .NET No Comments

OSX COCOA HTTP POST method

For those of you interested in COCOA Objective-C development, here is some code to proper achieve an upload using HTTP POST.
The input data as you can see is provided by some NSTextFields.
The HTTP request is done Synchronously but there is a simple way to do it asynchronously.
So here you go :

————————————————————————-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
- (IBAction)upload:(id)sender
{
 
    //creating the url request:
    NSURL *cgiUrl = [NSURL URLWithString:@"http://www.testsite.com/upload.php"];
    NSMutableURLRequest *postRequest = [NSMutableURLRequest requestWithURL:cgiUrl];
 
    //adding header information:
    [postRequest setHTTPMethod:@"POST"];
 
    NSString *stringBoundary = [NSString stringWithString:@"0xKhTmLbOuNdArY"];
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",stringBoundary];
    [postRequest addValue:contentType forHTTPHeaderField: @"Content-Type"];
 
 
    //setting up the body:
    NSMutableData *postBody = [NSMutableData data];
    [postBody appendData:[[NSString stringWithFormat:@"\r\n\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"title\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [postBody appendData:[[NSString stringWithString:[edTitle stringValue]] dataUsingEncoding:NSUTF8StringEncoding]];
 
 
    [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"description\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [postBody appendData:[[NSString stringWithString:[edDescript stringValue]] dataUsingEncoding:NSUTF8StringEncoding]];
 
 
    [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"username\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [postBody appendData:[[NSString stringWithString:[edUser stringValue]] dataUsingEncoding:NSUTF8StringEncoding]];
 
 
    [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"password\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [postBody appendData:[[NSString stringWithString:[edPasswd stringValue]] dataUsingEncoding:NSUTF8StringEncoding]];
 
 
    [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"videoFile\"; filename=\"@\"\r\n", [[edFileName stringValue] lastPathComponent]] dataUsingEncoding:NSUTF8StringEncoding]];
    [postBody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [postBody appendData:[[NSString stringWithString:@"Content-Transfer-Encoding: binary/video\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
 
    [postBody appendData:[NSData dataWithContentsOfFile:[edFileName stringValue]]];
 
    [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [postRequest setHTTPBody:postBody];
 
 
    NSError *error;
    NSData *searchData;
    NSHTTPURLResponse *response;
    int n = 0;
 
    //==== Synchronous call to upload
    searchData = [ NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&amp;error];
 
    while (1)
    {
        if ([ response allHeaderFields])
        {
            NSString *monster = [[ response allHeaderFields] valueForKey:@"Monstermsg"] ;
            NSAlert *alert = [[NSAlert alloc] init];
            [alert addButtonWithTitle:@"OK"];
            [alert setMessageText: monster ];
            [alert setAlertStyle:NSWarningAlertStyle];
            if ([alert runModal] == NSAlertFirstButtonReturn)
            {
                NSLog(@"%@", monster);
            }
            [alert release];
            break;
        }
        NSLog(@"%d", n++);
    }
}
  • Share/Bookmark

Tags: , , , , , ,

Friday, April 11th, 2008 COCOA 3 Comments

VNC Proxy

Recently I found an annoying problem when I find out that our video conference software cannot do desktop sharing on computers that have no public IP.
We decided to build a VNC Proxy that can be controlled using some commands.
The task got a little bit complicated when you think that this proxy is supposed to support multiple conferences each with multiple clients at the same time.
So, using my good old friend Delphi 7 (especially TServerSocket component) we’ve managed to implement the VNC Proxy. Testing revealed that this solution is viable although the speed is a little bit slower than on direct IP access (as all data is transferred via proxy server).
Ahh … just a remainder for all of you searching the TServerSocket component:
By default this package is not installed in Delphi 7, so:
Component >> install packages >> Add button >> select C:\Program Files\Borland\Delphi7\Bin\dclsockets70.bpl.

Right now, the FLASH videocenferencing application allows desktop sharing(limited or full control) on any computer, public IP or not.
For those of you interested in the real project, you can test the results on http://demo.streamingbase.com.

  • Share/Bookmark
Friday, April 11th, 2008 Delphi No Comments