Monday, 28 June 2021

Chart with mongodb and php

 https://github.com/sikrigagan/PHP-MongoDB-Charts/blob/master/index.php

PostGresql

 

Introduction

PostgreSQL is an efficient and flexible database that fits a wide variety of use cases. In this guide, you will learn about different ways to query a PostgreSQL database so that you can create a simple and expressive backend to your app or library.

Let's dive in!

SELECT Statements

The SELECT statement is the fundamental building block of querying your PostgreSQL database. SELECT statements can include several clauses. Some of the more important clauses include:

  • FROM
  • WHERE
  • GROUP BY
  • ORDER BY
  • LIMIT

The following query showcases a SELECT statement that uses all of the clauses mentioned above.

1SELECT id, first_name, last_name
2FROM person
3WHERE age > 20
4GROUP BY country
5ORDER BY last_name
6LIMIT 10
sql

The above query will grab the first 10 people over the age of 20 from the person table ordered by their surname and grouped by the country in which they reside. As you can see, a set of columns follows the SELECT keyword in the query. From there, you can specify one or more tables using the FROM clause. The WHERE clause is used to filter your returned rows. The GROUP BY clause is used to group rows together by one or more columns, while the ORDER BY clause is used to order rows in ascending or descending order. The LIMIT clause is used to limit the number of rows returned by the query.

There are many more clauses that can be used. Some of these include the different joining clauses and the OFFSET clause, but these are beyond the scope of this guide. For more information, please check out the documentation.

WITH Queries - Common Table Expressions

WITH queries, or common table expressions, provide a succinct way to create temporary tables that are only kept in memory until the final query is completed. WITH queries are often much faster and more readable than creating multiple temporary tables from which to query as well. The below SQL uses a common table expression to select the average ages for dogs and people by their countries.

1WITH dog_ages AS (
2    SELECT AVG(age) AS avg_dog_age, country 
3    FROM animals
4    GROUP BY country 
5    WHERE species = 'dog'
6), person_ages AS (
7    SELECT AVG(age) as avg_person_age, country 
8    FROM person
9    GROUP BY country
10)
11SELECT da.avg_dog_age, pa.avg_person_page, da.country
12FROM dog_ages da
13LEFT JOIN person_ages pa ON pa.country = da.country;
sql

As you can see, common table expressions are a powerful and expressive means of querying your PostgreSQL database. Remember that anywhere you are using a temporary table, you can probably use a common table expression instead and get faster results!

Views

The view is PostgreSQL's way of encapsulating queries such that they can be reused in different parts of your database schema. A view makes it so that your query can be used by other queries, triggers, or functions all across your database. The below SQL is an example of a view that is used to query our mocked person table.

1CREATE VIEW vw_person_seniors AS
2    SELECT p.id, p.age, p.first_name, p.last_name
3    FROM person p
4    WHERE age >= 65;
sql

Apart from making your queries reusable, views are a great means of making your backend code more readable and maintainable. By creating views, you can structure your queries such that they are separated out by features found within your app. This can dramatically improve the maintainability and separation of concerns within your app's architecture.

Materialized Views

A materialized view is a view that is immediately executed at the time of creation. The results of the query executed by the view are stored on disk and are retrieved when the materialized view is queried. This is huge in terms of performance! A query that takes seconds can be reduced to milliseconds. Below, you can see an example materialized view.

1CREATE MATERIALIZED VIEW mat_person AS
2    SELECT p.id, p.age, p.first_name, p.last_name
3    FROM person p
4    INNER JOIN blog_posts bp ON bp.person_id = p.id;
sql

The biggest downside to using materialized views is that, unless you refresh them by running REFRESH MATERIALIZED VIEW <mat_table>, you may have stale data when you query the view. This is why materialized views work best when the data you are querying is mostly static and rarely updated.

Conclusion

In this guide, you learned all about the key methods for querying data in PostgreSQL. You learned how SELECT queries comprise the fundamental base for querying a PostgreSQL database and how CTEs (Common Table Expressions) can be used to combine temporary tables together. Building on top of the SELECT query, you learned how to create PostgreSQL views to organize your queries in an elegant manner. You also learned how to utilize materialized views to gain massive performance boosts to your queries when the possibility of stale data is not a problem for your user base.

You can now be confident when it comes to querying your PostgreSQL database. For more information, please check out the PostgreSQL documentation.

Saturday, 26 June 2021

