creating fractals in javascript

Posted: June 19th, 2010 | Author: sofia | Filed under: curious, open | Tags: , | No Comments »

Just found out about the Context Free Art project through it’s javascript port, ContextFree.js done by Aza Raskin, the same guy involved in the development of Firefox. Raskin developed a lovely playful site, Algorithm Ink. I actually showed it to a friend who’s not a developer and she started playing right away : )

Here’s an example: http://azarask.in/projects/algorithm-ink/#aa486456 . Click browse to see lots more.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Mixx
  • Google
  • description

how to install munin on rhel

Posted: March 13th, 2010 | Author: sofia | Filed under: useful | Tags: , , | No Comments »

Just jotting down all the steps I took to install Munin on a RHEL server:

  1. Login as root
  2. Add the Epel Repository
    $ sudo rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
  3. $ sudo yum install munin munin-node
    Dont forget to say yes on all checks. I got distracted by the phone and when I looked again I had a missing dependency error.
  4. Edit munin’s conf file
    $ vim /etc/munin/munin.conf
  5. Set up mail alerts when a status change occurs (eg from OK to warning)
    contact.sofia.command mail -s “Munin notification” sofia@example.com
  6. Notice the line
    # htmldir /var/www/html/munin
    This will set where munin’s reports will beaccessible by the web browser. Change it (and uncomment it) if you want but make sure the folder you set it is writable by munin (chown -R munin <directory>). I had some problems here, Munin didnt create the files there so i set up an alias. But maybe you’ll be fine : )
  7. Write and close munin.conf. Edit munin-node
    $ vim /etc/munin/munin-node.conf
  8. Change the host entry from
    host *
    to
    host 127.0.0.1
    In this way you restrict the node to listen to localhost only
  9. Start munin
    $ sudo /etc/init.d/munin-node start
  10. Add munin to reboot
    $ sudo /sbin/chkconfig munin-node on
  11. Set up the alias. My public directory isnt there so I needed to set up an alias in httpd.conf
    $ vim /etc/httpd/conf/httpd.conf
  12. Add the below at the end adjusting what you need
    Alias /srvmunin /var/www/html/munin
    <Directory /var/www/html/munin>
        Options FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    
        AuthType Basic
        AuthName "Members Only"
        AuthUserFile /etc/munin/munin-htpasswd
        <limit GET PUT POST>
        Require user admin
        </limit>
    </Directory>

    Notice we set the alias at srvmunin, so that the reports will be viewable at www.example.com/srvmunin. We also set an httpauth because otherwise anyone can see the munin reports.

  13. Write and close and restart apache
    $ /sbin/service httpd stop
    $ /sbin/service httpd start
    Someone told me this was quicker than a restart (service httpd restart) but I have no idea if it’s true
  14. Set up the password
    $ htpasswd -c /etc/munin/munin-htpasswd admin
  15. Go to www.example.com/srvmunin and you should be prompted for the password. Then wait a few hours and you’ll start to see the charts. Done!

This was heavily taken from slicehost’s article on munin so if anything goes wrong check there as well.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Mixx
  • Google
  • description

NLP e Língua Portuguesa

Posted: November 24th, 2009 | Author: sofia | Filed under: curious | Tags: , , | 1 Comment »

Desde há algum tempo que tenho alguma curiosidade sobre NLP (natural language processing) tanto a nível teórico (como funcionam os algoritmos que usam) como a nivel prático. Não existe por exemplo, um serviço semelhante ao Apture para português. Assim, derivados das minhas pesquisas aqui vão alguns links que achei interessantes:

LXSuite - um conjunto de webservices para a análise linguística de texto desenvolvido pela Universidade Lisboa. Na LxSuite estão todos juntos mas podem ser vistos em separado no LxCenter. Infelizmente, o serviço não tem api e é necessário consentimento para o seu uso.

LXService:  Web Services of Language Technology for Portuguese - artigo a descrever o desenvolvimento dos webservices acima.

Linguateca - todo um conjunto de recursos de NLP para a língua portuguesa. O HAREM - NER for portuguese e respectivo livro está aqui. Eles também disponibilizam vários corpus para português aqui, inclusivé o CETEMPúblico (disponível para download gratuitamente).

Portuguese Language Processing Service - um artigo sobre o desenvolvimento dum conjunto de webservices de NLP para língua portuguesa desenvolvido no Brasil. De acordo com os próprios:

In this paper, we describe F-EXT-WS, a Portuguese Language Processing Service that is now available at the Web. The first version of this service provides Part-of-Speech Tagging, Noun Phrase Chunking and Named Entity Recognition. All these tools were built with the Entropy Guided Transformation Learning algorithm, a state-of-the-art Machine Learning algorithm for such tasks.

