Thursday, January 13, 2022

VMWARE extend LVM partition in linux using GPARTED

 A lot of instructions can be found on the internet with the most official this one [Complete Guide] How to Increase space on Linux vmware. This guide is creating a new partition and connecting it to the LVM. The following steps are extending the existing partition and the LVM.

 

Before I bumped into this article I did my one things which where not complying with the above guide so I could not use it. So I will describe you my steps and you can use them as more easy way to extend LVM

  1.  Added extra space from VMWARE. 
    1. Virtual machine settings -> Hard Disk -> Expand
  2. Logged in my Fedora and with gparted I extended my disk
  3. Then open terminal and type  lvdisplay to find the logical volume you want to extend. You will see something like that :

  --- Logical volume ---
  LV Path                /dev/fedora/root
  LV Name                root
  VG Name                fedora
  LV UUID                5pueVE-DkS9-9KdL-u39f-qlYq-4Yo2-3brBlu
  LV Write Access        read/write
  LV Creation host, time 192.168.120.133, 2017-01-27 15:59:57 +0200
  LV Status              available
  # open                 1
  LV Size                <43.27 GiB
  Current LE             11076
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/fedora/home
  LV Name                home
  VG Name                fedora
  LV UUID                mi5PEa-MLZB-0TM5-tD3S-9w5w-eKSq-j09GW3
  LV Write Access        read/write
  LV Creation host, time 192.168.120.133, 2017-01-27 15:59:59 +0200
  LV Status              available
  # open                 1
  LV Size                <33.67 GiB
  Current LE             8619
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

4. Then type the following command: lvresize -L +5G /dev/fedora/home
5. Then type the following command: df -h to find the filesystem name.

Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 5.9G     0  5.9G   0% /dev
tmpfs                    5.9G     0  5.9G   0% /dev/shm
tmpfs                    2.4G  2.1M  2.4G   1% /run
tmpfs                    4.0M     0  4.0M   0% /sys/fs/cgroup
/dev/mapper/fedora-root   43G   39G  2.1G  96% /
tmpfs                    5.9G   44K  5.9G   1% /tmp
/dev/sda1                976M  225M  684M  25% /boot
/dev/mapper/fedora-home   34G   26G  5.7G  83% /home
overlay                   43G   39G  2.1G  96% /var/lib/docker/overlay2/85bc5ded5006148967e7b5618e8844cc2c2b614af1bc3ca47a764e8ae7b44935/merged
tmpfs                    1.2G  168K  1.2G   1% /run/user/1000

 6. Finally type the following command: resize2fs -p /dev/mapper/fedora-home


 

 


Wednesday, November 15, 2017

Javascript: Convert image binary to base64 string

private convertImagetoURI(data): string {
let str = data.reduce(function (a, b) { return a + String.fromCharCode(b) }, ”);
return btoa(str).replace(/.{76}(?=.)/g, ‘$&\n’);
}

Considering that you get the image as binary data from an API call, use the above the function to pass the response and get back the string image.

Add it to you src in your image tag:
var imageSRC = ‘data:image/jpeg;base64,’ + this.convertImagetoURI(result.responseObject.Body)

< img src=imageSRC />


In angular2 you have to sanitize the string otherwise you  will get an xss error
import DomSanitizer,
create a variable (e.g sanitizer :Domsanitizer)
use the bypassSecurity* functions

this.sanitizer.bypassSecurityTrustResourceUrl(‘data:image/jpeg;base64,’ + this.convertImagetoURI(result.responseObject.Body)) as string;

Monday, March 30, 2015

Oracle (plsql) scripts


Calculate first and last day of each month


Use the below script to select the last and first day for a number of months.

select trunc(add_months((sysdate),-level),'MM') date_from,
        trunc(add_months(last_day(sysdate),-level)) date_to
   from dual
connect by level < to_char(sysdate,'MM')+12 /*count since first month add +12 for 1 year back etc*/
Two more different approaches for calculation of last day of each month.
select last_day(to_date(t2.yy||'-'||t1.mon||'-01', 'YYYY-MM-DD')) foo
from (select level mon from dual connect by level < 13) t1,
     ( select distinct extract (year from date_period) yy from date_to) t2
order by 1 desc

