Thursday, September 25, 2014

Google drive: Host some CSS/JS files

This is how to store some web files in what Google calls the new Drive as of today, 25-09-2014.
Say we want to fetch some CSS file from a folder on Google Drive.
  1. Right click on the folder and select "Share..."
  2. Select "More..." in the popup dialog
  3. Check the "Public on the web" box
  4. A public URL is proposed in the following dialog
  5. The folder URL is of the form:

    https://drive.google.com/folderview?id=0B7uYPyj_NiVxYVltWjZ0VUVULTQ&usp=sharing.

    In order to use it in a web page, pick the id from the proposed URL and re-use it in the following new URL:
    https://googledrive.com/host/0B7uYPyj_NiVxYVltWjZ0VUVULTQ
  6. Then add the filename to be used, e.g.

    https://googledrive.com/host/0B7uYPyj_NiVxYVltWjZ0VUVULTQ/toto.css
Et voila.

Oracle: Dump data into CSV file

Tom Kyte gives details on how to do that here:
http://tkyte.blogspot.fr/2009/10/httpasktomoraclecomtkyteflat.html

NB: See the flat script as a base and use chr(59) if you want to have ';' instead of tabs in the output.

Oracle: Handle error codes with sqlplus

Tom Kyte explains it here:
http://tkyte.blogspot.fr/2010/04/new-thing-about-sqlplus.html
  1. Start with
    set errorlogging on identifier toto
    delete from sperrorlog where identifier = 'toto'
    /
    
  2. Then use some sqlplus commands
  3. And terminate with
    col nb_errors new_value nb_errors
    select count(*) as nb_errors from sperrorlog where identifier = 'toto'
    /
    exit nb_errors
This allows for testings the return code of sqlplus in a bash / perl script.

NB: See http://ss64.com/ora/syntax-sqlplus.html for the sqlplus syntax

Friday, September 19, 2014

Oracle: ORA-00600: internal error code, arguments: [kqd-objerror$]

If this error occurs when trying to drop a trigger, e.g.
DROP TRIGGER RADIUS_DB.RADACCT_RADACCTID;

  1. Find the object_id of the trigger
    select object_id from dba_objects where object_name='RADACCT_RADACCTID';
  2. Insert the object_id into objerror$
    insert into sys.objerror$ values(126915);
    commit;
  3. shutdown abort
  4. startup
  5. Retry to drop the trigger, this should be OK now.
    DROP TRIGGER RADIUS_DB.RADACCT_RADACCTID;

Bash: delete last n lines of a file

head -n -100000 FILE > NEWFILE

Thursday, September 18, 2014

Oracle: using statspack

Use the steps as described in:
http://www.oracledistilled.com/oracle-database/performance/installing-and-configuring-statspack/
which are:
1) Create the tablespace to hold the Statspack tables.
CREATE TABLESPACE statspack_db_data DATAFILE 
  '/home/oracle/oracle/oradata/CRMMBQT/statspack_db_data_01.dbf' SIZE 500M AUTOEXTEND ON NEXT 10M MAXSIZE 2048M
EXTENT MANAGEMENT LOCAL uniform size 1M
SEGMENT SPACE MANAGEMENT AUTO;
2) Run the ORACLE_HOME/rdbms/admin/spcreate.sql script to create the PERFSTAT schema.
cd /home/oracle/oracle/product/11.2.0/dbhome_1/rdbms/admin
> sqlplus / as sysdba
SQL> @spcreate
A list of available table spaces will be presented. Type in the name of the table space created earlier and hit the enter key.
When selecting a temporary table space for the PERFSTAT user, keep the default tablespace as proposed.

3) Execute a snapshot w/ level 7:
exec statspack.snap(i_snap_level => 7);
4) Run a report:
ORACLE_HOME\rdbms\admin\spreport.sql is used to generate an instance level report.
You will then pick a beginning snapshot and an ending snapshot, as well as a file name to save results.
cd /home/oracle/oracle/product/11.2.0/dbhome_1/rdbms/admin
> sqlplus / as sysdba
SQL> @spreport

