Monday, February 27, 2012

Extract RPM without installing

Extract RPM file using rpm2cpio and cpio command:
> rpm2cpio php-5.1.4-1.esp1.x86_64.rpm | cpio -idmv

Output:

/etc/httpd/conf.d/php.conf
./etc/php.d
./etc/php.ini
./usr/bin/php
...
19188 blocks
Output of rpm2cpio piped to cpio command (see how to use cpio) with following options:
  • i: Restore archive
  • d: Create leading directories where needed
  • m: Retain previous file modification times when creating files
  • v: Verbose i.e. display progress

Sunday, February 26, 2012

Restarts apache on Ubuntu

> sudo /etc/init.d/apache2 restart
or
> sudo service apache2 restart
or
> sudo apachectl restart

Friday, February 24, 2012

Changelanguage to english in SQL Developer

In %SQL_DEVELOPER_PATH%\sqldeveloper\bin\sqldeveloper.conf, add
AddVMOption -Duser.language=en

No directory /home/jerome logging in with home=/

Solution:
> sudo touch /.autorelabel
> sudo reboot

Thursday, February 23, 2012

PL/SQL: format decimals like french

ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ', ';

Tuesday, February 21, 2012

Resize a Fedora .vdi file in Oracle VM VirtualBox 4.1.8

The LVM system file used by Fedora is not supported by GParted.
In order to add the new volume to the existing partition, we need to use system-config-lvm.
sudo yum -y install system-config-lvm
French article describing how to proceed. NB: If meeting the following error:
process 702: D-Bus library appears to be incorrectly set up; failed to read 
machine uuid: Failed to open "/var/lib/dbus/machine-id": No such file or directory.
Then run the following command as root.
> dbus-uuidgen > /var/lib/dbus/machine-id

Sunday, February 19, 2012

Disable 3G on Android

  • Open dialer
  • Dial *#*#4636#*#*
  • Tap 'Phone Information'
  • Press Menu button
  • Tap on More
  • Tap Disable data connection
  • Tap Disable data on boot

Friday, February 17, 2012

List perl module dependencies

perl -MTime::Local -e 'print $_," => ",$INC{$_},"\n" for keys %INC'

Tuesday, February 14, 2012

Permanent hostname change on RedHat based systems

From MDLog:/sysadmin:
RedHat based system use the file /etc/sysconfig/network to read the saved hostname at system boot. This is set using the init script /etc/rc.d/rc.sysinit
/etc/sysconfig/network:
NETWORKING=yes
HOSTNAME="plain.domainname.com"
GATEWAY="192.168.0.1"
GATEWAYDEV="eth0"
FORWARD_IPV4="yes"
So in order to preserve your change on system reboot edit this file and enter the appropriate name using the HOSTNAME variable.

Permanent hostname change on Debian based systems

From MDLog:/sysadmin:
Debian based systems use the file /etc/hostname to read the hostname of the system at boot time and set it up using the init script /etc/init.d/hostname.sh
/etc/hostname:
server
So on a Debian based system we can edit the file /etc/hostname and change the name of the system and then run:
/etc/init.d/hostname.sh start
to make the change active. The hostname saved in this file (/etc/hostname) will be preserved on system reboot.

yum

YUM : Configuration du gestionnaire de paquets

Monday, February 13, 2012

Fedora: users managenent

Create user:
useradd --home /home/jerome jerome -g users
passwd jerome
Delete user:
userdel --remove jerome

Thursday, February 9, 2012

Make sure only one invocation of a script is active at a time

Neat solution implemented in Sys::RunAlone CPAN module.

Wednesday, February 8, 2012

Copy rectangle

C-x rr i       copy rectangle into register i
C-x rg i       paste rectangle from register i
C-x rk         cut rectangle region 
C-x ry         yank rectangle region 
C-x rc         clear rectangle region

CPAN install: do not have write permissions on

Installing DBIx::Class::Schema::Loader from CPAN results in some permissions error:
cpan[1]> install DBIx::Class::Schema::Loader
...
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ERROR: Can't create '/usr/local/bin'
Do not have write permissions on '/usr/local/bin'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 at -e line 1
make: *** [pure_site_install] Error 13
  ANDK/CPAN-1.9800.tar.gz
  /usr/bin/make install  -- NOT OK
