lunes, 28 de marzo de 2011

How to open port 80 for out connections to a specific user

sudo iptables -A ufw-user-output -p tcp --dport 80 -m owner \
--uid-owner pepito -j ACCEPT

jueves, 17 de marzo de 2011

Apache RewriteRule to Forbid (403) unknown URL requests

Write as the last rule:

# Everything else is forbidden
RewriteRule (.*) - [F,L]

jueves, 24 de febrero de 2011

martes, 15 de febrero de 2011

PAM authentication in PHP


sudo aptitude install php5-auth-pam
sudo cp /usr/share/doc/php5-auth-pam/examples/php /etc/pam.d/php


PHP example:

$error = 0;
if(pam_auth("zappedy", "XXXX", &$error))
echo "bien";
else
echo "mal $error";


Ref:
http://www.dokuwiki.org/auth:pam

miércoles, 19 de enero de 2011

MySQL slow queries

sudo mysqld_safe --timezone=+0:00 --long_query_time=1 --log-slow-queries=/tmp/slow.log --log-queries-not-using-indexes

Sort by Rows_examined:

grep Query_time /tmp/slow.log |sort -n -k9
# Query_time: 0.007019 Lock_time: 0.000098 Rows_sent: 0 Rows_examined: 65
# Query_time: 0.001595 Lock_time: 0.000042 Rows_sent: 0 Rows_examined: 66
# Query_time: 0.002316 Lock_time: 0.000101 Rows_sent: 0 Rows_examined: 72
# Query_time: 0.003357 Lock_time: 0.000380 Rows_sent: 0 Rows_examined: 83
# Query_time: 0.003342 Lock_time: 0.000403 Rows_sent: 0 Rows_examined: 116
# Query_time: 0.004729 Lock_time: 0.000319 Rows_sent: 0 Rows_examined: 116
# Query_time: 0.002406 Lock_time: 0.000043 Rows_sent: 0 Rows_examined: 205

jueves, 13 de enero de 2011

Unit Tests' value in TDD

Hierarchy of tests:
  • Acceptance: Does the whole system work?
  • Integration: Does our code work against code we can't change?
  • Unit: Do our objects do the right thing, are they convenient to work with?

Unit Tests' value in TDD:
  • Write loosely coupled components
  • Detect errors while the context is fresh in our mind
  • Add an executable description of what the code does (documentation)
  • Focus: discouraging unnecessary features
  • Rythm: tests tell what to do next
  • Trust: tests give a reason to trust you
ref:
- Extreme Programming Explained
- Growing Object-Oriented Software, Guided by Tests

miércoles, 1 de septiembre de 2010

Brooks's law

adding manpower to a late software project makes it later