Tuesday, December 3, 2019

Oracle database

select * from sample_db where 
id =1
and 
(name like '%praveen%'
or name like '%naveen%')

SQL CONSTRAINTS

primary key
CREATE TABLE sbanks (
    ID int NOT NULL,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    Age int,
    PRIMARY KEY (ID)
);
TO ADD PRIMARY KEY CONSTRAINT TO EXISTING TABLE ie for one column.
 syntax
ALTER TABLE sbank
ADD PRIMARY KEY (ID);
imp:u can have primary key constraint one only.
now to add primary key constraint for more than one column to already existing table with primary constraint
you have to delete existing primary key,and add  new primary key constraint.
DROP a PRIMARY KEY Constraint

syntax
ALTER TABLE sbank
DROP PRIMARY KEY;
o/p
 MySQL returned an empty result set 
now adding primary key constraint for two columns
ALTER TABLE sbank
ADD CONSTRAINT PK_sbank PRIMARY KEY (ID,LastName)
o/p
MySQL returned an empty result set
here PK_sbank is the constraint name.

DATABASE column name search in all tables /schemas
select c.tabschema as schema_name,
       c.tabname as table_name,c.colname
from syscat.columns c
inner join syscat.tables t on 
      t.tabschema = c.tabschema and t.tabname = c.tabname
where c.colname like '%PRODUCT_NUMBER%' and t.type = 'T'
order by schema_name,table_name;
for more details https://dataedo.com/kb/query/db2/find-tables-with-specific-column-name
https://dataedo.com/kb/query/db2
SEARCH TABLES QUERY
select name from sysibm.systables 
where name like '%ISP%' 
and type = 'T'
EASY CONCATENATE STRINGS IN EXCEL AND SEARCH THE STRING IN DB
="'"&A1&"',"
DB2 
SELECT * FROM customers FETCH FIRST 1 ROWS ONLY
http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html?ssSourceSiteId=otnpt


SQL joins are used to combine rows from two or more tables.
Types of Joins:
INNER JOIN: Returns all rows when there is at least one match in BOTH tables
EG: view Intersection (matching data in two tables) of two table’s data.
Syn: SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name=table2.column_name;


LEFT JOIN: Return all rows from the left table, and the matched rows from the right table
EG : view Table 1’s + Intersection (matching data in two tables) of two table’s data
Description: SQL LEFT JOIN
Syn: SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name=table2.column_name;
RIGHT JOIN: Return all rows from the right table, and the matched rows from the left table
EG : Intersection (matching data in two tables) of two table’s data + Table 2’s
Description: SQL RIGHT JOIN
FULL JOIN: Return all rows when there is a match in ONE of the tables
EG : view complete  2 table’s data  (Table1 + Table 2)








Monday, November 18, 2019

soap ui



soap ui file reading via groovy script

for more please refer

// To get the output value, use the built-in result map object
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def projectPath = groovyUtils.projectPath
def directoryName = projectPath + "/testData"
def row = testRunner.testCase.testSteps["DataSource"].currentRow
def allFiles = []
new File( directoryName ).eachFile() { file ->
    if( file.name =~ /.txt/ ) {
        allFiles.add( file.name ) }
}
if ( (row + 1) <= allFiles.size ) {
    // Output to the test step property called inputData
    result["inputData"] = new File( directoryName + "/" + allFiles[row] ).text
}

https://www.soapui.org/scripting-properties/tips-tricks.html

IOT languages

LUA
LUA has emerged as an extensible procedural language that is mostly designed to support procedural programming with powerful data description facilities. Since it is an embedded language, LUA needs to be embedded in a host client in order to function well. To help developers build IoT-enabled applications, LUA offers a framework called Node.lua that is built on lightweight Lua interpreter and libuv for event-driven (non-blocking I/O model).

ParaSail
Parallel Specification And Implementation Language is another unusual language that can build highly parallel yet secure applications which can be mapped to multicore, manycore, heterogeneous, or distributed architectures. ParaSail is a feature-rich language in terms of module parameterization, interface separation from implementation, and module-independent invariants, etc.

