Happy New Year

January 1, 2013 | Leave a Comment

2012 in a glance


Piwik is an open source Google Analytics like tool. Normally, it works by setting up piwik and adding a tracking code (JS or PHP or any code able to call the API) to record your site’s or app’s usage.
Another option is to use piwik to analyze your webserver’s logs to generate tracking infos for all your websites.

Here is how to set this up :

  1. Download the project : http://piwik.org/latest.zip
  2. Unzip the archive in your webroot
  3. Browse to yourserver.yourdomain.com/piwik (or the URL your setup piwik at).
  4. Follow the installation steps (database setup and first site creation). Follow the steps and click next on the code tracking page. We will not use this information in this setup.
  5. Once the setup is done, you need to run the script which will read the access.log file and generate usage data.
    The command looks like this

    1
    python /path/to/piwik/misc/log-analytics/import_logs.py --url=http://yourserver.yourdomain.net/piwik --add-sites-new-hosts /var/log/apache2/other_vhosts_access.log

    Replace /var/log/apache2/other_vhosts_access.log with the path to your apache access.log or apache vhost access logs.

  6. Browse to your piwik installation again and you should see your stats.
  7. If everything works fine, you should add a daily task to run this script (using cron)
    1
    crontab -e

    Add a line similar to

    1
    0 6 * * *  python /path/to/piwik/misc/log-analytics/import_logs.py --url=http://yourserver.yourdomain.net/piwik --add-sites-new-hosts /var/log/apache2/other_vhosts_access.log
Note : 
If your piwik is setup in an admin vhost of your server you might get an Authentication Required message when running the script. You should modify your vhost and allow access from the server’s IP.
1
2
3
Satisfy Any</div>
<div>Allow from XX.XX.XX.XX</div>
<div>
That should be all. More information can be found in piwik’s official documentation.

Livebox and Freebox are DSL box provided by Orange and Free Internet providers to their customers in France. These  boxes allow their owners to connect to the Internet (DSL), create a home network (router, wifi access point), make Voice Over IP calls and watch TV. They are known in France as “quadruple play boxes” and were first released by Free.

Anyway, because these equipments are for French users, I’ll write this one in French.

Comment connecteur les sous-réseaux d’une Livebox et d’une Freebox ?

Comme j’ai la chance de travailler depuis la maison, je dépends professionnellement d’Internet, il est donc capital pour moi que ma connexion fonctionne en permanence.

Comme j’ai en plus la chance de ne pas vivre en zone urbaine, je n’ai pas un débit très important (je suis bien loin des 12Mbps que j’avais au minimum lorsque j’habitais en Ile de France).

Pour ces deux raisons, j’ai deux lignes téléphoniques (deux lignes physiques distinctes entre France Telecom et la maison) et deux abonnements Internet : un avec Orange (livebox, pas d’option TV, débit max autour de 3Mbps) et une avec Free (Freebox Revolution sur une ligne fraichement degroupee et un debit maximum de 5 Mbps).

L’ordi pro est connecté à la Livebox, les ordis persos, iPhones et la Freebox Player passent par la Freebox Revolution. Comme ça, en cas de souci technique chez un opérateur, je peux basculer sur l’autre et surtout, un téléchargement d’une update de Mac OS X sur mon ordi perso ne vient pas perturber mes svn up sur l’ordi pro.

Il me restait un souci, l’ordi pro et les ordis persos ne pouvaient pas communiquer (pas d’accès au disque dur de musique de la maison par exemple).

Jusqu’à ce que je trouve la solution suivante :

Tout d’abord j’ai utilisé un outil pour déterminer les adresses et masques de sous-réseau à utiliser pour créer deux sous-réseaux en 192.168.x.x

Ensuite, j’ai configuré la Livebox pour qu’elle utilise le premier sous-réseau. L’ordi pro aura donc une IP en 192.168.1.X avec X > 1 et X < 126.

Puis, j’ai configuré la Freebox pour qu’elle utilise l’autre sous-réseau et, au niveau du DHCP, elle n’assignera que des IP en 192.168.1.X avec X > 126 et X < 253.

Il restait plus qu’un seul problème, permettre les échanges entre les deux sous-réseaux. Pour une fois, la solution ne se trouve pas implémentée chez Free (??!!) mais dans la Livebox (les appels sur mobiles ne sont pas gratuits, y a pas la TV mais … ) avec l’option de routage.

Tout commence par le branchement d’un câble réseau entre un port ethernet de la Livebox à un port ethernet de la Freebox (un des ports RJ45 numérotés de 1 à 4 comme tout autre ordinateur de votre réseau)

