Tuesday, March 10, 2009

Posix thread

#include 
#include 
#include 

void my_routine(void * arg)
{
printf("\n hello \n");
}

int main(int argc, char* argv[])
{
pthread_t th;
pthread_attr_t attr;

pthread_attr_init(&attr);

int rc = pthread_create(&th, (void *)&args, (void *)my_routine, NULL);

return 0;
}

Monday, March 2, 2009

C++ survival kit

  • If you don't want somebody to instanciate your class, set the constructor private

  • Operator precedence
    http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence

  • Operator overloading:
    Complex Complex::operator+( Complex &other ) {
    return Complex( re + other.re, im + other.im );
    }
    


  • Dummy template
    // ---------------------------------------
    class MyPairClass
    {
    int pair_1;
    int pair_2;
    };
    
    // ---------------------------------------
    template < class T, int i > class MyTemplate
    {
    public:
    T* testFunc(T* pl);
    };
    
    template < class T, int i >
    T* MyTemplate::testFunc(T* p1) 
    {
    return p1;
    };
    
    // ---------------------------------------
    void myTemplateFunc()
    {
    
    MyPairClass * myPairClass = new MyPairClass();
    MyTemplate < MyPairClass, 2 >  myList;
    myList.testFunc(myPairClass);
    }
    


  • Access to class members
    The default access to class members (members of a class type declared using the class keyword) is private; the default access to global struct and union members is public. For either case, the current access level can be changed using the public, private, or protected keyword.

  • const array size
    const int maxarray = 255;
    char store_char[maxarray];  // allowed in C++; not allowed in C
    
  • Saturday, February 28, 2009

    Simple samba smb.conf (seen as \\server\everybody from Windows)

    [global]

    workgroup = WORKSPACE
    server string = %h server (Samba, Ubuntu)

    log file = /var/log/samba/log.%m
    syslog = 0
    security = share

    # name of the share
    [everybody]
    comment = Samba server
    path = /home/toto/everybody
    public = yes
    writeable = yes
    browseable = yes
    user = toto
    .

    Friday, February 27, 2009

    Ubuntu / Debian Survival Kit



    • Install / Packages 
      • instal .deb
        • sudo dpkg -i nomachine_5.1.26_1_amd64.deb
      • install LAMP on a fresh Ubuntu
      sudo tasksel install lamp-server
      • If you want to use the "Gnome classic" desktop instead of Unity from Ubuntu 14:
      sudo apt-get install gnome-session-fallback then reboot, and you will get the gnome icon in the user login part
      • Font: FreeSans 16 is not bad for firefox
      • dpkg -l |grep emacs (list installed packages)
      • alien (package conversions: rpm, tgz, etc). Usually not working for me when trying to convert Debian packages
      • To install a Debian package (read dpkg before, since it can mess up your config)
        sudo dpkg -i mysql-workbench-gpl-5.2.33b-1ubu1010-amd64.deb
      • aptitude install mysql-workbench
      • search:
        • apt-cache search libtool
        • or aptitude search libtool
    • Network
      • ip adress   (ifconfig is obsolete, see "ip" command)
      • restart network interface:
        • ifdown eth0
        • ifup eth0
      • Network, command line (dhcp/static)
        sudo vi /etc/network/interfaces
      • If your network is disabled, first right click on the network icon and enable connections (sometimes these get disabled at reboot)
      • NetworkManager
      • look at your /etc/resolv.conf, the first line will tell you if the network management of your machine is done through the NetworkManager server. You need to start it in case of failure: sudo /etc/init.d/network-manager restart The other network management way is sudo /etc/init.d/networking
      • If your IP is static, you need to specify your DNS servers manually
        /etc/resolv.conf, should look like this:
        search mydomain.example
        nameserver 212.27.40.254
      • # dns google nameserver 8.8.8.8 Note that resolv.conf is overwritten with another dns nameserver when going through DHCP
        To know what is the dns of a specific network interface
        nmcli device show eth0
      • Network config:
        sudo apt-get install gnome-network-admin
        network-admin (do not use sudo, otherwise, everything is grayed out)
        sudo /etc/init.d/networking restart
        (you need to use this command when you go on standby and come back on, the networking get a new IP address throuch DHCP in this case)
      • WIFI
        • To use WIFI, you need to stop firestarter. So better stop apache and samba also while you use WIFI. RPCbind port 111 remains open. If you really want to close this port too (you don't have to):
          /etc/init.d/portmap stop
        • Also, at some point NetworkManager was not working anymore, not sure why. I could not use WIFI anymore. I installed wicd and it worked fine. Useful commands to trouble shoot WIFI on Ubuntu are:
          lshw, sudo iwlist scan
          Note that when login identification is required on a web site, the WIFI connection will show alternate "connected"/"disconnected" on wicd until you login.
          wicd 1.7.0 shows "wrong password" for WPA2 (Ubuntu 10.04 LTS). Seems working with wicd 1.6. Just use the regular wifi icon on the tray.
        • wifi not working after Ubuntu suspend
          • sudo nmcli nm sleep false
        • list wifi connections
          • sudo nmcli dev wifi list
      • firewall: "sudo firestarter"
      • When using wireshark, do not forget to use sudo, otherwise, it does not see any network interface. There is no snoop on ubuntu
      • tcpdump -n -A -p -i lo host 127.0.0.1 and port 8086
      • tcpdump -n -A -p -i eth0  host 192.168.0.202 and port 8080 |grep GET
      • tcpdump -n -A -p -i lo host 127.0.0.1 and dst port  8080
      • tcpdump -n -A -p -i eth0 host 192.168.0.195 and port 12501 |grep kWords --color=auto
      • tcpdump -n -A -p -i eth0 host 192.168.4.101 and port 12560 |grep kWords --color=auto
      • sudo tcpdump -n -A -p -i bond1  host   10.64.113.173 and port 8080 |grep GET
      • tcpdump -n -A -p -i em2  host 192.168.4.188 and port 8384 |grep solr
      • tcpdump -n -A -p -i em1 |grep 10\.1\.65\.208
      • (proxy / threesint2) tcpdump -n -A -p -i bond1  host 10.64.114.35 and port 8080 |grep GET              (can be run from threesint2, not from docker)
      • [proxy vv157]# tcpdump -n -A -p -i eth1  host  10.64.115.157 and port 8080 |grep "siteId=" --color
      • some packets are filtered by tcpdump (local machine)

    • Flush RAM / Clear memory cache
      x14:/data/data_ref/DE# echo "1" > /proc/sys/vm/drop_caches
      x14:/data/data_ref/DE# echo "0" > /proc/sys/vm/drop_caches
      x14:/data/data_ref/DE# free -m

    • Config / Settings / Display
      • Need a .profile file to specify to exec .bashrc See dot files
      • compiz settings:  sudo ccsm &
      • BUG Ubuntu: "Display settings" not taken into account when using nvidia driver:
        • pkill -9 -f gnome-settings-daemon
    • Services
      • sudo service "equivalent to" sudo /etc/init.d/serviceName (start|stop|rerstart)
      • see /etc/inetd.conf : services made available by this machine over the net - see System/Administration/Services to disable samba for example
      • dpkg -S /sbin/init   - is either "upstart" or  "systemd"
        • systemd => /etc/init.d
        • upstart => /etc/init
      • service --status-all
      • initctl list
      • remove a service started at boot time
        • update-rc.d -f  hbase-master  remove
        • see also    "ls -al /etc/rc*.d/"
      • some services (updatedb / mlocate) are started from
        • /etc/cron.daily     (/etc/cron.*)
        • the way to disable this services seems to be:
          • /etc/cron.daily#   chmod -x mlocate
    • version
      cat /etc/lsb-release
      cat /etc/issue

    • CPU temperature
      • "sensors" to get processor temperature
      • The following gets the BIOS info but the system freezes shortly after that:
        - "sudo modprobe i8k force=1" to be able to use i8kctl on vostro. A folder /proc/i8ctl is created (and disappear after reboot). Seems disabled after reboot.
        - "i8kctl" to display infos
    • boot
      • /etc/rc.local
      • /etc/fstab for boot time mounts
    • To mount a remote directory on my machine:
      vi /etc/fstab (add the my_folder line)
      mkdir /mnt/my_folder
      ln -s /mnt/my_folder /my_folder
      mount -a
      df
      exportfs
    • alias
      alias h='history 50'
      alias l.='ls -ald .*'
      alias ll='ls -l'
      alias ls='ls --color=auto'
    • To get colors when using vi
      • apt-get install vim
    • To acces an NT machine file system
      from the "Places" Ubuntu file explorer:
      smb://192.168.0.22/
    • unmount Sony-Ericsson:
      sudo eject /media/PHONE
    • If mouse and keyboard are frozen at login
      sudo apt-get update
      sudo reboot
      or plug a USB mouse
    • alsa force-reload       (restart audio device)
    .

    Sunday, January 18, 2009

    Linguistics

    Anaphora / ellipsis resolution

      - anaphora resolution
      The music stopped, and that upset everyone

      - ellipsis resolution

    Toponymy
    Studies place names

    .

    Friday, January 16, 2009

    About BTree

    Hash clusters were introduced in Oracle 7 as an alternative way of indexing
    a table. Instead of randomly storing rows in arbitrary table blocks and
    using indexes to locate them (using a B-tree search), hash cluster rows are
    stored according to the key values. Each row's location is derived by its
    key value.
    .

    Wednesday, January 14, 2009

    OO survival kit

    If one has:
    class MyImplement : public MyInterface

    If the destructor of MyInterface is not virtual, then the destructor of MyImplement is not called in this case:

    MyInterface * myInterface = new MyImplement();
    delete myInterface;
    .