Wednesday, September 10, 2014

Oracle: drop interval partitions

source: http://prutser.wordpress.com/2010/01/11/dropping-interval-partitions/
-- Count number of partitions: 905
select count(*) from dba_tab_partitions where table_name = 'AT_PROCESS_LOG';

-- List of partitions to drop: keep 30 latest partitions
select * from (
select partition_name, interval, high_value, partition_position
from dba_tab_partitions where table_name = 'AT_PROCESS_LOG'
order by partition_position desc
) where 1 < partition_position and partition_position < 905 - (30-1);
Drop syntax examples:
-- Drop partition w/ high_value = 16-03-2012
alter table monitor_db.at_process_log drop partition for (to_date('15-03-2012','DD-MM-YYYY')); 

-- Drop partition from name
alter table monitor_db.at_process_log drop partition SYS_P61;

Monday, September 8, 2014

Oracle: Random UUID

v_uuid RAW(16) := sys.dbms_crypto.randombytes(16);

Friday, September 5, 2014

Delete files older than

E.g. Delete files in current directory older than 90 days :
find . -mtime +90 -delete

Friday, August 29, 2014

perl -c equivalent in python

You actually need to compile the file like in:
python -m py_compile toto.py

Wednesday, August 6, 2014

Mavericks: mount network drive at startup

  1. Go to System Preferences > Users & Groups
  2. Push "Login Items" tabbed button
  3. Drag the network drive from desktop into the "Login Items" list (e.g. Public here)
Finally, drag the network drive from desktop into the Finder left pane to make it available from Finder.

Friday, August 1, 2014

CentOS: yum hangs on "Loading mirror speeds from cached hostfile"

> sudo yum install cpan
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
...
Disable this behavior with:
> vi /etc/yum/pluginconf.d/fastestmirror.conf
enable=0

Thursday, July 31, 2014

CentOS: missing repo

If you get this error with yum:
yum install ...
Error: Cannot find a valid baseurl for repo: base
Then:
vi /etc/yum.repos.d/CentOS-Base.repo
and add
baseurl=http://vault.centos.org/6.3/os/i386/
given that 6.3 is your CentOS version

Thursday, July 24, 2014

CentOS / VirtualBox: copy paste shit from/to Windows and urxvt

#! /usr/bin/perl

sub on_sel_grab {
    my $query = quotemeta $_[0]->selection;
    $query =~ s/\n/\\n/g;
    $query =~ s/\r/\\r/g;
    system( "echo -en " . $query . " | xsel -ibp" );
}
I called it clipboard, saved it to /usr/lib64/urxvt/perl/, and enabled in ~/.Xdefaults:
urxvt*perl-ext-common:      default,matcher,clipboard

Thursday, July 10, 2014

Perl: Epoch to date

perl -e 'print scalar gmtime 1404982047'
Thu Jul 10 08:47:27 2014

Monday, July 7, 2014

Set up Word 2010 / 2013 styles

If when re-opeing your doc, Word decided to turn your existing styles into shit (e.g. 3.4 became 1.49), start all the way from the start:
  • Enable Developer menu: File | Options | Customize Ribbon then tick the Developer checkbox in the right hand side list
  • Then in the new Developer menu, push the Document Template button, and untick the Automatically update document styles checkbox
  • Then follow this tutorial: How to create numbered headings or outline numbering in Word

Friday, July 4, 2014

Blocked loading mixed active content

A workaroung in FF is:
Go to about:config
and
security.mixed_content.block_active_content = false

Tuesday, June 17, 2014

Javascript: force client to reload javascript files

Ctrl+F5

or add a version information in file specification, and change it every time the js file is updated

<script type="text/javascript" src="file.js?1.1"></script>

Thursday, June 5, 2014

OSX: from 10.9.2 to 10.9.3

Install the OS X Mavericks 10.9.3 Update (Combo)
Use MultiBeast 6.3 with this conf.

Reboot, et voila:

Wednesday, June 4, 2014

XEmacs: show ^M (\r)

M-x find-file-literally /path/to/file