PHPoC
Yes, there is a variant of PHP language too available for IoT development. Not only a language but a hardware platform also, PHP on Chip (PHPoC) is a general-purpose language for IoT with most syntaxes and core functions inherited from PHP. Addition of new functions like I/O, UART, I2C, SPI, ADC, TIMER/COUNTER, RTC etc. gives it the ability to interact with hardware peripherals in a better way.

Rust
Similar to C/C++, Rust also conceives fine-grained memory management and low runtime overhead, which makes it a strong candidate in the IoT-friendly language list. Popularly known as an alternative to C, Rust is used for system programming and safeguards memory from getting corrupted. With basic structure and easy to learn syntaxes, Rust has become a language of choice for many IoT developers.

Go

Google’s child, Golang or Go programming language is considered a big player in IoT platform development because of its inherent qualities like inbuilt concurrency and ability to maximising the hardware usage to boost performance. Go’s cloud community support makes it real easy for learners to get acquainted with the knowledge of IoT development super quick and in a very

Tuesday, November 12, 2019

Memory Layout

Memory Layout of C Programs
A typical memory representation of C program consists of following sections.
1. Text segment
2. Initialized data segment
3. Uninitialized data segment
4. Stack
5. Heap


A typical memory layout of a running process

1. Text Segment:
A text segment , also known as a code segment or simply as text, is one of the sections of a program in an object file or in memory, which contains executable instructions.

As a memory region, a text segment may be placed below the heap or stack in order to prevent heaps and stack overflows from overwriting it.





Usually, the text segment is sharable so that only a single copy needs to be in memory for frequently executed programs, such as text editors, the C compiler, the shells, and so on. Also, the text segment is often read-only, to prevent a program from accidentally modifying its instructions.

2. Initialized Data Segment:
Initialized data segment, usually called simply the Data Segment. A data segment is a portion of virtual address space of a program, which contains the global variables and static variables that are initialized by the programmer.

Note that, data segment is not read-only, since the values of the variables can be altered at run time.

This segment can be further classified into initialized read-only area and initialized read-write area.

For instance the global string defined by char s[] = “hello world” in C and a C statement like int debug=1 outside the main (i.e. global) would be stored in initialized read-write area. And a global C statement like const char* string = “hello world” makes the string literal “hello world” to be stored in initialized read-only area and the character pointer variable string in initialized read-write area.

Ex: static int i = 10 will be stored in data segment and global int i = 10 will also be stored in data segment

3. Uninitialized Data Segment:
Uninitialized data segment, often called the “bss” segment, named after an ancient assembler operator that stood for “block started by symbol.” Data in this segment is initialized by the kernel to arithmetic 0 before the program starts executing

uninitialized data starts at the end of the data segment and contains all global variables and static variables that are initialized to zero or do not have explicit initialization in source code.

For instance a variable declared static int i; would be contained in the BSS segment.
For instance a global variable declared int j; would be contained in the BSS segment.

4. Stack:
The stack area traditionally adjoined the heap area and grew the opposite direction; when the stack pointer met the heap pointer, free memory was exhausted. (With modern large address spaces and virtual memory techniques they may be placed almost anywhere, but they still typically grow opposite directions.)

The stack area contains the program stack, a LIFO structure, typically located in the higher parts of memory. On the standard PC x86 computer architecture it grows toward address zero; on some other architectures it grows the opposite direction. A “stack pointer” register tracks the top of the stack; it is adjusted each time a value is “pushed” onto the stack. The set of values pushed for one function call is termed a “stack frame”; A stack frame consists at minimum of a return address.

Stack, where automatic variables are stored, along with information that is saved each time a function is called. Each time a function is called, the address of where to return to and certain information about the caller’s environment, such as some of the machine registers, are saved on the stack. The newly called function then allocates room on the stack for its automatic and temporary variables. This is how recursive functions in C can work. Each time a recursive function calls itself, a new stack frame is used, so one set of variables doesn’t interfere with the variables from another instance of the function.