SELECT LAST_DAY(ADD_MONTHS(TO_DATE('2010-01-01', 'YYYY-MM-DD'), LEVEL-1)) FOO
  from dual m
      CONNECT BY LEVEL<=12*( EXTRACT(YEAR FROM SYSDATE)-2009 )
order by 1 desc

Function to convert rows in separated-string

create or replace function append_field(sqlstr in varchar2, sep in varchar2 )
return varchar2 is
  ret varchar2(4000) := '';
  type cur_typ is ref cursor;
  rec cur_typ;
  field varchar2(4000);
begin
     OPEN rec FOR sqlstr;
     LOOP
         FETCH rec INTO field;
         EXIT WHEN rec%NOTFOUND;
         ret := ret || field || sep;
     END LOOP;
     if length(ret) = 0 then
          RETURN '';
     else
          RETURN substr(ret,1,length(ret)-length(sep));
     end if;
end;

Function of oracle to convert rows in separated-string

select comp_emp.department , 
       listagg(user_login, ',') within group (order by department) as employees
  from comp_emp, employees, supplier_addresses
 where comp_emp.emp_code = employees.emp_code 
   and comp_emp.company = supplier_addresses.recno 
   and comp_emp.company in ( to_date('13-05-1926 15:02:34','DD-MM-YYYY HH24:MI:SS') )
  group by  comp_emp.department

Wednesday, April 4, 2012

BIRT :: Tips&Tricks

Tips and tricks for using BIRT functions.

Contents

  • 1 Get Parameters Value/Display Text
  • 2 Cascaded Parameters
  • 3 Get query text from data set
  • 4 Dynamic query
  • 5 Get the first day of month
  • 6 Get the last day of previous month
  • 7 Get the previous quarter day (since now)
  • 8 Display the values of a Multiple Values ListBox parameter
  • 9 Pass Multiple values from List Box to a query
  • 10 Increase Page Break Rows
  • 11 Drill-through
  • 12 Dynamic Chart Size
  • 13 Rownum for sorted crosstab
  • 14 Internet explorer (IE) compatibility problem
  • 15 External Links with tips

Get Parameters Value/Display Text


BIRT Parameters are stored in a params table.

You can get a value from the table using

params["parameter_name"].value
You can get the Display Text of a value using

params["parameter_name"].displayText

Cascaded Parameters

When the user selects the first level parameter in a cascaded parameter group the second level in the group is automatically re-queried.

Cascaded Parameters


Get query text from data set

You can get the query string using

this.queryText

Dynamic query


1. On initialize script add the below JavaScript query

function buildWhereClause(paramName, fieldName) {
 var paramVal = reportContext.getParameterValue(paramName); 
 
 if (paramVal == null || paramVal == "ALL" || paramVal == "") {
  return "";
 } else {
      return " where "+ fieldName + "= '" + paramVal +"'"; 
 }
 }

2. On the beforeOpen script of the main data set, where your main query is, add the below JavaScript

// Parameters are used to create a dynamic conditional clause. 
// The buildWhereClause function is in the Initialize of the report. 

var where = " ";

where += buildWhereClause("fieldName", "paramVal");

var sql = "";
 sql += " REWRITE YOUR MAIN QUERY HERE ";
    sql += where;
     
this.queryText = sql;
In fieldName and paramVal add the name of your query filed (participating in the main query) and the name of the Parameter you use for filtering.


Get the first day of month

Use the following expression to get it

BirtDateTime.addDay(BirtDateTime.today(),1-BirtDateTime.day( (BirtDateTime.today()) ))

Get the last day of previous month


Use the following expression to get it

BirtDateTime.addDay(BirtDateTime.today(),-BirtDateTime.day( (BirtDateTime.today()) ))

Get the previous quarter day (since now)

BirtDateTime.addDay(BirtDateTime.addQuarter(BirtDateTime.today(),-2),-BirtDateTime.day( (BirtDateTime.today()) )+1)

Display the values of a Multiple Values ListBox parameter


Just place a data value field in your report, set the data Type of the parameter as Java Object and the parameter expression params["parameter_name"].value.

Pass Multiple values from List Box to a query

On the before open script add the bellow function to rewrite the query with a where clause.

