Ubuntu Linux on Acer Aspire AO751h

August 9th, 2010

Don’t use the Ubuntu Netbook Remix but the Desktop version.

To fix the monitor resolution:
https://wiki.ubuntu.com/HardwareSupportComponentsVideoCardsPoulsbo/

Wi-fi should work out of the box

Process forking in PHP on Linux

August 3rd, 2010

Command Line with PHP

_ Introduced with PHP 4.3 (2002-12-27)
_ PHP packed with very useful functions: exec, shell_exec, passthru
_ PEAR package Console_CommandLine to easily handle arguments and options
_ You can do system administration and release management with a language you already know
_ Bad: if you run very long and complex processes (i.e. Parsing XML files into database), you can experience memory leaks
_ Bad: PHP is mainly for running short scripts to serve web pages so core developers focus time on that
_ Those issues are going to be addressed soon (something already done as of 5.3)

MultiProcess programming with PHP
_ ps auxf to see the parent/child process tree
_ There are basically 2 methods:
__ pcntl_fork()
__ exec

  • http://www.electrictoolbox.com/article/php/process-forking/
  • http://www.rooftopsolutions.nl/article/213
  • http://dev.mysql.com/doc/refman/5.1/en/gone-away.html (search for fork)
  • See the PHP ProcessControl class

How to benchmark apache+php

August 3rd, 2010

This is to see whether you server is CPU-bound or RAM-bound.

We have to stress it and see which one of those components gets saturated first.

If that is the RAM, we can add easily more RAM. The amount of RAM to add depends of the share of the CPU that can still be used before the website becomes slow.

ab -n 300 -c 1 http://www.mywebsite.com

This are the command to run during the stress test

_ uptime

_ free

_ ps -ylC httpd –sort:rss > number_of_apache_processes.txt

_ netstat -nt | grep :80 | wc -l

And obviously check how quick the website is.

Create video tutorial

August 3rd, 2010

_ recordmydesktop (CONTROL-C to stop)

_ mencoder out.ogv -o out.avi -ovc lavc -oac pcm

_ avidemux

__ cut start

__ cut end

__ don’t crop the video

__ video: mpeg4 (x264)

__ format: AVI

__ add subtitles (if any)

__ save

__ upload to Youtube

Linux command Line - copy a file from remote to local

August 3rd, 2010

Copy a file from a remote location to a local directory (for example to burn a backup on DVD):

scp backups@server1:backup20100105 local/path

Android - test application with different APIs

August 3rd, 2010

This is to change the device used by the emulator

Run button > its menu > Run configurations > Target tab

This is to change the actual API used for the application:

Menu > Project > Properties > Android >

How to make a transparent background/selection on an image using GIMP

August 3rd, 2010

http://geekswithblogs.net/TimH/archive/2006/03/20/72797.aspx

PHP Conference - London 2010 - Summary

August 3rd, 2010

Free notes from the PHP London Conference 2010  - http://www.phpconference.co.uk

Lost art of Simplicity by Josh Holmes (working in Microsoft)   -  http://www.slideshare.net/joshholmes/the-lost-art-of-simplicity - http://www.joshholmes.com/blog/2009/04/29/TheLostArtOfSimplicity.aspx
_ NIH (not invented here) syndrome   -  people want to develop everything internally
_ The focus shouldn’t be creating something from ground-up but putting together technologies in a way even their inventors didn’t think of
_ Simplicity is not a goal. It is the by-product of a good idea and modest expectation.
_ If it is right, you can explain it to non-technical people. Otherwise it means you haven’t understood it very well.
_ Don’t let the future complicate your present. Maybe that future you are envisaging is not going to happen
_ Get your users in the room. Be with you user while building a system to see what *they* need and expect

_ Within enterprises where are 2 complexity issues (the real one is not scalability): politics and religion (about OS, platform, …). Do *not* do technical choices based on those factors.
_ If you find yourself talking more than walking, shut up, cut the vision in half and launch the product. You can always fill in the gaps later. (Jason Fried)
_ You must understand your users and problems to avoid wasting time on unused features
_ Reuse is not always what you need. Sometimes a specific tool to solve a specific problem is better


AntiPHPPatterns
by Stefan Priebsch (PHP consultant)

_ List of common antipatterns:
__ gold hammer: try to use the same tool for too many things
__ copy&paste development
__ feature creep (proliferation of features)
__ software bloat (a lot of useless features, just because you have resources available)
__ spaghetti code
__ magic values
__ blind faith (= no checks on return values of methods)

__ proliferation of global constants