Ensuite , pour ce qui est de la configuration, aller sur l’interface de gestion de la Livebox : http://<IP_Livebox>, entrez votre mot de passe admin et aller dans la partie Configuration.

De là, aller dans l’entrée Livebox puis Paramètres avancés (à gauche) puis dans l’onglet Routage (en haut à droite).

Ici, il faut ajouter une règle de routage :

  • réseau de destination : 192.168.1.128 (le sous-réseau de ma freebox)
  • masque de sous-réseau de destination : 255.255.255.12
  • passerelle : 192.168.1.X (l’IP interne de ma freebox)
  • interface : LAN
  • métrique : 0 (par défaut)
  • activation : activer
Ensuite, j’ai redémarré les équipements. D’abord les box puis les ordinateurs qui ont tous récupérés de nouvelles IP sur les bons sous-réseau puis j’ai pingé un ordi perso depuis l’ordi pro. Bingo !

J’imagine que ce n’est pas une architecture réseau très répandue mais j’espère que ce guide pourra servir à d’autres.

I have been on a the lookout for tools to help me validate source code quality for PHP. Since PHP isn’t compile, a lot of errors which would be detected by a compiler are not found until runtime. And some errors won’t be revealed runtime in a specific context. I already know and use PHPUnit to write unit tests but there are still some errors that could/should be detected without running a test with the right context. For example, I know the code below would generate a warning with Visual Studio.