function MultiParameters(parameter){
 var parmcount = parameter.value.length;
 var whereclause = "";

 whereclause = " where code in ( '";
 for ( i=0; i < parmcount; i++ ){
  if( i == 0 ){
   whereclause = whereclause + parameter.value[i];
  } else {
   whereclause = whereclause + "' , '" + parameter.value[i];
  }
 }
 whereclause = whereclause + "' ) ";
 
 return whereclause;
}


this.queryText  = "select * from invoices ";
this.queryText  = this.queryText  + MultiParameters(params["department"]);

Increase Page Break Rows

Select the table from the report, go to Properties -> Page Break and in Page Break Interval add more rows.

Drill-through


Select the element from the table, on property editor Hyperlink clik edit, select Drill-through, select the Report Design, enter the Report Parameters and any other possible options and click ok.

In case the path of the drilled through report is not correct or not working try changing the WORKING_FOLDER_ACCESS_ONLY to false in the web.xml (/var/lib/tomcat5/webapps/birtXXX/WEB-INF/web.xml) and restart tomcat.


This happens because the working directory (defined in web.xml) is not exactly the same case as the actual directory where your reports are located.

Dynamic Chart Size

In this example we resize the chart based on output format.

If you want the chart to resize based on the data populated in the chart data sets it requires a little bit of a work around. First, name the chart as with the simple chart API and enter the following code in your beforeFactory event handler.

var mychart = this.getReportElement( "mychart" );
mychart.setWidth("");
mychart.setHeight("");



After you have done that, enter code similar to the following in your afterDataSetFilled chart event handler.

function afterDataSetFilled(series, dataSet, icsc)
{
if( series.getSeriesIdentifier() == "seriesone" ){
if( dataSet.getValues().length > 4 ){
 icsc.getChartInstance().getBlock().getBounds().setWidth(800);
 icsc.getChartInstance().getBlock().getBounds().setHeight(600);
}else{
 icsc.getChartInstance().getBlock().getBounds().setWidth(400);
 icsc.getChartInstance().getBlock().getBounds().setHeight(300);

}
}
}
In this example we have named our series “seriesone” on the third tab of the chart wizard.

If the category values contain more than four entries we double the size of the chart. The sizing could be more dynamic, for example we could use the list size to increment a delta per category as well.

This example works with BIRT 2.2.2, but will not work with the chart output type set to SVG, when rendering to HTML.

Source: Resizing Charts


Rownum for sorted crosstab

Put something like: var i = 0, in your initialize script.

Then, instead of trying to use your rownum field as a dimension, just put a 2 column / 1 row grid in where your name field is.

Put the name field in the right cell and a dynamic textbox in the left cell. For the dynamic textbox expression, put i++; i;.

Now, for each row, the variable i will increment and then display in the textbox, giving you a row number.

Source: Rownum for sorted crosstab

Internet explorer (IE) compatibility problem


In case Internet explorer needs compatibility mode to show the report, try adding the following code on <head> section to the
webapps/birt/webcontent/birt/pages/layout/FramesetFragment.jsp (line 46)

<!-- Mimics Internet Explorer 7, it just works on IE8. -->
<META HTTP-EQUIV="X-UA-Compatible" CONTENT="IE=EmulateIE7">

External Links with tips

Tips&Tricks

Thursday, May 6, 2010

Six Cool PHP Tricks You May Not Know

Over the years I've come across some useful tricks in PHP that are not obvious, but are worth mentioning. This is not meant to be a comprehensive list of all the useful tricks that you can do with PHP.

1. Count Characters in a String

To do this, I've usually just used the function strlen(). However, there is a faster method. Take a look at the following code example:
<?php
$string = 'testing';

if(isset($string[6]))
	echo "The string '$string' is at least 7 characters long.";
else
	echo "The string '$string' is less than 7 characters long.";
You treat the $string value like an array by passing an integer value to isset(). If that number plus one is greater than or equal to the number of characters in the string, it will return true. You need to add one because it is zero based.
2. Use PHP Echo like a Function
I've always thought that if you wanted to concatenate strings with echo, you needed to use periods. But you can actually treat echo like a function and use commas instead (it is also faster). Take a look at the following code:
<?php
$string1 = 'test-string1';
$string2 = 'test-string2';
$string3 = 'test-string3';

