cooking, programming and everyday life xrado

Wednesday, January 21, 2009

Simple combining of multiple javascript and css files

I've already wrote about "firefox only includes styles form .css files" and I found out that isn't quite true. Actually firefox doesn't care about the css file extension, but only relay on header Content-Type: text/css. If you as usual have .css file, apache will take care of right content-type, otherwise you will have to take care about it.
header('Content-Type: text/css');
I came across this when i was writing this script:
## combine.php

// Define path prefix
$prefix = realpath('.');

if(!empty($_GET['js'])) {
	header('Content-Type: application/x-javascript');
	$data = Array('path'=>$prefix.'/template/js/','files'=>$_GET['js'],'ext'=>'.js');
} elseif(!empty($_GET['css'])) {
	header('Content-Type: text/css');
	$data = Array('path'=>$prefix.'/template/styles/','files'=>$_GET['css'],'ext'=>'.css');
} else exit();

foreach(explode(',',$data['files']) as $file) {
	if($file && file_exists($data['path'].$file.$data['ext'])) readfile($data['path'].$file.$data['ext']);
}
Simple few lines of code, but already do the trick. That will minimise number of server requests and benefit in faster page loading.

Defining the path and file extension is important, otherwise you may expose some other scripts source or even worse, some system files.

Usage in page head
<link rel="stylesheet" type="text/css" href="combine.php?css=style,forms" />
<script type="text/javascript" src="combine.php?js=mootools,validate,fx"></script>
Hope you like it, otherwise If you want more advanced solution try minify.

cheers

Thursday, January 01, 2009

pyGtranslator 0.2 (new version)

Here is a new version of pyGtranslator (GUI tool for Google translate) with many fixes and some new features. I think now works as it should.

what's new:
  • utf-8 characters works properly now
  • showing new lines fixed
  • added languages swap button
  • settings are now saved on exit
  • better connection error handling

happy translating and a happy new year :)


Downloads

Source
pygtranslator-0.2.tar.gz

Linux (require python, gtk, pygtk)
- ubuntu / debian: pygtranslator_0.2-1_i386.deb
- zenwalk: pygtranslator-0.2-noarch-54.1.tgz dep md5

Windows (require GTK2 runtime)
pygtranslator-0.2-win32.zip

Thursday, December 11, 2008

pyGtranslator - GUI tool for Google translate

Update:new version pyGtranslator 0.5 avalible
I've been playing with python these days. I made a small GUI tool that brings Google translate to your desktop. Application was easy to code, although I use python occasionally  (wish I could more and learn it better), but want it to make it run on both linux and windows. That took me quite more time. I almost gave up with py2exe and building windows executable, but after hours of googling and trying I figure out that I have to set environmental path to GTK runtime libs. I also made packages for two my favourite linux distros Zenwalk and Ubuntu. pyGtranslator can be improved and also "suggest a better translation" is missing, but that's maybe for late updates, if the need shows. I hope it works for you, otherwise let me know.

pygtranslator

pyGtranslator on GitHub

Downloads

Source
pygtranslator-0.1.tar.gz

Linux (require python, gtk, pygtk)
- ubuntu / debian: pygtranslator_0.1-1_i386.deb
- zenwalk: pygtranslator-0.1-noarch-54.1.tgz md5 dep

Windows (require GTK2 runtime)
pygtranslator-0.1-win32.zip

Saturday, November 15, 2008

Cauliflower sandwich filling

This is actually an mix of cooked cauliflower and some seasoning with almonaise (almond mayonnaise)... yummy bread spread. A real favorite!

imageAlmonaise ingredients:
  • 1/2 cup blanched almonds
  • 2-3 tablespoons extra virgin oil
  • 2-3 tablespoons fresh lemon juice
  • 1/2 teaspoon of salt
  • small garlic (optional)
  • salt free seasoning  (optional)
  • pepper to taste


First, blend almonds to powder and then mix all together in a mixer. Add some water if too dense and mix until a thick cream forms.

OK now that we have the almonaise, we just need a small cooked cauliflower and parsley or oregano for seasoning. Mix all together in slower mixer (if possible), otherwise it will become too creamy.

Here it is...  Bon app├ętit!

Monday, October 27, 2008

FireSpider extension for Firebug

FireSpider is a an extension for Firebug that can help you find broken or misleading urls and optimize your web page for search engines.

Extension enables you start and the stop the spider. After pressing the start button it fetch the current url and parses the content for new urls. Every unique url is fetch only once. It follows only the current domain urls and detects its content type. Not html content types are reported. Besides fetching, firebug panel gives you information about page title, page where url was got from, its link name and loading time. Reported are also not found urls and ones went in time out after 10 seconds. Requests are send one after another, so some sites may find it to aggressive or may detect you as a dangerous script. Be careful.

image

This is the first version (hope not the last) and first extension i ever made. Some things may not be very well done, but the basic functionalities are working, i think. Try it and tell me what you think. Hope you find it useful.

firespider-0.1.xpi ( download / install )

FireSpider on GitHub
pages:  1   2   3   4   5   6   7   8   9   10