1
2
3
4
if (isset($_GET["userId"]) {
$userId = (integer)$_GET["userId"];
}
$user = loadUser($userId);

That’s all good and fine when a userId is sent but what happens when there isn’t one ?

Visual Studio doesn’t recommend a variable declaration inside a if statement arguing that, if the code doesn’t enter the if, the variable won’t be defined. With that warning, then the code would have been, for example :

1
2
3
4
5
$userId = $currentUserId;
if (isset($_GET["userId"]) {
$userId = (integer)$_GET["userId"];
}
$user = loadUser($userId);

Anyway, my search lead me to try Phantm, a tool written in Scala that can be used to detect potential programming errors inside PHP applications. It will both work for small isolated script as well as full-blown applications. phantm stands for “PHp ANalyzer for Type Mistakes”.

 

It took me a little while to get it to run so here is the solution :

  1. Download the phantm release jar
  2. Download the JFlex jar
  3. Download and install Scala
  4. Run phantm with
    1
    scala -classpath JFlex.jar  phantm-1.0.6.jar /Users/samobk/Workspace/bktrunk/application/controllers/api/v3/ApiBaseController.php
I have found some issues with Phantm, especially the lack of support for PHP namespaces but I will investigate it some more and try to incorporate it to my development workflow.

That’s it, I have switched away from the flag ship text editor of all web dev running OS X. Why ?

I gave Sublime Text 2 a try after upgrading to Lion. With Lion, Textmate started acting quirky. I had display bugs when closing a tab sometimes. At first, I did’t care much for Sublime’s interface (and hated the icon) and as soon as Textmate 2 beta came out, I switched back to my usual editor. But, there is one thing I had got addiced to in the meantime : Sublime is fast, lightning fast. Switching from one file to another is a pleasure and with TextMate 2 it had become waaayyy to slow. And so, after reading this post about icon and looks tweaks, I switched – again.

 

Tweaking Sublime Text

The Icon

Even if the latest update came with an icon, I prefer to use the one by dmatarazzo (available on GitHub)

The Look ‘n’ Feel

I really liked the way TextMate 2 was going with its new interface and I find that the Soda look’n’feel for Sublime brings the same simplicity and efficiency to Sublime.

What makes switching to Sublime possible is that it supports TextMate’s bundles and themes so I imported Tomorrow from my Textmate to Sublime.

Sweetness Everywhere

I try to separate the work computer from the personal computer but it doesn’t mean I don’t code a little bit on the personal computer… So I like for my settings and packages to keep in sync. It was possible with TextMate using Dropbox and it still is possible with Sublime. Move packages, installed packages and pristine packages to Dropbox and create some symlinks.

Awesome Bundles and add-ons

I installed the Package Control and used to install the As Above package but that’s just a start because there are a bunch of cool packages in addition to the existing compatible TextMate bundles.

I installed these two snippets for JSON and XML formatting and validation.

One more thing

Setting up Sublime Text 2, I found this application that will generate themes for TextMate / Sublime Text.

 I upgraded to OS X Lion on release day (I’m more of a geek all the time) and I was very confused with iCal. It immediatly appeared that all the events I created were now set to “all day” by default and I found this very annoying (they used to be set for the default 10am to 12pm slot by default). Researching a way to customize the default length for new events I found out that, new events will be created with start and end dates based on their labels.

Simply create an event titled Sprint 3 meeting from 2 to 4 pm and it will create the event Sprint 3 meeting and assign it the right information. I thought this was awesome and wondered how Apple came up with this feature and why they took the time to focus on this. Then, I saw the iOS 5 keynote and met Siri. Now it all makes sense and I am eager to hire my virtual personal assistant.

Steve Jobs was a visionary. The respect he got from the tech industry is well deserved.

If you are using Mail.app and GMail you might have noticed that emails you read (in Mail.app) are counted as unread in your sidebar.

If you expend the labels in your sidebar, you will notice the unread emails all belong to the default imap GMail labels :

I’ve finally found how to fix this. Simply log in your GMail account and go to your Mail Settings. Click on the Labels tab and uncheck all the “Show in Inbox” boxes for all the GMail “System Labels” except Inbox (which is grayed out anyway)

Back in Mail.app, right click on your account in the list in the left pane and click on Syncronize account. It will update the labels counts and everything will “look better”.

Just a quick note on how to achieve the following purpose. Say you have a 3 months old baby and your mother sends you a 3 month old birthday ecard. Say you wish to download the animation of that ecard and share it on the blog you keep for your family and close friends. I suppose this is “everyday computing” for the rest of them.

Anyway, here is how it is done :

  1. In firefox, you can find the swf animation easily. simply type about:cache in the address bar and locate the swf. Copy it on your desktop or somewhere accessible.
    Warning:
    if you have NO CACHE at all showing when you type about:cache, you might be a web developer using web developer tools with cache disabled. Re-enabled it, re-watch your animation, now it will be in the cache.
  2. In WordPress, upload the swf by using the add media button. Obtain the attachement location by clicking the “Link to Media” button and, in “HTML” view, paste the following code (replace http://url/to/my.swf with the link to your media – twice) :
1
<object id="test1" width="600" height="458" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://url/to/my.swf" /><param name="pluginspage" value="http://www.adobe.com/go/getflashplayer" /><embed id="test1" width="600" height="458" type="application/x-shockwave-flash" src="http://url/to/my.swf" pluginspage="http://www.adobe.com/go/getflashplayer" /></object>

In case you are sharing a disk over network and you want it to be available on your Mac automatically at boot up, you can have it auto mount at login.

  1. Go to System Preferences > Users & Groups.
  2. Make sure your user is selected on the left and go to the Login Items tab
  3. Go to the Finder and press Cmd+K and connect to your network drive. Make sure to save the password to your keychain.
  4. A Finder window opens showing the content of your network drive. Press Cmd + up arrow key to go up a level
  5. Drag and Drop your network volume in the Login Items window
  6. Check the box Hide left to your Volume in the list so the window won’t open at every boot up
  7. Close the System Preferences, you’re all set

A quick note on how to share a USB drive over your private network (Network Attached Storage) using a router running on the DD-WRT firmware. Needless to say, your router needs to have a USB port for this feature to be enabled in the firmware.

  1. Plug the drive in your router USB port and turn it on
  2. Simply login to your router administration console (default credentials are root:admin)
  3. Go to the Services tab.
  4. Go to the USB sub tab and enable the core USB support and the USB storage support. Also, I recommend enabling the auto drive mount.
  5. Select your disk mount point i.e. /mnt and apply settings
  6. The router will mount the drive and give you information about your device
  7. Go to the NAS sub tab and enable the Samba sharing (or FTP if you so desire). Enter your workgroup information and create a share. It should look as follow :
    Path /mnt
    Name nDrive (enter what you want there)
    Public unchecked (you can check this box if you don’t wish any user management for your data)
    Access Read/Write (you can change this to Read Only)
  8. Below, create users and give them access to your device.
That’s all. The DD-WRT makes administration straightforward and, for those who have several routers, it also can make it constant across different devices.

<< Previous PageNext Page >>

  • About Me


    photo of Samantha Halfon Samantha Halfon
    Software Engineer
    blueKiwi software
    Paris, France
    I enjoy playing with my computer(s), listening to Bob Dylan (and related artists) and watching movies (especially if they were directed by Martin Scorsese or John Cassavetes). Sometimes, I play a little guitar... If not doing any of the above, I am either riding a small red bike around Paris, or, making videos. About my videomaking please check out World Wide Angle and its blog.