Thursday 28 May 2020

Update Random Value in Column Using PostgreSQL


Add Random Value Column In PostgreSQL Table
    Add Random Value Column In Existing Table
Create Random uuid Without postgresql extension

Test Query :

SELECT uuid_in(md5(random()::text || clock_timestamp()::text)::cstring);

Update Example :

update product
set random_uuid =
uuid_in(md5(random():: text || clock_timestamp():: text):: cstring);

Check IS random_uuid in Uniq Using :

SELECT (product.random_uuid):: text, count(*)
FROM product
GROUP BY product.random_uuid
HAVING count(*) > 1


Saturday 16 May 2020

Nest Js Serve Static File , Image and Download Pdf File



import { ControllerGetPostResParamReqHeader } from '@nestjs/common';
import { fsRoot } from './server-config';
import { createReadStream } from 'fs';
import { join } from 'path';
import url = require('url');

@Controller()
export class AppController {

    @Get('/upload/:fileId')
    async serveAvatar(@Param('fileId'fileId, @Res() res): Promise<any> {
        return res.sendFile(fileId, { root: 'upload' });
    }

// serve all nested folder
// @Get('/upload/*')
     // async serveAvatar(@Req() req, @Res() res): Promise<any> {
// const urlObject = url.parse(req.urltrue);
     //    const filePath = decodeURI(urlObject.path).replace('/api/upload/''');
     //    return res.sendFile(filePath , { root: 'upload' });
     // }


    @Get('/test')
    //@Header('Content-Type', 'application/pdf')
    getTest(@Res() response) {
        const url = join(fsRoot(), '/upload/test.pdf');
        const data = createReadStream(url);
        response.setHeader('Content-Type''application/pdf');
        response.setHeader('Content-Disposition''attachment; filename=another.pdf');
        data.pipe(response);
    }
}

// Create upload folder on your project root dir
// If you set app.setGlobalPrefix("api");
// image is serve on http://localhost:3000/api/upload/a.png
// pdf file is serve on http://localhost:3000/api/upload/test.pdf

// **************** server-config.ts Code ****************************

import path = require('path');

export const fsRoot = () => {
     return path.resolve(__dirname'../');
};


Thursday 14 May 2020

React Js and Backbone Js Compare , Read React Internal Code


React Js Link



Backbone Js Link




React Js 
  
  Line Code  :  3318
  Empty catch Block : 2 ( catch (e) {} )
Todo: 12
 setTimeout  use in  8 to 10 Place

I found This Four eslint-disable

/* eslint-disable no-unused-vars */
// eslint-disable-line no-new-wrappers
// eslint-disable-next-line react-internal/no-production-logging
/* eslint-disable no-var */


Despite all these additions, React 16 is actually smaller compared to 15.6.1!

  • react is 5.3 kb (2.2 kb gzipped), down from 20.7 kb (6.9 kb gzipped).
  • react-dom is 103.7 kb (32.6 kb gzipped), down from 141 kb (42.9 kb gzipped).
  • react + react-dom is 109 kb (34.8 kb gzipped), down from 161.7 kb (49.8 kb gzipped).



Backbone Js 

 Backbone.js    Size  7.9kb, Packed and gzipped
 
6.78kb, Minified and Gzipped

   Underscore provides over 100 functions that support both your favorite workaday functional       helpers: mapfilterinvoke — as well as more specialized goodies: function binding, javascript templating,   creating quick indexes, deep equality testing, and so on.

jquery-3.5.1.min.js    Size  31.4 kb 

Backbone + Underscore + jquery-3.5.1 = 46.08  kb



React is Only a view layer . React Provide View Related Function 
React not include Router,Model and Collection or Function like Underscore or Jquery. 

in Any Application You Need a Router , jquery Like Plugin Pattern , Underscore 
like functional programming .

Backbone Provide You a View , Model , Collection and Router 

You Can add a Epoxy.js : Data Binding for Backbone 2k-gzip size
  • Computed Model & View Attributes
  • Declarative View Bindings
  • Automated Dependency Mapping
  • Automatic View Updates

Read This ( i think this website name should be youneedjquery )
99% case jquery code is small, readable and support a chaining and advance extra
feature and error handling in case of  Element is empty , null or undefined .
http://youmightnotneedjquery.com/

all new javascript framework or lib is like a virus in the programming community, is that not only is it completely brain death , but the people who use it go on to infect other people who can't think for themselves.