Sixth Sense
Posted: November 21st, 2009 | Author: sofia | Filed under: creative, humane, useful | Tags: gadgets, sixth sense | No Comments »This is truly amazing..
And another interesting find: LED tattoos
This is truly amazing..
And another interesting find: LED tattoos
Recently I found out about doctests in php. Doctests are tests you can put inside the docblock of the class or method. They originated in python but now there’s a ruby implementation, a php implementation and even a javascript implementation.
An example will explain better (applies to the php package):
class simplemath
{
/**
* subtract function.
*
* @access public
* @param int $a
* @param int $b
* @return int
*
* <code>
* //doctest: subtract
* echo simplemath::subtract(10,6);
* //expects:
* //4
* </code>
*/
public static function subtract($a, $b)
{
return (int)$a - (int)$b;
}
}
The test itself is inside the <code> tags. If I then run this code through doctest’s commandline runner for php, by running
$ phpdt simplemath.php
I’ll get something like this:
Doctests can serve as great documentation by example and as tests, both for your documentation - comments tend to get terribly out of date (when code changes the comments aren’t updated accordingly) - and for the code itself.
I’ve also found they’re an invaluable tool during development. Imagine you’re developing a method that validates credit card numbers and the only way to get to it in a browser is to perform several actions, eg going to the specific webpage, inputting the credit card number, and submitting the form - it’s hell basically. If you’re already doing TDD and using phpUnit you’re probably not doing this but doctest for me has an advantage there, the test and the code being tested are in the same file - it’s all there! and so it’s really easy to grasp the problem at hand.
My process has been,
Due to this I submitted a patch to allow the testing of only 1 test, it’s not in the current release but it’s been accepted. This way instead of waiting for all the tests to run, i can run only the method I’m working on.
Another cool thing about it is you become aware of any initial setup code and dependencies. Look at the following:
/**
* Calculates the number of nights between the start and end date of the booking
* @return int
*
* <code>
* // doctest: booker->total_nights
* require_once('lib/utilities.class.php');
* $booker = new booker();
* $booker->startDate = '2009-02-23';
* $booker->endDate = '2009-02-26';
* echo $booker->total_nights(). "\n";
* // expects:
* // 3
* </code>
*
*/
public function total_nights()
{
if (!isset($this->startDate) || !isset($this->endDate)) {
return false;
}
return (int)utilities::date_diff($this->startDate,$this->endDate,'d');
}
Even without the rest of the class it’s immediately visible that this method requires that the start and end dates be set and the inclusion of another class.
I view doctest as unitestting in its simplest form, there’s no setup/teardown methods, no mocks, etc. But since not all classes need all that, that’s fine by me. You can use doctest and phpunit/simpletest side by side. This way you have tests for code and tests for documentation
Doctests pros (more or less from the php-doctest documentation ):
Cons:
Wishlist for the php package:
* <code>
* //doctest: add
* echo simplemath::add(3,2);
* echo simplemath::add(5,2);
* // expects-file: atestfile.txt
* </code>
Hope it’s as useful to you as it’s been to me
* Update: I submitted a patch to allow for this, so if it’s accepted, it will be possible soon.
Here are 2 links that allow you to check if mod_deflate is enabled:
You can also use YSlow + Firebug but I ran into a strange problem where YSlow did not detect the compressed content (gave an F on gzip components) when I knew I was actually compressing content. I then looked around for other tools and found those 2 which detected the compression correctly. So lesson learned, use several tools to validate compression - just to make sure.
These instructions are for xampp on a mac.
zend_extension=/Applications/xampp/xamppfiles/lib/php/php5/extensions/no-debug-non-zts-20060613/xdebug.so
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_host = localhost
xdebug.show_local_vars=1
xdebug.dump.SERVER=HTTP_HOST, SERVER_NAME
xdebug.dump_globals=On
xdebug.collect_params=4
xdebug.profiler_enable=On
xdebug.profiler_enable_trigger=On
xdebug.profiler_output_name=”%p-%R”
The “xdebug.profiler_output_name=”%p-%R”" sets the file name to process pid (default) + “-” + the REQUEST URI (helpful if you’re rewriting urls). The xdebug.dump commands are not for profiling but they improve var_dump & error messages. Check zend’s article series on xdebug for more info.
no-debug-non-zts-####### part might be different)Sources:
Might be interesting:
Since i’ve got my ipod touch, i’ve been trying out several applications. Some have sticked, others less. So here’s my current favorite list along with a few comments.
Stanza provides the best reading experience of all the ereaders i’ve tried (stanza, filemagnet, instapaper, ereader) . A feature suggestion: I really would like the ability to add notes on any page or at least to underline/highlight text. Highlighting would really be nice - it just makes the reading experience much better. Basically the physical action of highlighting makes it easier for me to process the information and remember it later.
A note on page turning: Stanza is the only app where you press the left/right side of the screen to go to the previous/next page which would be fine if everyone else was doing it as well. As it is, I frequently scroll down and then wonder why nothing’s happening. I actually would like for everyone else to use Stanza’s method - it just jumps to the exact spot you were on which is less tiring on the eyes.
Stanza Pros: free; good readability. Cons: Most pdfs i tried to convert were not converted correctly making the app much less usable than i initially thought. Especially images and indexes are really poorly converted. So the search for a decent experience on reading my pdf’s went on which led me to the next app.
FileMagnet - a file manager for the ipod/iphone. Does what it’s supposed to do allowing the ipod work like a thumb drive. Cons: Frequent warnings on low memory when reading large pdfs and much poorer reading experience than stanza. Price:3.99€. Pros: Everything that i can’t read on Stanza, i read here. Useful.
Instapaper - simple app for saving pages and then reading offline. This is probably the app i use the most now along with itunes. Free and paid version. No real cons.
SmartTime - an app i really appreciate. A todo list + calendar: it’s been done a thousand times before but they actually innovated in the ui. Cons: no integration with google calendar, no export/import.
Writing Pad - another innovator. Instead of the default experience we have on small software devices where we click letter after letter to write, we now basically draw a line in between all the letters - this simple difference makes the writing experience a bit less clumky and much faster. I’ve gotten so used to it that i miss it in other apps where i write. A really good idea for writing on small devices (and they’ve filed a patent).
Accountr - a simple app for finance management. Didn’t really like it at first but it’s really quick to register stuff and i keep using it so that’s a good sign. Price: 0.79€
I could also mention others like Evernote but those are the ones i’m using the most now. Suggestions welcome ![]()
Para me divertir e porque me era útil decidi criar 2 comandos ubiquity para o firefox, um para o pai.pt e outro para o dicionário priberam.
O pai.pt foi fácil, bastou usar o searchCommand et voilá:
makeSearchCommand({
name: "pai",
url: "http://pai.pt/search/{QUERY}.html",
icon: "http://pai.pt/favicon.ico",
description: "Pesquisa nas páginas amarelas (pai.pt); Seaches the portuguese yellow pages."
});
No caso do dicionário priberam a coisa foi um pouco mais trabalhosa, primeiro tudo aquilo funciona à base de javascript no site (após alguma leitura do código lá percebi que faziam à mesma um pedido GET) e depois porque foi necessário codificar os parametros GET porque palavras com acentos estavam a falhar. Neste caso tive que usar o createCommand pois por enquanto não é possível escapar os parâmetros GET no searchCommand.
CmdUtils.CreateCommand({
name: "priberam",
description: "Searches the portuguese dictionary priberam",
help: "Try issuing "priberam aglet"",
icon: "http://priberam.pt/favicon.ico",
takes: {"pal": noun_arb_text},
execute: function( directObj ) {
var word = directObj.text;
Utils.openUrlInBrowser( "http://priberam.pt/dlpo/definir_resultados.aspx?pal=" + escape(word) );
}
});
O comando das páginas amarelas está aqui (comando pai) e o da priberam está aqui (comando priberam).
[Update: Acabei de reparar que o Rui Moura já tinha construído um comando para o dicionário priberam aqui. De qualquer modo, ao menos não são iguais porque a versão dele usa o searchCommand e como tal falha no caso de palavras com acentos ou caracteres especiais, ex. doçura.]
[Update 2: O Miguel Pais tem a versão mais completa neste momento (instalar aqui), com preview e também lida bem com caracteres especiais. Vejam os comentários abaixo.]
[For the english readers: to sum it up, when you need to escape accented characters in the query parameter use createCommand instead of searchCommand; see example code above).]
Those that decided to try out the chrome cross over port on their macs probably noticed that when chrome is first run, it strongly encourages the installation of quartz-wm included in Apple X11, in turn included in the cd. First i tried to reinstall X11 but it said i had a newer version so tried this tip that proved helpful 10.4: Provide Crossover with a missing quartz-wm and curiosity satisfied (hmm.. probably killed the cat and a bit of my time as well), i now have a working chrome in my mac.
Just a quick tip for those that want to use phpSecurityScanner but also use xampp/mampp. By default the scanner uses the local mysql server but since i’m used to xampp i wanted to use its mysql server.
So when i first ran the tool i got
[nativecode=Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)]
which was natural since what i’d started was xampp. To fix this i just added to bin/config.php, right after set_include_path, the following :
ini_set(’mysql.default_socket’,'/Applications/xampp/xamppfiles/var/mysql/mysql.sock’);
There are several caching strategies in web application development:
Page caching is the fastest method since the webserver can serve the html page directly allowing for the web app to be totally bypassed.
The idea is if a page is cached then the webserver detects that it exists in the cache folder and displays it, if the page doesn’t exist then the request continues to the web application which will render the page and save it to cache.
So how can the webserver detect this? Well, modrewrite to the rescue :=)
Here’s the snippet that makes it all possible:
[code]
IndexIgnore *
DirectoryIndex index.php index.html
Options +FollowSymLinks
RewriteEngine On
#if the request is domain.com/about, it will check if domain.com/cachehtml/about.html exists, if so displays it
RewriteCond %{DOCUMENT_ROOT}/cachehtml/$1.html -f
RewriteRule ^([a-z_-]+)$ cachehtml/$1.html [NC,QSA,L]
#goes one level deep
#if the request is domain.com/blog/hello-world, it will check if domain.com/cachehtml/blog/hello-world.html exists, if so displays it
RewriteCond %{DOCUMENT_ROOT}/cachehtml/$1/$2.html -f
RewriteRule ^([a-z_-]+)/([a-z_-]+)$ cachehtml/$1/$2.html [NC,QSA,L]
[/code]
The code above implies we are at the root. If not just add the folder name so that
RewriteCond %{DOCUMENT_ROOT}/cachehtml/$1.html -f
becomes
RewriteCond %{DOCUMENT_ROOT}/mysite/cachehtml/$1.html -f