5. Heap:
Heap is the segment where dynamic memory allocation usually takes place.

The heap area begins at the end of the BSS segment and grows to larger addresses from there.The Heap area is managed by malloc, realloc, and free, which may use the brk and sbrk system calls to adjust its size (note that the use of brk/sbrk and a single “heap area” is not required to fulfill the contract of malloc/realloc/free; they may also be implemented using mmap to reserve potentially non-contiguous regions of virtual memory into the process’ virtual address space). The Heap area is shared by all shared libraries and dynamically loaded modules in a process.

Examples.

The size(1) command reports the sizes (in bytes) of the text, data, and bss segments. ( for more details please refer man page of size(1) )

1. Check the following simple C program

filter_none
edit
play_arrow

brightness_4
#include <stdio.h>

int main(void)
{
    return 0;
}
[narendra@CentOS]$ gcc memory-layout.c -o memory-layout
[narendra@CentOS]$ size memory-layout
text       data        bss        dec        hex    filename
960        248          8       1216        4c0    memory-layout
2. Let us add one global variable in program, now check the size of bss (highlighted in red color).

filter_none
edit
play_arrow

brightness_4
#include <stdio.h>

int global; /* Uninitialized variable stored in bss*/

int main(void)
{
    return 0;
}
[narendra@CentOS]$ gcc memory-layout.c -o memory-layout
[narendra@CentOS]$ size memory-layout
text       data        bss        dec        hex    filename
 960        248         12       1220        4c4    memory-layout
3. Let us add one static variable which is also stored in bss.

filter_none
edit
play_arrow

brightness_4
#include <stdio.h>

int global; /* Uninitialized variable stored in bss*/

int main(void)
{
    static int i; /* Uninitialized static variable stored in bss */
    return 0;
}
[narendra@CentOS]$ gcc memory-layout.c -o memory-layout
[narendra@CentOS]$ size memory-layout
text       data        bss        dec        hex    filename
 960        248         16       1224        4c8    memory-layout
4. Let us initialize the static variable which will then be stored in Data Segment (DS)

filter_none
edit
play_arrow

brightness_4
#include <stdio.h>

int global; /* Uninitialized variable stored in bss*/

int main(void)
{
    static int i = 100; /* Initialized static variable stored in DS*/
    return 0;
}
[narendra@CentOS]$ gcc memory-layout.c -o memory-layout
[narendra@CentOS]$ size memory-layout
text       data        bss        dec        hex    filename
960         252         12       1224        4c8    memory-layout
5. Let us initialize the global variable which will then be stored in Data Segment (DS)

filter_none
edit
play_arrow

brightness_4
#include <stdio.h>

int global = 10; /* initialized global variable stored in DS*/

int main(void)
{
    static int i = 100; /* Initialized static variable stored in DS*/
    return 0;
}
[narendra@CentOS]$ gcc memory-layout.c -o memory-layout
[narendra@CentOS]$ size memory-layout
text       data        bss        dec        hex    filename
960         256          8       1224        4c8    memory-layout

for more refer https://www.geeksforgeeks.org/memory-layout-of-c-program/

Monday, November 11, 2019

What are Web Services?

What is a Web Service?

Web Services work on client-server model where client applications can access web services over the network. Web services provide endpoint URLs and expose methods that can be accessed over network through client programs written in java, shell script or any other different technologies.
Web services are stateless and doesn’t maintain user session like web applications.

Tuesday, September 10, 2019

Linux commands for day to day use

file search
1. print top lines
head sample.log
head -n 20 /path/to/logfile.log

2. print bottom lines
   tail  sample.log
   
terminal commands
control A - begining of the line
control E - end of the line
control right arrow
control left arrow
control U start line delete
control K start from custor delete 


file system

cd 
when folder name has space
cd Exercise Files error
cd Exercise\ Files

ls -R inside directory
ls --color=always


rm -sample?.txt