____ bad because you need to remember them, then you will probably end up replicating them
____ bad because they introduce dependencies
____ remedy: try to use class constants and, even better, provide setters (not getters) for attributes of a class instead of having the class depend on a constant.
class Something
{
protected $basePath = BASEPATH;

public function setBasePath($path)
{

}
}

instead of:

class Something
{
protected $basePath;

public function setBasePath($path)
{

}
}

Basically, remove the constant from the class, and require the caller to supply a sensible value for the base path.

__ God classes - they are classes that know too much. To promote re-usability you need to create dumb classes that don’t know anything about the application (i.e.: String Matcher)
Nowadays, PHP applications rely too much on Singletons because they are very convenient.
Singleton is bad because is like a glorified global variable (it is accessible from anywhere).
Singleton is very bad because creates dependencies and, even worse, you can’t find out those dependencies from the API. That makes testing very difficult.
The cure is the use of dependencies injection.
ORM is not always a good solution because, for example, creates a lot of queries.
The more coupled is your code, the more difficult will be to do testing.
PHP 5.3 in practice by Fabien Potencier

_ Sensio employ 70 people

_ Why 5.3? New features, much faster, uses less memory
_ What’s new in 5.3?
__ Namespaces
____ allow better interoperability and you can share the same autoloader with different projects.
____ actually the fully qualified class names are longer but you can use shortcuts using the keywords ‘use’ and ‘as’
__ Late static binding - for static classes
____ via the function get_called_class
____ it allows you to extend a singleton class (that wasn’t possible prior to PHP 5.3)
____ Anyway Singleton is not good because you can’t mock it for testing because it is hardcoded. Symfony 2.0 hasn’t got any singleton.
__ __callStatic  (like __call but for static methods)

__ anonymous functions

____ you can store a function in a variable $hello, and then call it like this: $hello() or call_user_func($hello)
____ useful with the array_* functions or anywhere you need to pass a callback function
____ a closure is an anonymous function that remembers the context when it was created
Dependencies injection is not easy in the day-to-day development because it is not very convenient.
The solution is to build a Dependency Injection Container. That is possible using closure.
Resources:
_ http://components.symfony-project.org/dependency-injection/documentation
_ pimple project on github - a simple 40-line dependency injection container
Hidden features in PHP by Johannes Schluter (release manager for PHP 5.3)
_ SPL (standard PHP Library) with data structures, exception classes, iterators - http://uk3.php.net/manual/en/book.spl.php
_ SPL iterators
__ to work on a collection of items (similar to an array)
__ you can chain iterators
__ you can use FilterIterator to remove elements from the collection
perform MySQL queries asynchronously
__ use $link->query(“SELECT ‘test’”, MYSQLI_ASYNC);  together with mysqli_poll
_ streams
__ stream is a resource object which exhibits streamable behavior. That is, it can be read from or written to in a linear fashion, and may be able to fseek() to an arbitrary locations within the stream
__ very useful with file_get_contents: http://fabien.potencier.org/article/20/tweeting-from-php
__ new classes for date&time manipulation: http://php.net/manual/en/book.datetime.php
_ php -a   -  to get an interactive shell
_ inclued()  -   Traces through and dumps the hierarchy of file inclusions and class inheritance at runtime.
_ APC can be used to get the status of an upload
_ How to implement method overloading in PHP?
__ using the __call method with func_get_args
__ creating different methods with similar names
‘In search of…’ - integrating site search systems

by Ian Barber (PHP consultant for Ibuildings)

_ You can develop a search engine for your website using Google but:
___ Google can’t see your intranet
___ the Google crawler will not index new content immediately
___ maybe you want more control over the indexing

_ Technologies for implementing a search:
_ MySQL fulltext (not so good but easy)
_ Swish-e
_ Lucene (as it is written in PHP you can have problem with memory with very big datasets)
_ Xapian
_ Sphinx
_ Solr
___ High-scale: Nutch
___ High-scale: Hadoop

PHP on the D-BUS

by Derick Rethans

_ D-BUS is part of the Freedesktop.org
_ D-BUS to talk with desktop apps
_ derick at php.net

Checklist before releasing Android app

August 3rd, 2010

_ Cross-Android-API testing
_ Securing Your Private Key
_ Versioning Your Application
http://developer.android.com/guide/publishing/versioning.html

_Specifying Your Application’s System API Requirements
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html

_ http://developer.android.com/guide/publishing/preparing.html
_ http://developer.android.com/guide/publishing/publishing.html

PHP - Plurilize

August 3rd, 2010

This is a very good post:

http://kuwamoto.org/2007/12/17/improved-pluralizing-in-php-actionscript-and-ror/

We have test it in the office and it works great!