----
  You may have to su to root to install the package
  (Or you may want to run something like
    o conf make_install_make_command 'sudo make'
  to raise your permissions.Failed during this command:
 ANDK/CPAN-1.9800.tar.gz                      : install NO
Trying as suggested will do no good:
cpan[4]> o conf make_install_make_command 'sudo make'
    make_install_make_command [sudo make]
Please use 'o conf commit' to make the config permanent!

cpan[5]> install DBIx::Class::Schema::Loader
Running install for module 'DBIx::Class::Schema::Loader'
Running make for R/RK/RKITOVER/DBIx-Class-Schema-Loader-0.07017.tar.gz
  Has already been unwrapped into directory /home/jerome/.cpan/build/DBIx-Class-Schema-Loader-0.07017-_upIn_
  Has already been made
Running make test
  Has already been tested successfully
Running make install
  Already tried without success
So the solution is:
cpan[6]> force install DBIx::Class::Schema::Loader

Install perl modules locally - Best approach

local::lib is a Perl module that sets everything up so you can install distributions from CPAN into your home directory.
Download it from http://search.cpan.org/dist/local-lib.
tar xvfz local-lib-1.008004.tar.gz
cd local-lib-1.008004
We now need to tell local::lib we want it to 'bootstrap' itself. This creates a 'perl5' folder within your home directory, and instructs the toolchain to install local::lib there.
perl Makefile.PL --bootstrap
Then, build, test and install local::lib:
make
make test
make install
Now set some environment variables that tell Perl where your installed modules are kept.
echo 'eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)' >>~/.bashrc
Test it:
perl -MCPAN -eshell
At the CPAN prompt, enter:
cpan[1]> install DBIx::Class::Schema::Loader

Install a perl module locally

On Solaris, installing a Perl module can be done that way:
export PERL5LIB=/u/gallinar/perl5lib/tmp/lib/site_perl
perl Makefile.PL PREFIX=/u/gallinar/perl5lib/tmp CC=gcc LD=gcc CCCDLFLAGS=-fPIC OPTIMIZE=-O3 CCFLAGS=" "
make
make install

Tuesday, February 7, 2012

Use Java 7 with SQL Developer

If using Java 7 with Oracle SQL Developer 3.1 for Windows, one can get an error message about MSCVR100.dll missing.
Solution:
Simply copy MSCVCR100.dll from java bin directory into sqldeveloper directory.

Monday, February 6, 2012

Closures

In Perl or PHP 5.3+, closures are implemented as anonymous subroutines with lasting references to lexical variables outside their own scopes.
Perl example:
#!/usr/bin/perl

sub test_it {
    my ($count) = @_;
    return sub { ++$count; };
}

my $test1 = test_it(10);
my $test2 = test_it(50);
print $test1->(), "\n";         # 11
print $test2->(), "\n";         # 51
print $test1->(), "\n";         # 12
print $test2->(), "\n";         # 52

PHP distinguishes between read-only closures or read-write closures:
#!/usr/bin/php

<?php
function test_it_ro($count) {
    return function() use($count) {
        return ++$count;
    };
}
function test_it_rw($count) {
    return function() use(&$count) {
        return ++$count;
    };
}
$test1 = test_it_ro(10);
$test2 = test_it_ro(50);
print $test1()."\n";            // 11
print $test2()."\n";            // 51
print $test1()."\n";            // 11
print $test2()."\n";            // 51

$test1 = test_it_rw(10);
$test2 = test_it_rw(50);
print $test1()."\n";            // 11
print $test2()."\n";            // 51
print $test1()."\n";            // 12
print $test2()."\n";            // 52
?>

Thursday, February 2, 2012

How to use Git to test an idea

Setup git in your project directory:
git init
This will create a local .git repository for git. Run
git status
As we did not add any files to git, it will show you all files as untracked.
Suppose we want to exclude .svn folders from git, then in .git/info/exclude, add line
.svn*
From now on, git status won't show .svn folders anymore.
Add all project's files to git:
git add .
git status will show all files as ready to be commited. Proceed:
git commit -am "initial file import"
Run: git status - it will show everything is ok
Now, suppose we want to experiment a new idea without impacting other developers. For that, we will create a new branch.
git branch idea
git checkout idea
or
git checkout -b idea
Run git status, it will show you are in new branch.
Now you can make all you changes and commits.
If you want to switch back to the main branch:
git checkout master
and return to the new branch:
git checkout idea
If you want to merge the new branch into the master branch, you have to move all changes made in the idea branch.
git checkout master
git merge idea
To drop the idea branch, run:
git branch -d idea

Rapid s h a r e series

Series in french or VOSTFR.

PHP debugging

French article on how to debug PHP with the Xdebug extension.

Native PHP extension for enum

This is what the SplEnum class is all about.
Example use here.