2009-11-04

Obama and ACTA

This is so important, its found a place even in this blog:
http://www.boingboing.net/2009/11/03/secret-copyright-tre.html

Hashes: #ACTA #obama #copyright #usa #eu

2009-11-03

Kohana modules hack

When adding modules to kohana, most oftenly you need to add that module to the config file to have it loaded. Now I find this mostly an unnecessary hassle. (Its useful when sharing module path between applications, though).

However, just comment out the module settings, replacing it with this code snippet:

$config['modules'] = array();
foreach (scandir(MODPATH) as $folder) {
if ($folder != '.' && $folder != '..') {
$config['modules'][] = MODPATH . $folder;
}
}

That'll load all your modules automatically. :)

Hashes: #kohana #php

Excel export module

Important! All Kohana-related posts are now at http://kohana.lillem4n.se.

This is a excel export module to Kohana. Simpel use like this:
$excelExport = new Excel_export();
$excelExport->addRow(array('first row, first column','first row, second column'));
$excelExport->addRow(array('second row, first column','second row, second column'));
$excelExport->download('myExcelFile.xls');

Full documentation of all available methods and parameters are in the module library source.

Bug reports, comments, improvements; very welcome. :)

Hashes: #kohana excel export module #kohana module #kohana #excel export #php

2009-11-01

Kohana extended form rules

Important! All Kohana-related posts are now at http://kohana.lillem4n.se.

New version available here, a post about this issue is located here.

This is a module with rules you'd like when validating forms in kohana. It is the same concept as the valid::-rules.

For example:
$post->add_rules('some_field', 'required', 'digit', 'formrules::positive');


This will require "some_field" to be a digit (whole number) above zero.

For now, positive is actually the only rule in this module. So it is more like the foundation of a module. :) More rules will follow.

Hashes: #kohana form rules module #kohana module #kohana #form validation #php

2009-10-17

Kohana XML helper module

Important! All Kohana-related posts are now at http://kohana.lillem4n.se.

This module is actually just a helper (for now, at least). But it is very handy when working with converting various data to XML in PHP. A few examples:

Simple example of the two different return values.
As DOMDocument:
<?php
$doc = xml::toXML(array('root'=>array('fnupp'=>'dah')));
$doc->formatOutput = true;

echo $doc->saveXML();
?>


As DOMNode:
<?php
$doc = new DOMDocument();
$container = $doc->appendChild($doc->createElement('root'));

xml::toXML(array('fnupp'=>'dah'), $container);

echo $doc->saveXML();
?>


How the $container works:
xml::toXML(array('fnupp' => 'dah'))

will output:
<fnupp>dah</fnupp>

xml::toXML(array('fnupp' => 'dah'), 'root')

will output:
<root>
<fnupp>dah</fnupp>
</root>

That was just a few examples, full documentation is within the helper PHP-file. That includes passing SQL and getting it back as XML directly, working with attributes etc.

All feedback is very welcome!

Hashes: #kohana xml module #kohana module #kohana #xml #php

2009-10-12

postgreSQL crash course

As I was searching for a INNER JOIN problem in postgreSQL, I ran across this must awsome guide. With examples and all. Easy to overview. Starting from a very basic level, increasing to very in depth knowledge of postgres inner workings.

http://www.commandprompt.com/ppbook/x5802

Hashes: #postgreSQL #database #postgre #SQL

Port Forwarding in Ubuntu with iptables

Assuming your ubuntu box already have NAT up and running, and you wish to connect directly to the internet from a machine behind your Router (Ubuntu, GNU/Linux-box).

iptables -A PREROUTING -t nat -i ##incomming interface## -p tcp --dport ##incomming port## -j DNAT --to ##destination IP##:##destination port##

For example:
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 8080 -j DNAT --to 10.1.249.250:80

When I wanted to access a web server behind my Ubuntu NAT-router in my home. Now I can surf to #mydomain#:8080 to access that internal web server at port 80.

Hashes: #linux #ubuntu #nat #port forwarding #iptables