vs

cat sample.txt | cat -n | tail -n4

grep "hello" sample.txt - simple search
grep -in "hello" sample.txt - with line numbers /ignore case with line numbres
grep -vi "hello" sample.txt - with line numbers /ignore matching case and print remaining
grep -n "hello" sample.txt - with line numbers
grep -E "[hijk]" sample.txt - search for letters and shows the results
grep -E "/w{6,}" sample.txt - count words and shows the results


log analysis with awk command
awk '/error/ {print}' /var/log/syslog
awk '{print $2}' sample.txt
awk '{print $2 "\t" $1}' sample.txt | sort -n  more filter on tablular data 

sed s/Orange/Red/ sample_data  to edit& replace text
s for substitute
g for global replace

sort sample.txt
sort -k2 -n sample.txt sort the data
sort -u sample.txt - remove dublicates only unique print
rev tac tr



tar -xvf log.tar.gz 


log analysis
less filename
cat filename | grep "string" | awk '{print $9}' |sort -u > users.txt

free -h
cat /proc/cpuinfo - c

df -h memory information 





copy the text from ssh editor to local 

cntrl+insert for copy
shift +insert for paste

grep commands for daily use

 grep -B 3 -A 2 'Invalid user' /var/log/auth.log
https://www.loggly.com/ultimate-guide/troubleshooting-with-linux-logs/

scp command to transfer files

1. search text in vi editor

  1. Press ESC key.
  2. Type /vivek.
  3. Hit n to search forwards for the next occurrence of word named “vivek”. You can press N to search backwards.

Find Files linux commad


find / -name "*conf" 
find /home/exampleuser/ -name "*conf" 

2. How to unpack (ungzip, unarchive) a tar.gz file

For many systems, REBOL is distributed as a tar gz file. This is a common archive format. Here's how to unpack it...

For tar.gz

To unpack a tar.gz file, you can use the tar command from the shell. Here's an example:
tar -xzf rebol.tar.gz
The result will be a new directory containing the files.
(Also, on many systems, when you download the tar.gz from a web browser, an unpacker will open, and you can just use that.)

For just .gz (.gzip)

In some cases the file is just a gzip format, not tar. Then you can use:
gunzip rebol.gz
In order to execute it, you will need to add execute permissions to the file:
chmod +x rebol


for more refer below videos on detailed commands


Monday, August 12, 2019

Useful tools

#1. Glitch 

This is a multi-purpose tool that can be used to perform different actions. The Glitch website can help you create web apps in the browser or mix code developed by others. The online platform allows you to check out free apps built by other developers. You can edit any project and have your own app running instantly. Building a project becomes easier with Glitch. 

#2. Codeply 

Codeply is designed for front-end UI developers. You can easily create a responsive design playground using this tool. Codeply has Semantic UI and CSS tools, which are important for front-end developers. 

#3. Regexr 

This tool is basically a tester with syntax highlighting. You can use this online tool to learn, build & test Regular Expressions. Regexr supports JavaScript, PHP, and PCRE RegEx. 

#4. Jex.im 

Jex.im is an open source tool created to help you visualise JavaScript Regular Expressions. Programmers can write regular expressions into an editor and get the visual representation on of how the expressions work. 

#5. Httpie 

Httpie is a command line tool with an intuitive UI, JSON support, syntax highlighting, wget-like downloads, plugins etc. This tool can be used to make HTTP requests to web severs and Restful APIs. It comes with a simple version of CURL. 

#6. Mackaroo 

If you ever need some mock data to test your app, Mockaroo can help in generating up to 1,000 rows of data. The data can be exported in CSV, JSON, SQL, and Excel formats. 

#7. Astexplorer 

This tool allows you to paste JavaScript code into its editor. The web-based tool generates Abstract Syntax Tree, which offers better understanding of how the JavaScript code works.

Vi Editor

VI EDITOR Move move in the editor: h right j up k  down l left move top shift +g gg down the line of the file :8 go to line 8 search /string...