Skip to main content

Posts

Showing posts from July, 2023

Making vanilla web-fontend (project with lit, web component) secured (discussions with chatGpt)

Query: I wn complete seperate .css/.scss and .html template file for my webcomponent.js like in angular. But with complete security. In lit. Use any js lib like domPurify, etc. But I wan complete safety. How? ChatGPT said: Thought for 16s Totally doable. Here’s a secure Lit setup with fully separate .html + .scss files , sanitized with DOMPurify , and rendered into the Shadow DOM without sacrificing performance. Folder layout src / lib/ safe- html .js components/ app-shell .html app-shell .scss app-shell .js 1) Install deps npm i dompurify npm i -D sass Vite will compile .scss . We’ll import the compiled CSS as text and attach it via adoptedStyleSheets (fast + memory-friendly). 2) app-shell.html (pure template file) Put your Carbon UI Shell markup here (no scripts). Example stub: < cds-header aria-label = "My App" > < cds-header-name prefix = "IBM" >[Platform] </ cds-header-name > < cds-header-glo...

chatGpt Ans: For using smart pointers demonstration

Question:   suppose string fn1(){ char * cstr=... string str(cstr); free(cstr); return str; } shared_ptr<char*,&free> fn2(){ char *cstr=... shared_ptr<char*,&free> ptr=... return ptr; } unique_ptr<char*,&free> fn3(){ char *cstr=... unique_ptr<char*,&free> ptr=... return ptr; } Compare above 3 Fns wrt memory require, performance upon calling in main(){...} Answer: Let's compare the three functions `fn1()`, `fn2()`, and `fn3()` in terms of memory requirements and performance. 1. `fn1()`: ```cpp string fn1() {     char* cstr = ... // Assuming cstr is allocated dynamically, e.g., using malloc     string str(cstr);     free(cstr); // Release the memory after creating the string     return str; } ``` In this function, memory is dynamically allocated for `cstr`, and then it is used to create a `string` object. After creating the `string`, the memory is explicitly released using `free()`. This approach has an a...

gBard Ans: For using smart pointers demonstration

 Question suppose string fn1(){ char * cstr=... string str(cstr); free(cstr); return str; } shared_ptr<char*,&free> fn2(){ char *cstr=... shared_ptr<char*,&free> ptr=... return ptr; } unique_ptr<char*,&free> fn3(){ char *cstr=... unique_ptr<char*,&free> ptr=... return ptr; } Compare above 3 Fns wrt memory require, performance upon calling in main(){...} Answer: Sure, I can compare the three functions you have provided. Function Memory required Performance fn1() Allocates memory for the char* pointer and the string object. The string object will be copied when the function returns. fn2() Allocates memory for the char* pointer and the shared_ptr object. The shared_ptr object will keep a reference to the char* pointer, so the memory will not be deallocated until the shared_ptr object goes out of scope. fn3() Allocates memory for the char* pointer and the unique_ptr object. The unique_ptr object will take ownership of the char* point...