svn remove –keep-local Comments Off

tout est dans le titre !
pour ne plus versionner des fichiers sur voter projets sans pour autant les supprimer du disque local utilisez la commande magique
svn remove --keep-local ./the/file/i/should/not/commit.ext

Tags: svn, sysadmin, tips

Disctinct IP details in apache access.log 1

awk 'NR<=10000{a[$1]++; }END{for (i in a) printf "%-6d  %s\n",a[i], i |"sort -n"}' access.log

Tags: script, sysadmin, tips

Réinstallation complète de macosx, comment bien configurer son environnement Comments Off

Suite à un crash de disque dur (paix à son âme) je profite de cette install tout fraîche de macosx 10.6 pour bien configurer mon environnement.

Pour mémo:

  • Autoriser l’accès SSH sur la machine (pref système > partage > session à distance)
  • créer un fichier /.profile
  • créer un dossier ~/bin
  • dans ~.profile, personnaliser le PATH comme suit :export PATH=~/bin:$PATH
  • mettre dans ~/bin les liens symbolique et script utiles
    1. contrôle d’itunes (http://gist.github.com/184838)
    2. contrôle du volume (http://gist.github.com/184840)
    3. cd ~/bin && ln -s /Applications/MAMP/bin/php5/php php
    4. ln -s /Applications/MAMP/Library/bin/mysqladmin mysqladmin
      ln -s /Applications/MAMP/Library/bin/mysql mysql
      ln -s /Applications/MAMP/Library/bin/mysqldump mysqldump
    5. etc …
  • virer les applications hadoc de /usr/bin (php au hasard)

Bon évidemment l’idéal aurait été de faire un Rsync du dernier backup sur la lunxbox mais bon c’ets moins marrant ;-)

Tags: Apple, bonne pratiques, gist, Macosx, MAMP, mysql, PHP, rsync, script, SSH, sysadmin, tips

Safari ne trouve pas Adobe PDF Viewer Comments Off

Depuis quelques temps, impossible d’ouvrir un PDF dans safari sans devoir manuellement sélectionner l’emplacement de Adobe PDF Viewer. À l’origine, Safari ouvre les PDF avec aperçu, plutôt pratique quand on connait la différence énorme de performance de Aperçu et Adobe PDF viewer, en faveur d’Aperçu.

La solution est simple :
ouvrez un terminal et naviguez jusqu’à “Macintosh HD -> Library -> Internet Plug-Ins”
cd /Library/Internet\ Plug-Ins/
puis
rm -Rf AdobePDFViewer.plugin/
un petit redémarrage de Safari et le tour est joué.

Display PDF in Safari with aperçu

Display PDF in Safari with aperçu


src : macgeneration

Tags: Apple, Macosx, PDF, Safari, tips

Evaluate the similarity between objects through a “many to many” SQL relation Comments Off

RelationsIn many database-based projects you have to show your visitors that this “thing” is similar to this other one. For example, this blog post is similar to this other one. That’s a crucial functionnality and at first sight it’s looks easy to create.

The landscape

let’s start with this basic example :
In a blog, a “blog_post” has many “tag”. These relations are stored in a “blog_post_tag” table. When a blog post is displayed, we want to show the list of similar post to the current blog_post. Our “blog_post_tag” table just store “blog_post_id” and “tag_id“.

The first train of thought

I wanted to get all blog post that have the same associated tag. But, in this database-relation context “the same” may only mean only one of them. Quite annoying. So i finally get something that worked, and that was based on this kind of algorythm:

blogPostTags = $myBlogPost->getTags
postList = array()
foreach(blogPostTags as currentTag)
tempPostList = getAllBlogPostByTag(currentTag)
postList = array_merge(postList, array_diff(tempPostList,postList)
endforeach

Quite awfull isn’t it ? after two hours spent on something else and got back to home and discussed with friends (and whatever you want. Who said IT guy do not have a social life ?!) i just looked back at this problem and finally wrote this :

The proper way


SELECT COUNT(tag_id) as similarity, blog_post_id FROM blog_post_tag
WHERE tag_id IN (
SELECT tag_id FROM blog_post_tag WHERE blog_post_id = ?
)
GROUP BY blog_post_id

And that’s all. This SQL code gives you how many common tag you have between all the post that have at least on tag in common with a specific blog_post (replace ‘?’ by the correct value). Now just have to write it whith the Doctrine syntax ;-)

Conclusion

Just remember : when it sucks, just take a break !

Tags: devloppement, mysql, tips

Symfony : SQLSTATE[HY000]: General error: 1005 Can’t create table Comments Off

SQLSTATE[HY000]: General error: 1005 Can't create table
in a
symfony doctrine-build-all-load
command line means you have different integer size in your primary keys references

especially, sfDoctrineGuardPlugin use a integer(4) as primary key definition so, if you want to link your own ‘user’ class to sfGaurdUser class, you’ll have to define sf_uard_user_id as integer(4).

thanks to clear-cache.fr !

Tags: devloppement, mysql, symfony, tips

listening music remotely with Banshee + ssh -X ! Comments Off

just a small post to explain how i save 100€ today !

instead of buying an airport express to listen my music through wifi, and because my backup server is 10cm far from my sound system, i just discover that ssh -X allow me to pilot Banshee (itunes-like software on linux) so i can listen to all music that is on my backup server through wifi

for those who want to do the same :
ssh -X user@server
sudo apt-get install banshee

and then just launch banshee :
banshee
and that’s all, you should have the banshee software running on your remote computer but displayed on your local one, just import your music from local directories (on the server) and start playing songs :) dont forget to plug a audio-wire from your server to your sound system.

