cooking, programming and everyday life xrado

Thursday, January 10, 2008

imgBox ...like my lighter lightbox

You all probably know lightbox image popup,.. ok ..this is my simple version of it, using mootools 1.2.

DEMO

Features:
- gallery functions (next, previous image)
- direct link to certain image popup
- image description via title
- no extra css or images needed, except progress bar (optional)
- aware of linux flash non transparency
- fully custom able
- no effects ..not really a feature..but i like it this way

tested & working : firefox, opera, internet explorer, safari, konqueror

Default options

options:{
	classname: 'imgbox',
	overlay_bg: '#000000',
	overlay_opacity: '0.6',
	rbox_bg: '#ffffff',
	controls_color: 'red',
	numberof_color: '#333333',
	title_color: '#ffffff',
	thumb_url: 'size=thumb',
	image_url: 'size=large',
	progressbar: '',
	margin_top: '20px'
},

Usage
1. Include imgbox.js and mootools.js (DomReady, Selectors, Element.Dimensions, Element.Styles and deps) to header
<script type="text/javascript" src="js/mootools.js"></script>
<script type="text/javascript" src="js/imgbox.js"></script>
2. Add class 'imgbox' (or the one you want) to images you want to popup
<img src="small_image.jpg" class="imgbox" title="image description">
3.Add this line some where on your page (within script tags) or add it directly to imgbox.js
window.addEvent('domready', function(){ new imgBox({}); });

Example with options
window.addEvent('domready', function(){  
	new imgBox({		
		thumb_url: 'small_',
		image_url: 'big_'
	});
});
thumb_url and image_url set the differences in thumbnail and popup image path that will be switched/replaced. For example if you have thumbnail image with name small_12.jpg, the popup will show big_12.jpg.

I hope you like the script. Feel free to use it on your site. If you have an idea how to improve it, let me know.

Download:
imgbox.js

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
pages:  1   2   3   4   5   6   7   8   9   10