echo 'String #1: ', $string1, '<br />';
echo 'String #2: ', $string2, '<br />';
echo 'String #3: ', $string3, '<br />';

3. Use Single Quotes When Possible

By using single quotes instead of double quotes, you save PHP from having to parse your string for variables. It not only is faster, but I find it more programmer-friendly because it is easier to find variables in your code.
Also, when referencing an array that has a string index, always use single quotes. This prevents PHP from having to figure out exactly what you were trying to say.

4. PHP Variable Variables

There have been several cases when I needed to access a dynamic variable (where the variable name changed). You can do this easily in PHP by using what is called Variable Variables. Take a look at this example:
<?php
$var1 = 'nameOfVariable';
$nameOfVariable = 'This is the value I want!!!';

echo $$var1;

5. Use Arrays in Form Fields

Not only can you create a form field that creates an element in an array (like name['firstname'] ), but you can create dynamic arrays as well. This is especially useful in checkboxes, where the user could check multiple options. Take a look at this HTML:
<label><input type="checkbox" name="hobbies[]" value="Sports" /> Sports</label><br />
<label><input type="checkbox" name="hobbies[]" value="Hiking" /> Hiking</label><br />
<label><input type="checkbox" name="hobbies[]" value="Swimming" /> Swimming</label><br />
<label><input type="checkbox" name="hobbies[]" value="Swimming" /> Watching Movies</label><br />
When the above fields are posted to a PHP page, each hobby is added to the hobbies array. You can then loop through that array and access each value that was checked.

6. PHP Output Buffering

I have come across cases where something was being output to the screen that I didn't want (at least at that point, or maybe not at all).
A common example of this is if you have a function or a script that echoes out a string, but you are using the code in that instance where you don't want it to print to the screen at that point (when using a template system or framework system, for example). In this case you would still want to be able to reuse the code, but just prevent anything from being printed out at that exact point.
This will make more sense if you look at this simple example:
<?php
ob_start();

echo 'Print to the screen!!!';
$getContent = ob_get_contents();

ob_end_clean();

// Do whatever you want...

// Do something with the printed content (only if you want)...
echo 'Now: ' . $getContent;
You probably were familiar with at least some of these, but I hope that someone will find this list useful in some capacity. :)

Wednesday, March 31, 2010

Rename files with shell script

Rename a large list of files with names containing spaces and different characters

All the job is done using the tr command.


The following script i found on a Archlinux Forum Post changes spaces to underscores, remove characters like {}(),\! and convert the filenames to lowercase.

#!/bin/bash
ls | while read -r FILE
do
mv -v "$FILE" `echo $FILE | tr ' ' '_' | tr -d '[{}(),\!]' | tr -d "\'" | tr '[A-Z]' '[a-z]' | sed 's/_-_/_/g'`
done

The following script just changes spaces to underscores.

#!/bin/bash
ls | while read -r FILE
do
mv -v "$FILE" `echo $FILE | tr ' ' '_' `
done



Great everyday scripts. Thanks paramthegreat (Article post)

Thursday, October 22, 2009

OCI8

You need the following (once logged in) from Oracle Instant Client:

  • oracle-instantclient-basic
  • oracle-instantclient-devel

You also need to install two PHP related packages, namely:

  • php-pear
  • php-devel

You might need to update the channel data of pear and pecl by:

  • pear channel-update pear.php.net
  • pecl channel-update pecl.php.net

Now you should be able to install oci8 with the following command:

  • sudo pecl install oci8

Finally edit /etc/php.ini and add the line bellow in the extensions section:

  • extension=oci8.so

See also the php-oracle manual

Example

       # Here's how we connect:
$dbh = oci_connect ('USERNAME', 'PASSWD', '//172.31.5.337:1521/ORACL');
# Here's how we pass an sql statement:
$stmt = oci_parse ($dbh, 'SELECT USERNAME, PASSWORD FROM TABLE');
# Here we execute the statement:
oci_execute ($stmt);
$cnt = 1;
# Then we fetch rows in a loop until we're done
while ($result = oci_fetch_array($stmt)) {
echo "user: " . $cnt . " " . $result['USERNAME'] .
" " . $result['PASSWORD'] . "
";
$cnt = $cnt +1;
}
# last we close the database handle
oci_close($dbh);
# and note to the parser that this is the end of the php code section