Este artigo parece interessante e pode ser um ponto de partida para outras explorações (ex. ETL/Entropy Guided Transformation Learning - ver Portuguese corpus-based learning using ETL). Fui ver o F-EXT-WS mas é necessário registo e deu erro.

Alguém conhece outros recursos interessantes dentro desta àrea?

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Mixx
  • Google
  • description

Sixth Sense

Posted: November 21st, 2009 | Author: sofia | Filed under: creative, humane, useful | Tags: , | No Comments »

This is truly amazing..

And another interesting find: LED tattoos

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Mixx
  • Google
  • description

Links on tdd, css & others

Posted: March 1st, 2009 | Author: sofia | Filed under: Uncategorized | 1 Comment »
  • Doctest - runnable tests inside the docstrings (php pear package)
  • Mutation testing 

    “Mutation Testing is basically testing…for tests. It ensures that your tests are truly capable of detecting errors and problems with the source code. It does this by mutating the source code itself (using ext/runkit) in such a way that an error is created in the code. If your tests detect the error, all is well with the world. If your tests do not detect the error…well, you better add a new test that does” 

  • Phpcp

    “phpcpd is a Copy/Paste Detector (CPD) for PHP code.

    The goal of phpcpd is not not to replace more sophisticated tools such as phpcs, pdepend, or phpmd, but rather to provide an alternative to them when you just need to get a quick overview of duplicated code in a project.”

  • Object oriented CSS

    “OOCSS allows you to write fast, maintainable, standards-based front end code.” 

  • Bespin

    Bespin is a Mozilla Labs experiment on how to build an extensible Web code editor using HTML 5 technology.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Mixx
  • Google
  • description

Doctests for php - test & create documentation

Posted: March 1st, 2009 | Author: sofia | Filed under: useful | Tags: | No Comments »

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,

  • write a test case in doctest
  • write the code itself
  • test
  • repeat as necessary

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 think doctests are a really easy way to start writing tests. If you’re like me and also use phpUnit, it’s easy to write an AllTests file that runs both the doctest tests and the phpunit tests.

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 ):

  • it makes unit tests writing easier and quicker -> easy to test as you go
  • it ensures that docstrings are up-to-date by verifying that all examples work as documented -> a sort of testable documentation
  • it enforces writing of tutorial documentation, liberally illustrated with input-output examples.

Cons:

  • If placed inline and used as the only method of unit-testing they can easily clutter the code. 

Wishlist for the php package:

  • Ability to enter into interactive mode inside a doctest (interlude recently added this ability in python) 
  • Allow the inclusion of standalone test files (*) - right now asfaik it only allows for the expected values to be in another file, like this: 


    * <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.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Mixx
  • Google
  • description

How to check if mod_deflate is enabled

Posted: January 17th, 2009 | Author: sofia | Filed under: useful | Tags: | No Comments »

Here are 2 links that allow you to check if mod_deflate is enabled:

port80’s tools

what’s my ip mod gzip tester

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.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Mixx
  • Google
  • description

quick setup instructions for profiling php scripts on a mac with xdebug + webgrind

Posted: November 25th, 2008 | Author: sofia | Filed under: useful | Tags: , , , , | No Comments »

These instructions are for xampp on a mac.

  1. Download xdebug.so from activestate (thank you Komodo)
  2. Copy xdebug.so (choose the correct xdebug according to your php version) to xampp/xamppfiles/lib/php/php5/extensions/no-debug-non-zts-########/xdebug.so .
  3. Configure php.ini:
    At the end of php.ini (it’s in xampp/etc/php.ini) add

    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.

  4. Run php info & check xdebug’s there.
    If you get ‘could not load.. (null)’ you probably downloaded the wrong version for your mac. Also check the path to xdebug is correct (the no-debug-non-zts-####### part might be different)
  5. Install webgrind: download from here and copy directory to xampp/xamppfiles/htdocs folder
  6. Visit your script with ?XDEBUG_PROFILE=1 appended to the end of the url. Eg http://localhost/myapp/index.php?XDEBUG_PROFILE=1
  7. Now navigate to webgrind (eg. http://localhost/webgrind/ ), select the correct file from the dropdown - you can see the files xdebug’s created in yout /tmp directory -  and you should see the profiling info.
  8. Done!

Sources:

Might be interesting:

http://www.maccallgrind.com/

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Mixx
  • Google
  • description

ipod touch apps

Posted: November 5th, 2008 | Author: sofia | Filed under: useful | Tags: , , | 3 Comments »

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 :)

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Mixx
  • Google
  • description

Ubiquity para páginas amarelas e dicionário priberam

Posted: September 18th, 2008 | Author: sofia | Filed under: simple, useful | Tags: , , | 9 Comments »

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).]

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Mixx
  • Google
  • description