git remote -v update
Monday, November 30, 2015
Tuesday, November 24, 2015
PostgreSQL: see number of connections
select sum(numbackends) from pg_stat_database;
Labels:
postgresql
Sunday, November 15, 2015
Windows: change desktop icon size
- Using the left click of the mouse, click on an empty area in the desktop. This step is to make sure that there is no application selected/clicked on.
- Using your keyboard, press and keep holding the CTRL button, then using your mouse wheel, roll it upward to make the icons size larger, or downward to set the icon size smaller
Virtualbox centos: Device eth0 does not seem to be present
If, when copying a VM from one computer to another one, you face this error:
Then ensure first that /etc/sysconfig/network-scripts/ifcfg-eth0 has the same MAC address as in Virtualbox network settings, plus
service network restart
...
Bringing up interface eth0: Device eth0 does not seem to be present, delaying initialization.
Then ensure first that /etc/sysconfig/network-scripts/ifcfg-eth0 has the same MAC address as in Virtualbox network settings, plus
rm /etc/udev/rules.d/70-persistent-net.rules
and reboot
Labels:
centos,
virtualbox
Cisco AnyConnect - Adding Multiple VPN Devices to the Client
See http://www.petenetlive.com/KB/Article/0001011.htm
- Windows: vi C:\ProgramData\Cisco\Cisco AnyConnect Secure Mobility Client\profile\Profile.xml
- MacOS: vi /opt/cisco/anyconnect/profile/Profile.xml
false true false All false Native true 12 false true true true true DisconnectOnSuspend true Automatic SingleLocalLogon LocalUsersOnly false Disable false false 20 4 false My entry #1 my_entry1.com My entry #2 my_entry2.com
Labels:
anyconnect,
vpn
Wednesday, November 4, 2015
Monday, November 2, 2015
Friday, October 30, 2015
Monday, October 26, 2015
Git: cancel staged file update
With git log check which commit is one prior the update. Then you can reset it using:
git reset filename
git checkout filename
Git: cancel merge
With git log check which commit is one prior the merge. Then you can reset it using:
git reset --hard commit_sha
Monday, October 19, 2015
Saturday, October 17, 2015
OSX: use Clover Configurator
First mount EFI partition:
Identify EFI device
Identify EFI device
diskutil list
Then mount device, e.g.
mkdir /Volumes/EFI
sudo mount_msdos /dev/disk0s1 /Volumes/EFI
Then select /Volumes/EFI/EFI/CLOVER/config.plist in Clover configurator
Wednesday, October 14, 2015
PostgreSQL: compile pgloader
Compile SBCL with core compression support:
Compile pgloader:
git clone git://git.code.sf.net/p/sbcl/sbcl
cd sbcl
./make.sh --with-sb-core-compression --with-sb-thread
sudo ./install.sh
Compile pgloader:
git clone https://github.com/dimitri/pgloader.git
cd pgloader
make
sudo cp ./build/bin/pgloader /usr/bin
Labels:
postgresql
Tuesday, October 13, 2015
PostgreSQL: generate create table SQL
pg_dump -t 'my_schema.my_table' --schema-only
Labels:
postgresql
Tuesday, September 29, 2015
PostgreSQL: interval to number of days
select extract(epoch from my_interval)/86400;
Labels:
postgresql
Wednesday, September 23, 2015
Postgresql: import export of data
Export
copy (select * from shared_db.dt_process where process_name = 'AM_PARTITION') to '/tmp/shared_db__dt_process.csv' delimiter ',' csv header;Import
copy shared_db.dt_process from '/tmp/shared_db__dt_process.csv';
Labels:
postgresql
Tuesday, September 1, 2015
CentOS: install Oracle JDK
- Download JDK from download.oracle.com
cd /usr/local/share tar xvfz /media/host/jdk-8u60-linux-x64.tar.gz ln -s jdk1.8.0_60 jdk
alternatives --install /usr/bin/java java /usr/local/share/jdk/bin/java 1 alternatives --install /usr/bin/javac javac /usr/local/share/jdk/bin/javac 1 alternatives --install /usr/bin/jar jar /usr/local/share/jdk/bin/jar 1
Thursday, August 27, 2015
CentOS 6 VM: french Macbook keyboard under X11
setxkbmap -layout fr -model macintosh
Labels:
centos,
macos,
virtualbox
Saturday, August 8, 2015
QNAP: add dnsomatic cronjob
Source: http://forum.qnap.com/viewtopic.php?t=12970
vi /share/CACHEDEV1_DATA/homes/dnsomatic/dnsomatic.sh
#!/bin/sh HOSTNAME="all.dnsomatic.com" USER="my_dnsomatic_user" PASS="my_dnsomatic_password" TMPFILE="/tmp/dnsomatic.oldip" DATENOW=$(date) IP=$(/sbin/curl -s http://myip.dnsomatic.com) if [ -r "/tmp/dnsomatic.oldip" ]; then OLDIP=`cat /tmp/dnsomatic.oldip` if [ "$OLDIP" = "$IP" ]; then echo "IPs match; no update" exit 0 else RETURN=$(/sbin/curl -s -m 60 -k -u ${USER}:${PASS} https://updates.dnsomatic.com/nic/update?hostname=${HOSTNAME}&myip=$IP&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG) echo "Return message of DNS-O-Matic : " $RETURN echo $RETURN | grep "good" > /dev/null 2>&1 if [ "$?" -eq "0" ]; then echo $IP > /tmp/dnsomatic.oldip else echo "" > /tmp/dnsomatic.oldip fi fi else touch /tmp/dnsomatic.oldip fiThen update crontab to run it once an hour:
vi /etc/config/crontab
0 */1 * * * /share/CACHEDEV1_DATA/homes/dnsomatic/dnsomatic.sh >/tmp/dnsomatic.log 2>&1
crontab /etc/config/crontab
/etc/init.d/crond.sh restart
Thursday, July 9, 2015
PostgreSQL: copy table
select * into archive.radius_cdr_pdp_p2015_07_09 from ods_db.radiucdr_pdp_p2015_07_09;
Labels:
postgresql
Monday, June 29, 2015
PostgreSQL: get function source code
select pg_get_functiondef(pg_proc.oid) from pg_proc, pg_namespace where proname = 'add_cdr_req' and pg_namespace.oid = pg_proc.pronamespace and pg_namespace.nspname = 'crm_db';
Labels:
postgresql
Displaying current path in the window title with byobu on centos 6
The problem with CentOS 6, is that the tmux version that comes from the standard repo. is v1.6, and we need at least 1.8 to achieve the result.
So install tmux from the latest sources like explained here:
NB: Kill old tmux sessions before running byobu again.
And then use the following setting in your $HOME/.byobu/.tmux.conf
So install tmux from the latest sources like explained here:
# download latest libevent2 and tmux sources, and extract them somewhere
# (thx bluejedi for tip on latest tmux URL)
#
# at the time of writing:
# https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
# http://sourceforge.net/projects/tmux/files/latest/download?source=files
#
# install deps
yum install gcc kernel-devel make ncurses-devel
# cd to libevent2 src
./configure --prefix=/usr/local
make && make install
# cd to tmux src
LDFLAGS="-L/usr/local/lib -Wl,-rpath=/usr/local/lib" ./configure --prefix=/usr/local
make && make install
# you're good to go, for a sample ~/.tmux.conf check out
# https://github.com/sturadnidge/misc/blob/master/.tmux.conf
NB: Kill old tmux sessions before running byobu again.
And then use the following setting in your $HOME/.byobu/.tmux.conf
set -g status-left '#{pane_current_path} '
Monday, May 18, 2015
Tuesday, April 28, 2015
Friday, April 24, 2015
mod_perl: How to send a custom content type along with custom_response
By default, mod_perl Apache2::Response::custom_response will use the following content-type: text/html; charset=iso-8859-1.
But, what if we want to use e.g. application/x-www-form-urlencoded; charset=utf-8 instead?
Main handler:
But, what if we want to use e.g. application/x-www-form-urlencoded; charset=utf-8 instead?
Main handler:
sub handler { my ($i_request_rec) = @_; @{$i_request_rec->pnotes}{'err_txt', 'err_content_type'} = ('appid=45465&status=-42', 'application/x-www-form-urlencoded; charset=utf-8'); $i_request_rec->custom_response(Apache2::Const::SERVER_ERROR, '/error_vas/'); return Apache2::Const::SERVER_ERROR; }Apache conf.:
<Location /error_vas/> SetHandler perl-script PerlResponseHandler Toto::ErrorVas </Location>ErrorVas.pm:
package Toto::ErrorVas; use strict; use warnings; use Apache2::Const -compile => qw(:common :log); sub handler { my ($i_request_rec) = @_; return Apache2::Const::NOT_FOUND unless $i_request_rec->prev; $i_request_rec->content_type($i_request_rec->prev->pnotes->{err_content_type}); $i_request_rec->print($i_request_rec->prev->pnotes->{err_txt}); return Apache2::Const::OK; }source: http://foertsch.name/ModPerl-Tricks/custom-content_type-with-custom_response.shtml
perl: setting multiple hash values at once
perl -MData::Dumper -e '@{$h}{qw/toto tata/} = (34, 56); print Dumper $h;'
$VAR1 = {
'tata' => 56,
'toto' => 34
};
Thursday, April 23, 2015
perl: posting to multihomed hostname
What if you want to post to a hostname resolving to multiple IP addresses?
local @LWP::Protocol::http::EXTRA_SOCK_OPTS = ( PeerAddr => $my_hostname, MultiHomed => 1, ); my $ua = LWP::UserAgent->new; my $response = $ua->post("https://$my_hostname/action", Content_Type => 'application/x-www-form-urlencoded; charset=utf-8', Content => { param1 => 'value1', param2 => 'value2', });
php/oci-extension: missing leading zero
Reading numbers from Oracle in PHP results in missing leading 0s if -1 < value < 1.
The reason for this behavior is because Oracle OCI omits 0s in results and PHP converts all results from OCI to strings without performing any casting depending on column datatype.
A simple workaroud consists in converting to float:
Oracle alternative:
The reason for this behavior is because Oracle OCI omits 0s in results and PHP converts all results from OCI to strings without performing any casting depending on column datatype.
A simple workaroud consists in converting to float:
$a = '.63';
echo (float) $a;
source: http://stackoverflow.com/questions/4284571/php-oci-oracle-and-default-number-format
Oracle alternative:
REGEXP_REPLACE(TO_CHAR(x), '^\.', '0.')or if we handle negative numbers
REGEXP_REPLACE(TO_CHAR(x), '(-?)^\.', '\10.')
Wednesday, April 22, 2015
Thursday, April 9, 2015
HTML: POST array not showing unchecked checkbox
<td> <input type="checkbox" name="cb[]"/> <input type="checkbox" name="cb[]"/> </td>
- Solution 1) Explicit index + hidden trick
<td> <input type="hidden" name="cb[0]" value=""/> <input type="checkbox" name="cb[0]"/> <input type="hidden" name="cb[1]" value=""/> <input type="checkbox" name="cb[1]"/> </td>
<td> <input type="checkbox" name="cb[0]"/> <input type="checkbox" name="cb[1]"/> </td>
$post_array = $_POST['cb'];
$defaults = array_fill(0, 2, '0');
$post_array = $post_array + $defaults;
Tuesday, March 31, 2015
Friday, March 27, 2015
PostgreSQL: perl like join
db=# select array_to_string(array['a', 'b', 'c'], '-'); array_to_string ----------------- a-b-c (1 row)
Labels:
postgresql
Thursday, March 26, 2015
PostgreSQL: cursor example
create or replace function test_cursor() returns void as $$ declare _my_cursor(p_co_id text) for select * from crm_db.ht_co_addon where co_id = p_co_id; _idx int := 0; _row record; begin -- Example 1 for _row in _my_cursor('000000000666') loop _row.co_addon_id := _idx; _idx := _idx + 1; end loop; -- Example 2 open _my_cursor('000000000666') loop fetch _my_cursor into _row exit when not found raise notice 'co_addon_id=%', _row.co_addon_id end loop close _my_cursor end; $$ language plpgsql security definer;
Labels:
postgresql
PostgreSQL: hstore or a perl like hash table
create or replace function test_hstore() returns void as $$ declare _my_cursor(p_co_id text) for select * from crm_db.ht_co_addon where co_id = p_co_id; _row record; _addon_id2co_addon_id_h hstore; _sms_ao text := 'SMS_AO'; begin for _row in _my_cursor('000000000666') loop if _addon_id2co_addon_id_h is null then _addon_id2co_addon_id_h := (_row.addon_id||'=>'||_row.co_addon_id)::hstore; else _addon_id2co_addon_id_h := _addon_id2co_addon_id_h || (_row.addon_id||'=>'||_row.co_addon_id)::hstore; end if; end loop; raise notice 'SMS_AO: %', _addon_id2co_addon_id_h->_sms_ao; for _row in select * from each(_addon_id2co_addon_id_h) loop raise notice 'h: %=>%', _row.key, _row.value; end loop; end; $$ language plpgsql security definer;
Labels:
postgresql
Friday, March 20, 2015
Linux: remove files older than x days
E.g. Remove files older than 90 days
find . -mtime +90 -exec rm {} \;
Thursday, March 19, 2015
Git merge master into feature branch
Source: http://stackoverflow.com/questions/16955980/git-merge-master-into-feature-branch
You should be able to rebase your branch on master:
You should be able to rebase your branch on master:
git checkout feature1
git rebase master
Manage all conflicts that arise. When you get to the commits with the bugfixes (already in master), git will say that there were no changes and that maybe they were already applied. You then continue the rebase (while skipping the commits already in master) with
git rebase --skip
If you perform a git log on your feature branch, you'll see the bugfix commit appear only once, and in the master portion.
git: change remote repository
Context: I have used bitbucket as a remote git repository so far, and now I want to switch to a corporate git server.
Following the instructions detailled here: http://www.smashingmagazine.com/2014/05/19/moving-git-repository-new-server/
Here are the steps eventually run:
Following the instructions detailled here: http://www.smashingmagazine.com/2014/05/19/moving-git-repository-new-server/
Here are the steps eventually run:
git fetch origin
git remote add new-origin ssh://john.smith@192.168.2.3/volume1/git-server/is.git
git pull new-origin master
git push --all new-origin
git push --tags new-origin
git remote rm origin
git remote rename new-origin origin
Tuesday, March 17, 2015
Git: Sync remote repository w/ local
From http://stackoverflow.com/questions/6373277/git-sync-local-repo-with-remote-one
-p, --prune After fetching, remove any remote-tracking branches which no longer exist on the remote
cd $HOME/src
git pull -p
NB: git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch - git-scm.com/docs/git-pull
-p, --prune After fetching, remove any remote-tracking branches which no longer exist on the remote
Monday, March 16, 2015
Thursday, March 12, 2015
Disable Strict SSH Checking on Source Peer
By appending the following to your ~/.ssh/config file you can disable SSH prompts which ask to add new hosts to the “known hosts file.” Note that the ${DESTPEERHOST} should be the name of the host machine running the destination peer:
Host ${DESTPEERHOST}
CheckHostIP no
StrictHostKeyChecking no
BatchMode yes
SSH to tondu as omnitest without password
- As gallinar, in .ssh/config, comment “Batchmode yes” so as to temporarily get a password question when sshing:
#BatchMode yes
- As gallinar, in .ssh/config, add the following lines in order to log to tondu as omnitest:
Host tndu
HostName tondu
User omnitest
- As gallinar, if not already done, generate a public key:
ssh-keygen -t rsa
- As gallinar, copy the public key to the target:
scp ~/.ssh/id_rsa.pub tondu:/tmp
- As omnitest, on tondu:
cat /tmp/id_rsa.pub >> ~/.ssh/authorized_keys
- As gallinar, in .ssh/config, uncomment “Batchmode yes”, and remove /tmp/id_rsa.pub on tondu.
Configured ssh on host for no password but still asked
Check $HOME/.ssh and $HOME rights. If writeable for group or world, a password will be asked.
> chmod 700 $HOME/.ssh
> chmod 600 $HOME/.ssh/authorized_keys
Thursday, March 5, 2015
Virtualbox: Shrinking VM Disk Images
Source: http://snippets.khromov.se/shrinking-a-virtualbox-linux-image-with-zerofree/
After we find our partition run zerofree to zero out the free space. In our example we will run it on the LVM root partition
Finally, boot down your virtual machine, and run VBoxManage on the host to resize the .vdi file
NB: The other method mentioned on the net replacing zerofree with dd like in
- Download the SystemRescueCd Live Image Mount it as a CD on your virtual machine and boot into the live distro
- Find all available partition and LVM (volume groups) with:
fdisk -l
zerofree -v /dev/mapper/vg_rheldev-lv_root
C:\>"c:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyhd "c:
\Users\jerome\VirtualBox VMs\Monster\Mobiquithings.vdi" --compact
With this method, my VM shrunk from 200 GiB to 26 GiB
NB: The other method mentioned on the net replacing zerofree with dd like in
dd -if /dev/zero -of /bigemptyfile -bs 4096; rm /bigemptyfile
was not satisfactory for me.
Labels:
virtualbox
Tuesday, February 24, 2015
xemacs: Unable to load any usable fontset
If running XEmacs causes these warnings about fonts:
[jerome@mathusalem] > xemacs
Warning: Missing charsets in String to FontSet conversion
Warning: Cannot convert string "-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso10646-1, -*-helvetica-bold-r-*-*-
*-120-*-*-*-*-iso8859-*, *" to type FontSet
Warning: Missing charsets in String to FontSet conversion
Warning: Unable to load any usable fontset
Warning: Missing charsets in String to FontSet conversion
Warning: Unable to load any usable fontset
Then, try running it this way:
[jerome@mathusalem] > LANG=C xemacs
Monday, February 23, 2015
Windows Virtualbox: increase CentOS 6 VDI size
- Create a new VDI disk under Controller: SATA, sized appropriately
- Clone existing VDI into new one
- Remove legacy VDI
- Download GParted ISO from GParted Live CD
- Mount GParted ISO under Controller: IDE
- Start the VM, which will boot on the GParted live CD
- Extend the existing LVM2 partition (/dev/sda2) with the new unallocated space
- Stop the VM, detach the GParted ISO, and reboot the VM
- Extend the logical volume into the resized partition By default, CentOS uses LVM (Logical Volume Manager), which requires an extra step.
- Resize file system
C:\Program Files\Oracle\VirtualBox> VBoxManage.exe clonehd "c:\Users\jerome\VirtualBox VMs\Mathusalem\Mathusalem.vdi" --existing "c:\Users\jerome\VirtualBox VMs\Mathusalem\Mathusalem 2.vdi"
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone hard disk created in format 'VDI'. UUID: 48da07eb-3395-4fad-95e3-c0615b185da2
Identify the name of the logical volume via df:
df -h
Then force the LVM volume to take 100% of the available space on the partition:
lvextend -l +100%FREE /dev/mapper/vg_mathusalem-lv_root
resize2fs /dev/mapper/vg_mathusalem-lv_root
After this step, we are now good to go.
Labels:
centos,
virtualbox
Tuesday, February 10, 2015
Oracle: split / join
See http://stackoverflow.com/questions/381231/hidden-features-in-oracle
SQL> declare 2 v_array apex_application_global.vc_arr2; 3 v_string varchar2(2000); 4 begin 5 6 -- Convert delimited string to array 7 v_array := apex_util.string_to_table('alpha,beta,gamma,delta', ','); 8 for i in 1..v_array.count 9 loop 10 dbms_output.put_line(v_array(i)); 11 end loop; 12 13 -- Convert array to delimited string 14 v_string := apex_util.table_to_string(v_array,'|'); 15 dbms_output.put_line(v_string); 16 end; 17 / alpha beta gamma delta alpha|beta|gamma|delta
Friday, February 6, 2015
Thursday, February 5, 2015
Oracle: return a row even if select returns no rows
SELECT nvl(data_name, 'nothing') FROM ( SELECT data_name FROM data_table WHERE data_table.type = v_t_id UNION ALL SELECT NULL AS data_name FROM dual ) WHERE data_name is not null or ROWNUM = 1;
Monday, January 5, 2015
perl: one-liner with single quotes in
cat /media/host/export_PYF_NCL.csv | perl -e 'while(<>){print "'"'"'$1'"',"'" if /^(\d+);/}'
Subscribe to:
Posts (Atom)