Tags: music, SSH, sysadmin, tips

method setTemplate() in a sfComponent (symfony 1.2) Comments Off

source : blog.doubleu3.com

Oops, there’s no setTemplate() for components!

Why is this a problem? Because, without it, there’d have to be a seperate template file for each section’s action in the component. I just want to use the one template, and use the $section variable to determine what section to highlight.

The fix

The fix is to add a setTemplate() method to the sfComponents class.
It isn’t that complicated, but requires modification to a couple of files.

Add the following lines (2 methods, and one property definition) to
symfony/actions/sfComponent.class.php

/**
* Holds the sfView instance which performs the rendering.
*/
private $componentView;

/**
* @author Jared Armstrong
* Set the "View" object for this component, so that the component
* actions can modify the template for the view.
*
* @param sfView $componentView
*/
public function setComponentView($componentView) {
$this->componentView = $componentView;
}

/**
* @author Jared Armstrong
* Sets the template to use when rendering this component.
* @param string $template Name of the template to render
* (excluding _ and .php extension - automatically added since this is a component)
*/
public function setTemplate($template) {
$this->logMessage('Modifying template for component to \''.$template.'\'', 'debug');
if (isset($this->componentView) && $this->componentView instanceof sfView)
$this->componentView->setTemplate('_'.$template.'.php');
else
throw new sfException("Unable to set template for this component.
Component did not provide a sfView instance to modify.");
}

This provides the setTemplate() functionality like that of sfAction.

Now, we need to modify the code that creates the component instance and renders it, because we need to pass it the sfView instance to modify the output template which gets used.

In symfony/helpers/PartialHelper.php

function get_component($moduleName, $componentName, $vars = array()) {
...
$allVars = _call_component($moduleName, $componentName, $vars);
...
}

to

function get_component($moduleName, $componentName, $vars = array()) {
...
$allVars = _call_component($moduleName, $componentName, $vars, $view);
...
}

This passes the view instance to the method executing the component.

Now also

function _call_component($moduleName, $componentName, $vars) {
to

function _call_component($moduleName, $componentName, $vars, $componentView = null) {

and

function _call_component($moduleName, $componentName, $vars, $componentView = null) {
...
// create an instance of the action
$componentInstance = $controller->getComponent($moduleName, $componentName);
...
}

to

function _call_component($moduleName, $componentName, $vars, $componentView = null) {
...
// create an instance of the action
$componentInstance = $controller->getComponent($moduleName, $componentName);
$componentInstance->setComponentView($componentView);
...
}

Done!
Now your sfComponents should be able to successfully use the setTemplate method like that of your sfActions.

Possible better alternatives
Using the sfConfig, my guess is you can modify the class used to render ‘partials’, and when it runs the getTemplate() method, check to see if a variable has been set in the varholder that tells of a different template to use. However, the above method provides more transparency from actions to components.

Thank you Jared for this tip, wrote here to have a backup ;-)

Tags: devloppement, symfony, tips

Grep + Awk Comments Off

another tips for unix file management :

how to use grep an awk combined ? here is a simple example : i want to delete those boring ._* files created by macosx that i scp to my server

make a test :
find myDirectory/ "\._*" | grep "\._" | awk '{print "rm "$1}' > tmp_file

if cat tmp_file looks good, then execute the code !
find myDirectory/ "\._*" | grep "\._" | awk '{print "rm "$1}' | sh

there is probably better but i just know this tips :)

Tags: sysadmin, tips, ubuntu

How to add a post-commit mailing on SVN Comments Off

Here is a short mémo on how setting up an automatic emailing when a user commits files on a svn repository
Assuming you use a Ubuntu/Debian-based OS.

  1. First step : make sure you have a functionnal SVN-repository on the machine
  2. 2nd step : we’ll need libsvn-notify-perl package :sudo apt-get install libsvn-notify-perl
  3. You may now have the svnnotify binary in /usr/bin/ or something like this. try whereis svnnotify if you don’t know where it is
  4. go to you repository’s directory:cd /home/myname/svn/project1/
  5. create a file named post-commit in ./hooks/ and make it executable by www-datatouch ./hooks/post-commit && chown www-data:www-data ./hooks/post-commit && sudo chmod u+x ./hooks/post-commit
  6. Now edit post-commit file and write the following :#!/bin/sh
    REPOS="$1"
    REV="$2"
    /usr/bin/svnnotify -r "$REV" -C -d -H Alternative \
    --alt HTML::ColorDiff -p "$REPOS" -t "to@domain.tld" \
    --from 'from @ domain.tld ' \

    just replace to@domain.tld and from@domain.tld by your correct email adresses (advising that to@domain.tld may be a mailing-list that mail all the people that work on the project)
  7. Additionnaly, you can add this : --reply-to `cat "/home/myname/etc/svn-authors/myproject/$AUTHOR"`\ assuming that you have files that contains the email of each svn-user in the /home/myname/etc/svn-authors/myproject/ directory
    E.G : in the etc/svn-authors/myproject/ directory you can
    echo -n 'firstName.lastName@domain.tld' > userPseudo foreach of yours svn-users

Good luck !

Tags: devloppement, svn, sysadmin, tips, tool, ubuntu

Next Page »