envato market

 https://preview.themeforest.net/item/appino-a-perfect-mobile-app-landing-page/full_screen_preview/20601547?_ga=2.176703333.1183745144.1624691820-125615860.1589778961

Sunday, 20 June 2021

Ionic Storage

Store key for ionic async this.storage.get 


  You can't store object in storage.set() but you can do this:
  
  this.storage.set('key'JSON.stringify(value));
  and then get it:
  
  this.storage.get('key').then((value) => {
      let json_value = JSON.parse(value);

 }); 

Array Push After Creating Object JS

 let course = {
    name: 'Angular',
};

let newCourse= Object.assign({}, course);
newCourse.name= 'React';

console.log(course.name); // writes Angular
console.log(newCourse.name); // writes React

For Nested Object we can use of 3rd party libraries, for deep copying objects. In case of lodash, use _.cloneDeep()
let newCourse= _.cloneDeep(course);

https://stackoverflow.com/questions/39506619/angular2-how-to-copy-object-into-another-object/44199667

Angular - Ionic. Enlarge Photo Viewer

 


https://stackblitz.com/edit/angular-bkosu5?file=src%2Fapp%2Fapp.component.css


https://morioh.com/p/6bd2fa8478c4

Wednesday, 16 June 2021

PHP-JWT


Note that, by default, Apache will not pass the HTTP_AUTHORIZATION header to PHP. The reason behind this is:

The basic authorization header is only secure if your connection is done over HTTPS, since otherwise the credentials are sent in encoded plain text (not encrypted) over the network which is a huge security issue.

I fully appreciate the logic of this decision. However, to avoid a lot of confusion, add the following to your Apache configuration. Then the code will function as expected. If you’re using NGINX, the code should function as expected:

RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]


https://www.sitepoint.com/php-authorization-jwt-json-web-tokens/ 

Sunday, 13 June 2021

Format Date ( ) JS Functionalities

 https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date

Thursday, 10 June 2021

Install Chocolatey and Update node.js

 https://docs.chocolatey.org/en-us/choco/setup

choco install python
choco upgrade chocolatey

Wednesday, 2 June 2021

Session (Native Php)

Maybe depending on PHP settings, but if return values are not the above, then go for this:
_DISABLED = 0
_NONE = 1
_ACTIVE = 2



Universal function for checking session status.

start session

<?php
/**
* @return bool
*/

function is_session_started()
{
    if ( 
php_sapi_name() !== 'cli' ) {
        if ( 
version_compare(phpversion(), '5.4.0''>=') ) {
            return 
session_status() === PHP_SESSION_ACTIVE TRUE FALSE;
        } else {
            return 
session_id() === '' FALSE TRUE;
        }
    }
    return 
FALSE;
}

// Example
if ( is_session_started() === FALSE session_start();
?>


Unset

<?php
// remove all session variables
session_unset();


Destroy

// destroy the session
session_destroy();
?>


Notes

As a shorthand you can use
@session_start()
with the @ at the beginning to suppress the
PHP notice "A session had already been started - ignoring session_start()"

As stated in the manual for session_start(), a second call will do no harm,
it will be simply ignored. But you need the @, if you don't want to get the notice.

Put Cookie in prestashop 1.5 and 1.6

 Today I will show you how can you simple set and get your custom cookie variable.

It is useful when you want to keep locally on user’s PC some settings.

Setting cookie

$this->context->cookie->__set('your_cookie_name', 'your cookie value');
$this->context->cookie->write();

Getting cookie

$this->context->cookie->__get('your_cookie_name');

Check if cookie exists

$this->context->cookie->__isset('your_cookie_name');

Deleting cookie

$this->context->cookie->__unset('your_cookie_name');

Final words

Remember – if you don’t have access to $this->context, you can replace it with Context::getContext().

That’s all – as simple as that!


Reference Tutorial

https://prestacraft.com/tutorials/

Put Cookie in prestashop 1.5 and 1.6

 


Tuesday, 1 June 2021

array shift after export pdf array (col header, value row)

 Shift off the first item to get the keys:

$keys = array_shift($array);

Then map array_combine over the rest of it using the array of keys.

$result = array_map(function($values) use ($keys) {
    return array_combine($keys, $values); }, $array);

Based on the code shown in your edit, it looks like you could actually do this as you build the array instead if you replace $rows[] = $cells; with:

if (isset($keys)) {
$rows[] = array_combine($keys, $cells);
} else {
$keys = $cells;
}