cooking, programming and everyday life xrado

Friday, December 28, 2007

Field mushrooms with rucola

Ingredients: mushrooms, onion, garlic (optional), carrot, tofu, tomato sauce, soy sauce, vegetable soup, rucola, tomato and salt and pepper to taste.
Preparation time: 30-40min

mushrooms_rucola.jpg

Served with bread.

Wednesday, December 19, 2007

Generate INSERT and UPDATE mysql queries

Tired of writing long insert and update queries? I wrote a query that can generate it for you. Paste the query to phpmyadmin sql tab, edit the table and database and run it. The result is full insert/update for the row, just erase/edit unneeded parts and the query is ready for use, of course don't forget about escaping and filtering the data before they end in a query.
## generate INSERT query
SELECT CONCAT('INSERT INTO ',table_name,' (',GROUP_CONCAT( column_name SEPARATOR ',' ),') VALUES (',GROUP_CONCAT( "'$POST_",column_name,"'" SEPARATOR ',' ),')') AS insert_query
FROM information_schema.COLUMNS
WHERE table_name = 'table' AND TABLE_SCHEMA = 'database';
 
## generate UPDATE query
SELECT CONCAT('UPDATE ',table_name,' SET ',GROUP_CONCAT( column_name,"='$POST_",column_name,"'" SEPARATOR ',' )) AS update_query
FROM information_schema.COLUMNS
WHERE table_name = 'table' AND TABLE_SCHEMA = 'database';
I save a lot of time using this, not even saying about the typing mistakes I usually do by writing it manually.

Results:
INSERT INTO simpletable (id,date,rating) VALUES ('$POST_id','$POST_date','$POST_rating')
UPDATE simpletable SET id='$POST_id',date='$POST_date',rating='$POST_rating'

Friday, December 14, 2007

Pasta with broccoli and tofu

Ingredients: pasta, broccoli, tofu, garlic, olive oil, pepper, salt and mix of some other spices
Preparation time: 20min

00024_.jpg

Portion was damn big :) ..anyway my first cooking post over here... more coming... Some dishes are so tasty and good looking, that i have to take a picture :)

Thursday, December 13, 2007

PHP / Javascript Obfuscator

Have you ever want to prevent others sticking their fingers into your code? I did. I have searched over the web, but i didn't find anything suitable. Actually i didn't want to protect my code, but just make it harder to read and modify. So i made small script that do just that. The script strips all new lines, tabs, unneeded spaces and comments, so the code is braked in to one line. I didn't forget about php "here document" that i use quite a lot. This one needs new line right after the terminator, so if you using it, the output will have some more lines on the end.

I run this script from the linux shell as you see below, stored in to file comp.php. Just "cd" to directory where you have your php or js scripts and run the command. Find will recursively found all the *.php scripts and obfuscate them. Be careful before running the script!!! Always check the path you are in and do a backup copy, otherwise you might end up with a headache or even losing the code.

Usage
find . -iname "*.php" -exec php comp.php {} \;
find . -iname "*.js" -exec php comp.php {} \;
script:
// here document terminator
$here_document = "END";

error_reporting(0);

if(ereg($argv[0],$argv[1])) exit();

function cleanup($line){
	$line = preg_replace('/(^|\s)\/\/(.*)\n/','',$line); // remove line comments // comment
	$line = preg_replace('/(\t|\r|\n)/','',$line);  // remove new lines \n, tabs and \r
	return $line;
}

$lines = file($argv[1]);
echo $argv[1]." ";
echo "lines: ".count($lines)." -> ";
foreach ($lines as $line) {
        if(ereg($here_document,$line) && ereg("<<<",$line)) $out.= cleanup($line)."\n";
        else if(ereg("$here_document;",$line)) $out.= "\n".cleanup($line)."\n";
        else $out.= trim(cleanup($line))." ";
}
$out = preg_replace('/(\/\*[\s\S]*?\*\/)/', '', $out); // remove multi-line comments /* */

file_put_contents($argv[1],trim($out));	// store back to file

echo count(file($argv[1]))."\n";
Source: comp.php.txt

Wednesday, December 12, 2007

blog refresh

Hi, i finally took some time to refresh my site, blog or whatever. Actually it's completely rewritten and it is now using my mini CMS called xAdmin as a back-end. I will be probably introduce to you in some future post. Because i'm really bad at choosing colors and styles I took some style from the bloggers themes and i can say i'm satisfied for now. But i must tell you that i almost lost everything i did just before finishing up. I accidentally droped the database :/. i had luck, actually it took me two hours to recover the data from mysql binary log. i didn't know that it can be done :). Ok i don't have much to say..hear ya.

greetings
pages:  1   2