Wednesday, January 29, 2020

random choose small set of rows from oracle table

1) count total number of record from the table
    select count(*) from customers;

2)100 records out of 100000, is 100/100000 = 0.1 percent

3) use following query
  select * from customers SAMPLE(0.1), which will return 100 records randomly each time


Thursday, January 16, 2020

Oracle nested collection test code

set SERVEROUT ON;
DECLARE

TYPE VARCHAR_TABLE IS TABLE OF VARCHAR2(64);
TYPE VC_VARCHAR_TABLE IS TABLE OF VARCHAR_TABLE INDEX BY VARCHAR2(64);

v_t1 VARCHAR_TABLE := VARCHAR_TABLE ('abc1','abc2','abc3');
v_t2 VARCHAR_TABLE := VARCHAR_TABLE();

v_t3 VC_VARCHAR_TABLE;

BEGIN
    v_t2.EXTEND(4);
    v_t2(1) := 'test1';
    v_t2(2) := 'test2';
    v_t2(3) := 'test3';
   
    DBMS_OUTPUT.PUT_LINE('VALUE in v_t1 3 is ' || v_t1(3));
    DBMS_OUTPUT.PUT_LINE('VALUE in v_t2 3 is ' || v_t2(3));
   
    v_t3('a1') := v_t1;
    v_t3('a2') := v_t2;
   
    DBMS_OUTPUT.PUT_LINE('VALUE in v_t3 2 is ' || v_t3('a2')(2));
   
END;
/



-----------------------------------------------------------------------------------------

VALUE in v_t1 3 is abc3
VALUE in v_t2 3 is test3
VALUE in v_t3 2 is test2


PL/SQL procedure successfully completed.

Wednesday, January 8, 2020

try rxjs in chrome devtool

1)  got o https://rxjs-dev.firebaseapp.com/
2) press F11 to open devtools, you should see the welcome messages, like this
 ____           _ ____     
|  _ \ __  __  | / ___|   
| |_) |\ \/ /  | \___ \ 
|  _ <  >  < |_| |___) |   
|_| \_\/_/\_\___/|____/

started experimenting with RxJS:

type this into the console:

rxjs.interval(500).pipe(rxjs.operators.take(4)).subscribe(console.log)

3) now you can type any code in console to test rxjs
4) one thing need pay attention is that do not use any import since we are inside the js document
if we want use anything in rxjx like this (import { scan } from 'rxjs/operators';)
we should  use it like this
 scan = rxjs.operators.scan;
 fromEvent = rxjs.fromEvent;
fromEvent(document, 'click') .pipe(scan(count => count + 1, 0)) .subscribe(count => console.log(`Clicked ${count} times`));

Monday, March 5, 2018

aws cli result filter

aws lambda list-functions --query 'Functions[0]'



aws lambda list-functions --query 'Functions[*].{functionName:FunctionName, env.stage:Environment.STAGE, Handler:Handler, ModifiedAt:LastModified}'


aws lambda list-functions --query 'Functions[*].[FunctionName, Handler, LastModified]'

aws lambda list-functions --query 'Functions[?Handler==`handler.getVehicles`]'

Tuesday, January 23, 2018

angularJS DI

The DI in Angular basically consists of three things:
  • Injector - The injector object that exposes APIs to us to create instances of dependencies.
  • Provider - A provider is like a recipe that tells the injector how to create an instance of a dependency. A provider takes a token and maps that to a factory function that creates an object.
  • Dependency - A dependency is the type of which an object should be created.

Tuesday, August 29, 2017

Friday, August 25, 2017

powershell code that copy big file and show progress bar

1) copy following code into powershell console

function Copy-File {
    param( [string]$from, [string]$to)
    $ffile = [io.file]::OpenRead($from)
    $tofile = [io.file]::OpenWrite($to)
    Write-Progress -Activity "Copying file" -status "$from -> $to" -PercentComplete 0
    try {
        [byte[]]$buff = new-object byte[] 4096
        [int]$total = [int]$count = 0
        do {
            $count = $ffile.Read($buff, 0, $buff.Length)
            $tofile.Write($buff, 0, $count)
            $total += $count
            if ($total % 1mb -eq 0) {
                Write-Progress -Activity "Copying file" -status "$from -> $to" `
                   -PercentComplete ([int]($total/$ffile.Length* 100))
            }
        } while ($count -gt 0)
    }
    finally {
        $ffile.Dispose()
        $tofile.Dispose()
        Write-Progress -Activity "Copying file" -Status "Ready" -Completed
    }
}

2)use following command to copy file and show progress bar in powershell console
Copy-File -from FromFileLocationAndName -to toFileLocationAndName