853PHP define(): single or double quotes?

I recently came across the following situation. A new server, a client-defined database, a database name like this: 'my-database'. Checking if the DB exists in PhpMyAdmin, everything checks out.

Putting all the details in wp-config.php should also work, right?

define('DB_NAME', 'my-database');

Hmmm. No, not quite. Error establishing a database connection

Could it really be, that the dash in 'my-database' messes up the DB_NAME? Apparently yes.

define('DB_NAME', "my-database");

Ok, problem solved. As for why, that's still an open question.

647The 11G Text-Edit Challenge

Ok, here's a challenge. Say, you have a massive, 11 Gigabyte text file. The first two lines are the header files, unfortunately the header on line 2 is slightly wrong: Instead of 'Done' it should say 'Status:Done'. (Hit: 'Done' is the first occurrence of that string in that line)

Any Ideas?

  • split and the cat? Could not figure out to split it in uneven files, i.e. the first 2 lines and the rest...
  • vi? Seems to open, but bulks when saving it.

[Update]

sed seems to be the tool for this job. sed '2 s/Done/Status:Done/' input.txt > output.txt

Took about 7 minutes on my machine... Any better ideas still very much appreciated.

[Update 2: How to insert a tab with sed]

Inserting a tab with sed turned out to be more resilient than expected. Neither an escaped tab (\t) not a double-escaped tab (\t) seemed to do the trick. On bash it is necessary to drop out of sed and print the tab (\011) directly. 27 in the following statement means of course line 27.

sed '27 s/Done/Status:Done'"$(printf '\011')"'After Tab/' in.txt > out.txt

305Converting float to string %4.2f

printf ("floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416); floats: 3.14 +3e+000 3.141600E+000

73Concatenating Strings @”string1″ @”string2″ @”stringN”

That's basically it.

No more [@"string1" stringByAppendingString:@"string2"];

or [NSString stringWithFormat:@"string1%@", @"string1"];

just @"string1" @"string2" @"stringN" -> code>@"string1string2stringN"</code

The Objective-C 2.0 Programming Language.pdf, p131