Wednesday, December 1, 2010

valgrind

  • to run it:
    valgrind --leak-check=yes myprog

  • To see where the time is spent
    valgrind --tool=callgrind

    kcachegrind: Graphical interface taking callgrind.out.*
    .
  • Sunday, November 28, 2010

    sample Makefile

    #
    
    SOURCES=my_main.cpp
    
    INC_PATH=~/tools/ImageMagick-6.6.5-4/Magick++/lib
    
    LIBRARY_PATH=~/tools/ImageMagick-6.6.5-4/Magick++/bin
    
    all:
        g++ -g -L$(LIBRARY_PATH) -O0 -o my_main $(SOURCES)
    
    

    gdb

    (gdb) kill ---> kill the session and keep your breakpoints...
    (gdb) run ---> restart a new session
    (gdb) info locals ---> local variables
    (gdb) quit ---> exit gdb, lose your breakpoints...

    (gdb) bt or backtrace ---> call stack
    (gdb) bt full ---> call stack + all variables
    (gdb) x/200s 0x89b8a8 ---> display mem as string

    A blank line repeat the previous command

  • Debugging STL
    Add a file .gdbinit to debug STL, see this link:
    http://www.yolinux.com/TUTORIALS/GDB-Commands.html#STLDEREF

    Then you can use it like this:
    pmap params char* char*

    See "Run / Debug Configurations" and debugger tab to specify a particular .gdbinit. Note that I had to add the .gdbinit full path, otherwise it would not work

  • gdb with arguments
    gdb --args your_bin -c ~/2.2.25/etc -t 16

  • Debugging a core dump:
    - gdb MyBin core.14694
    and then bt for backtrace

    .
  • Thursday, November 25, 2010

    Sorting

    from wikipedia:

    Name Best Average Worst
    Memory Stable Method
    Other notes
    Insertion sort  \mathcal{}  n  \mathcal{}  n^2  \mathcal{}  n^2 \mathcal{} {1} Yes Insertion Average case is also \mathcal{O}\left( {n + d} \right), where d is the number of inversions
    Binary tree sort \mathcal{} {n \log n} \mathcal{} {n \log n} \mathcal{} n Yes Insertion When using a self-balancing binary search tree
    Cycle sort  \mathcal{}  n^2  \mathcal{}  n^2 \mathcal{} {1} No Insertion In-place with theoretically optimal number of writes
    Selection sort  \mathcal{}  n^2  \mathcal{}  n^2  \mathcal{}  n^2 \mathcal{} {1} No Selection Its stability depends on the implementation. Used to sort this table in Safari or other Webkit web browser [2].
    Bubble sort \mathcal{} n \mathcal{} n^2 \mathcal{} n^2 \mathcal{} {1} Yes Exchanging Tiny code
    Merge sort \mathcal{} {n \log n} \mathcal{} {n \log n} \mathcal{} {n \log n} Depends Yes Merging Used to sort this table in Firefox [3].
    Quicksort \mathcal{} n \log n \mathcal{} n \log n \mathcal{} n^2 \mathcal{} \log n Depends Partitioning Can be implemented as a stable sort depending on how the pivot is handled. Naïve variants use \mathcal{O} \left( n \right) space

    Saturday, November 13, 2010

    Quotes




  • "If I asked my customers what they wanted, they'd have said a faster horse." Henry Ford
  • "If you can't see the future, you won't have one." Noah Everett
  • "People often overestimate what will happen in the next two years and underestimate what will happen in ten." Bill Gates
  • "I have had all of the disadvantages required for success." Larry Ellison 
  • "There is no point in starting your own business unless you do it out of a sense of frustration." R. Branson
  • "Il y a trois manières de se ruiner: le jeu, les femmes — et les ingénieurs. Les deux premières sont plus agréables — mais la dernière est plus sûre." Rothschild
  • "You have got to find a controversial strategy. The more controversial, the better. That’s the way to differentiate yourself from everybody else. Then you've got to get really good at what you’re doing. And that’s how you will beat the competition!" Scott Mc Neally
  • "Fire kept us warm and cooked our food but also burnt down our houses. Every technology has had its promise and peril." Ray Kurzweil
  • "On regrette de ne pas avoir fait, on ne regrette pas d'avoir fait" OH
  • "The great opportunities come when your business idea isn’t as much about the product but is a different view of the industry,"  Capital One Founder, Chairman, and CEO Rich Fairbank
  • "If I were to awaken after having slept for a thousand years, my first question would be: Has the Riemann hypothesis been proven?"  D. Hilbert (Quoted in Mathematical Mysteries : The Beauty and Magic of Numbers (1999) by Calvin C. Clawson, p. 258)
  • « Je suis dans l’œil du cyclone, il n’y a plus de ciel, tout est amalgame, il n’y a que des montagnes d’eau autour de moi », dernier message  de Alain Colas
  • "Listen, invent, personalize"  Jeff Bezos
  • "What do you want to accomplish in the 12 coming months ?"  Me
  • "it should not be the user that is searching for news/products, but the news/product that is coming to the user" Taboola
  • "It has been my experience that folks who have no vices have very few virtues."  Abraham Lincoln
  • "A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P if its performance at tasks in T, as measured by P, improves with experience E." "   Tom M. Mitchell. 
  • "A man is but the product of his thoughts; what he thinks, he becomes" ( By Mahatma Gandhi)
  • "Simplicity is the ultimate sophistication" (Leonardo da Vinci, repeated by Steve Jobs)
  • "Jerrold Zacharias, my mentor, told me "you are not as stupid as you look", and it is important that people tell you that" Rainer Weiss (nobel price in physics).
  • "Quand les hommes ne peuvent changer les choses, ils changent les mots" Jean Jaures
  • O Breizh, ma Bro, me 'gar ma Bro
  • "Dire fait rire, faire fait taire". Jean Le Cam
  • "La vie a plus d'imagination que toi"   mère de Najat Vallaud-Belkacem
  • "n’attendez pas que ça change si vous continuez à faire la même chose tous les jours" Ophely Winter
  • "Ton devoir réel est de sauver ton rêve" Modigliani
  • "Optimism is an essential ingredient of innovation. How else can the individual welcome change over security, adventure over staying in safe places" Robert Noyce
  • "il y a ceux qui voudraient bien, ceux qui veulent, et enfin ceux qui veulent absolument" Bernard Tapie
  • "The greater danger for most of us lies not in setting our aim too high and falling short; but in setting our aim too low, and achieving our mark." Michelangelo
  • "I always invest in companies that can be managed by stupid people, because one day or another that happens" Warren Buffet
  • "“Le bonheur est souvent la seule chose qu'on puisse donner sans l'avoir et c'est en le donnant qu'on l'acquiert.” Voltaire
  • "le bateau à voile est le moyen le plus cher d'aller qq part gratuitement"
  • "Television is programs around advertisement" Sylvio Berlusconi
  • Tuesday, October 26, 2010

    Design Patterns

    • Creational patterns
    • Abstract Factory
      Builder
      Factory method
      Prototype
      Singleton ( + Double-Check Singleton )

    • Structural patterns
    • Adapter
      Bridge
      Composite
      Decorator
      Facade
      Flyweight
      Proxy

    • Behavioral patterns
    • Chain of responsibility
      Command
      Interpreter
      Iterator
      Mediator
      Memento
      Observer
      State
      Strategy
      Template method
      Visitor

    Tuesday, September 21, 2010

    ovh google apps

    Erreur du type:

    "Ajouter un champ MX dans la zone DNS"
    "Utilisez la section (email) pour modifier les champs MX"

    Voici comment saisir les données MX:

    Monday, July 5, 2010

    RestEasy: JBoss project

    RestEasy is a JBoss project that helps you build RESTful Web Services. It is JAX-RS compliant (Java API for RESTful Web Services).

    It is designed for JBoss but I am actually using it with tomcat only. It is very easy to use in an Eclipse project. You can use:

    JAX-RS Hello World with RESTEasy
    .

    Monday, June 28, 2010

    Complexity of basic STL containers

    \ . possible implementation insert/remove at the beginning insert/remove at the end find
    vector sequence, key not unique,
    back-insertion
    dynamic array
    (malloc)
    o(n) o(1) o(1) (operator[])
    o(n) (iter or algo)
    list sequence, key not unique doubly-linked list o(1) o(1) o(n) (iter or algo)
    set sorted associative container, key unique sorted tree o(log(n)) o(log(n)) o(log(n))
    map sorted associative container, key unique sorted tree o(log(n)) o(log(n)) o(log(n))
    hash_map hashed associative container, key unique hashmap o(1) o(1) o(1)

    Notes:
    • for insert/remove in list, assumes we have the iterator at the right position
    • no push_back on associative containers
    Ones that I don't use often:
    \ . possible implementation insert/remove at the beginning insert/remove at the end find
    deque sequence, key not unique
    o(n) in the middle
    dynamic array or
    doubly-linked list
    o(1) o(1) o(n)
    slist sequence, key not unique,
    single direction iterator,
    front-insertion
    single-linked list o(1) o(n)
    o(1) if insert_after
    o(n)

  • Sequence container
    1. vector
    2. deque
    3. list
    4. slist
    5. bit_vector

  • Associative containers
    1. set
    2. map
    3. multiset
    4. multimap
    5. hash_set
    6. hash_map
    7. hash_multiset
    8. hash_multimap

  • Container adaptors
    1. stack (LIFO)
    2. queue (FIFO)
    3. priority_queue
    .
  • Thursday, May 27, 2010

    templates

    simple template:

    template < class F > class ClassTemp
    {
    public:
    F test(F* feature );
    };
    
    template < class F >
    F ClassTemp < F > ::test(F* feature) 
    {
    return *feature;
    };
    
    ClassTemp < char > myInst;
    
    int main()
    {
    char c = 'c';
    char ret = myInst.test(&c);
    }
    
    


    Note: since the compiler replaces the templates, source code of the templates needs to be included where it is used (template source code in the .h for ex).
    .

    Wednesday, April 21, 2010

    blogger / blogspot

    I now backup only Ubuntu related stuff since "max-results" is not taken into account anymore in the query
    http://swiss-knife.blogspot.fr/search?q=ubuntu
    to see all posts, or backup blogger blogs:
    http://swiss-knife.blogspot.fr/search?max-results=1000&start=0


  • to insert an array in blogger, you need to put all the HTML on one line... Otherwise, the array is displayed way down.
  • to insert HTML in blogger posts, haven't found easier than putting "amp lt;" <  and "amp gt;" >
    .
  • Saturday, April 17, 2010

    maven







  • maven
    • to display all the targets:
      mvn -g > toto.txt
    • List of targets are in project.xml, see "build" target
    • "dist:" postgoals are described in maven.xml
    • To add a jar like mysql, you need to add it to project.properties and project.xml
    • Maven plugin for eclipse:
    • http://download.eclipse.org/technology/m2e/releases
  • To create an exe from Eclipse
  • Maven System Properties
      mvn assembly:assembly -Dmaven.test.skip=true   (doesn't build tests)
      mvn assembly:assembly -DskipTests=true   (doesn't do tests, but build them)
       
    • New Maven project for Eclipse 

      1. from the command line:
      2.  mvn archetype:generate -DgroupId=com.yourcompany.engine.api -DartifactId=EngineApi -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
        1. cd EngineApi
        2. mvn install
        3. mvn eclipse:eclipse
        4. Import the project into Eclipse as a maven project
        5. Right click on the Eclipse project: "Maven / Enable Dependencies Management" then "Maven / Update Project Configuration"

      • Maven/Eclipse problem
        1. Right-click on your project, select Maven -> Remove Maven Nature.
        2. Open you terminal, go to your project folder and do mvn eclipse:clean
        3. Right click on your Project and select “Configure -> Convert into Maven Project”
      • Create a pom compatible entry to be used as a dependency from a local jar file
      mvn install:install-file -DgroupId=org.winterwell -DartifactId=jtwitter -Dversion=2.8.2 -Dfile=/home/lee/tools/JTwitter/jtwitter.jar -Dpackaging=jar -DgeneratePom=true

      • if you lost or removed the /target folder
        • mvn compile
        • or
        • mvn package  (creates also the package...)

      Wednesday, March 24, 2010

      Tomcat survival kit (Tomcat6)


    1. Servlet container, no EJB support

    2. /conf
      Ubuntu: /var/lib/tomcat6/conf
      W7: C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0
      /usr/share/tomcat/bin/catalina.sh

    3. To see access log on your Tomcat, add the following to your conf/server.xml :

      &lt Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="common"/ &gt

    4. to administer the modules
      http://localhost:8080/manager/html
      default user: "admin / no pw"
      Otherwise, you can add
      &lt user name="username" password="secret" roles="standard,manager" / &gt
      in /Tomcat 6.0/conf/tomcat-users.xml

    5. default location for war files
      /var/lib/tomcat6/webapps
      then you do: http://192.168.0.12:8082/sample/

    6. for security reasons, slashes cannot be url encoded, like:
      http://127.0.0.1:8080/getimagelist/http%3A%2F%2F
      ( %3A works but not %2F). See property
      org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH: true|false

    7. for memory setting like

      JAVA_OPTS="-Djava.awt.headless=true -server -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+DisableExplicitGC"

    8. to make sure you don't use openJDK
      edit /etc/init.d/tomcat6 and look for JDK_DIRS

    9. if JAVA_HOME is not found when doing sudo /etc/init.d/tomcat start, do:
      sudo -E /etc/init.d/tomcat start

    10. other things:
      ./usr/share/tomcat6/bin/catalina.sh
      /var/lib/tomcat6/conf/logging.properties
    11. "too many open files" in catalina
      • ulimit -a
        • pipe size (512 bytes, -p) 8
      .
    12. Wednesday, February 17, 2010

      Android development

    13. when you plug in a nexus and you do
      ./adb devices
      you get:
      List of devices attached
      ???????????? no permissions

      What you need to do:
      ./adb kill-server
      sudo ./adb start-server
      * daemon not running. starting it now *
      * daemon started successfully *
      ./adb devices
      you get:
      List of devices attached
      HT019P803628 device

      Then, if you don't have an emulator running, you can do:
      ./adb install ../platforms/android-2.1/samples/ApiDemos/bin/apis.apk

      To get the debug trace on the host computer:
      ./adb logcat
    14. Friday, January 8, 2010

      Tesseract

      To use Tesseract, you need an uncompress Tiff file. To do that:

      C:\tools\ImageMagick-6.5.8\VisualMagick\bin\convert.exe c:\tmp4\toto.jpg c:\tmp4\toto.tif
      C:\tools\Tesseract>tiffcp -c none c:\tmp4\toto.tif c:\tmp4\unc_toto.tiff
      C:\tools\Tesseract>tesseract c:\tmp4\unc_toto.tif out

      Go and read the OCR result in out.txt