11 Jul 2024

How to Download Protected PDF from Google Drive?

 You can still download the PDF protected with the sharing settings of Google Drive by following these simple instructions:


Method 1. How to Download Protected PDF from Google Drive

Open the protected PDF in Google Drive and take a scrolling screenshot of it using a Chrome extension or any screenshot tool like GoFullPage and export the screenshot in PDF format.

Method 2. How to Download Restricted PDF from Google Drive?


Instructions: Head to your web browser and access Google Drive to access the restricted PDF. Double-click the PDF file to open it and press the "Ctrl + Shift + C" keys on the keyboard while using Windows. Then, hit the "Console" tab next to the "Elements." Afterward, paste the given code into the "Console" and hit the "Enter" key on the keyboard. This will download your PDF file automatically.


let jspdf = document.createElement( "script" );
jspdf.onload = function () {
let pdf = new jsPDF();
let elements = document.getElementsByTagName( "img" );
for ( let i in elements) {
let img = elements[i];
if (!/^blob:/.test(img.src)) {
continue ;
}
let canvasElement = document.createElement( 'canvas' );
let con = canvasElement.getContext( "2d" );
canvasElement.width = img.width;
canvasElement.height = img.height;
con.drawImage(img, 0, 0,img.width, img.height);
let imgData = canvasElement.toDataURL( "image/jpeg" , 1.0);
pdf.addImage(imgData, 'JPEG' , 0, 0);
pdf.addPage();
}
pdf.save( "download.pdf" );
};
jspdf.src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js' ;
document.body.appendChild(jspdf);

For Landscape PDF Code

let jspdf = document.createElement("script");
jspdf.onload = function () {
    let pdf = new jsPDF({ orientation: 'landscape' });
    let elements = document.getElementsByTagName("img");
    for (let i = 0; i < elements.length; i++) {
        let img = elements[i];
        if (!/^blob:/.test(img.src)) {
            continue;
        }
        let canvasElement = document.createElement('canvas');
        let con = canvasElement.getContext("2d");
        canvasElement.width = img.width;
        canvasElement.height = img.height;
        con.drawImage(img, 0, 0, img.width, img.height);
        let imgData = canvasElement.toDataURL("image/jpeg", 1.0);
        pdf.addImage(imgData, 'JPEG', 0, 0);
        pdf.addPage();
    }
    pdf.save("download.pdf");
};
jspdf.src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js';
document.body.appendChild(jspdf);

2 Jul 2024

Various of MySQL statements

 MySQL syntax format emphasizes consistency, readability, and maintainability. Here are detailed guidelines and examples for formatting various MySQL statements:

1. SELECT Statement

sql
SELECT column1, column2, ... FROM table_name WHERE condition GROUP BY column1 HAVING condition ORDER BY column1 [ASC|DESC] LIMIT number;

Example:

sql
SELECT first_name, last_name, birth_date FROM employees WHERE hire_date > '2020-01-01' GROUP BY department_id HAVING COUNT(*) > 5 ORDER BY last_name ASC LIMIT 10;

2. INSERT Statement

sql
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);

Example:

sql
INSERT INTO employees (first_name, last_name, birth_date, hire_date) VALUES ('Jane', 'Smith', '1990-02-15', '2023-06-01');

3. UPDATE Statement

sql
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;

Example:

sql
UPDATE employees SET hire_date = '2023-07-01' WHERE employee_id = 1;

4. DELETE Statement

sql
DELETE FROM table_name WHERE condition;

Example:

sql
DELETE FROM employees WHERE employee_id = 1;

5. CREATE TABLE Statement

sql
CREATE TABLE table_name ( column1 datatype [constraints], column2 datatype [constraints], ... );

Example:

sql
CREATE TABLE employees ( employee_id INT AUTO_INCREMENT PRIMARY KEY, first_name VARCHAR(50) NOT NULL, last_name VARCHAR(50) NOT NULL, birth_date DATE, hire_date DATETIME DEFAULT CURRENT_TIMESTAMP );

6. ALTER TABLE Statement

sql
ALTER TABLE table_name ADD column_name datatype [constraints];

Example:

sql
ALTER TABLE employees ADD email VARCHAR(100) NOT NULL;

7. DROP TABLE Statement

sql
DROP TABLE table_name;

Example:

sql
DROP TABLE employees;

8. CREATE INDEX Statement

sql
CREATE INDEX index_name ON table_name (column1, column2, ...);

Example:

sql
CREATE INDEX idx_last_name ON employees (last_name);

9. DROP INDEX Statement

sql
DROP INDEX index_name ON table_name;

Example:

sql
DROP INDEX idx_last_name ON employees;

10. CREATE VIEW Statement

sql
CREATE VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition;

Example:

sql
CREATE VIEW active_employees AS SELECT first_name, last_name FROM employees WHERE status = 'active';

11. DROP VIEW Statement

sql
DROP VIEW view_name;

Example:

sql
DROP VIEW active_employees;

12. Transaction Statements

  • START TRANSACTION: Begins a new transaction.
  • COMMIT: Saves the changes made in the transaction.
  • ROLLBACK: Reverts the changes made in the transaction.

Example:

sql
START TRANSACTION; UPDATE accounts SET balance = balance - 100 WHERE account_id = 1; UPDATE accounts SET balance = balance + 100 WHERE account_id = 2; COMMIT;

13. GRANT Statement

sql
GRANT privilege_name ON object_name TO user [WITH GRANT OPTION];

Example:

sql
GRANT SELECT, INSERT ON employees TO 'user'@'localhost';

14. REVOKE Statement

sql
REVOKE privilege_name ON object_name FROM user;

Example:

sql
REVOKE SELECT, INSERT ON employees FROM 'user'@'localhost';

Formatting Guidelines

  1. Consistent Capitalization: Use uppercase for SQL keywords (SELECT, FROM, WHERE) and lowercase for column and table names (table_name, column_name).
  2. Indentation: Use indentation to align SQL statements and enhance readability, especially in complex queries.
  3. Line Breaks: Place each clause (SELECT, FROM, WHERE, JOIN, ORDER BY) on a new line.
  4. Comments: Use comments to explain complex logic or important details within the code. Use -- for single-line comments and /* ... */ for multi-line comments.

By following these guidelines and using the provided formats, you can write MySQL statements that are clear, efficient, and easy to maintain.

MySQL syntax coding guidelines

MySQL syntax coding guidelines help ensure that your SQL code is readable, maintainable, and efficient. Here are some key guidelines to follow: 


1. General Formatting

  • Consistent Capitalization: Use uppercase for SQL keywords (e.g., SELECT, INSERT) and lowercase for column and table names (e.g., table_name, column_name).
  • Indentation: Use indentation to align SQL statements and enhance readability, especially in complex queries.
  • Line Breaks: Place each clause (e.g., SELECT, FROM, WHERE, JOIN, ORDER BY) on a new line.

2. Naming Conventions

  • Tables and Columns: Use descriptive names for tables and columns. Avoid using reserved keywords and keep names concise but meaningful.
  • Prefixes and Suffixes: Use prefixes (e.g., tbl_ for tables) and suffixes (e.g., _id for primary keys) consistently if they add clarity.

3. SELECT Statements

  • Column Selection: List column names explicitly instead of using SELECT *.
  • Aliases: Use meaningful aliases for tables and columns to make the query easier to understand.

4. JOINs

  • Explicit JOINs: Prefer explicit JOIN syntax over implicit joins (comma-separated lists in the FROM clause).
  • Join Conditions: Always use ON clauses for join conditions to clarify the relationship between tables.

5. WHERE Clauses

  • Conditions: Use appropriate operators and functions to filter data efficiently. Place conditions that reduce the result set size early in the clause.
  • Formatting: Align conditions vertically to improve readability when multiple conditions are used.

6. Subqueries

  • Readability: Format subqueries with proper indentation. If a subquery is complex, consider breaking it into a Common Table Expression (CTE).

7. Comments

  • Inline Comments: Use comments to explain complex logic or important details within the code. Use -- for single-line comments and /* ... */ for multi-line comments.
  • Block Comments: At the beginning of scripts or complex sections, provide a summary of the purpose and functionality.

8. Transactions

  • Atomicity: Group related operations within transactions using START TRANSACTION, COMMIT, and ROLLBACK to ensure atomicity.
  • Error Handling: Include error handling to manage exceptions and ensure data integrity.

9. Indexes

  • Index Usage: Use indexes to optimize query performance but avoid over-indexing, which can slow down insert and update operations.
  • Index Naming: Use a consistent naming convention for indexes, such as idx_table_column.

10. Performance

  • Query Optimization: Analyze and optimize queries using EXPLAIN to understand their execution plan.
  • Batch Operations: For bulk inserts or updates, use batch operations to reduce the number of database hits.

Example

-- Select users with their respective orders SELECT u.user_id, u.username, o.order_id, o.order_date FROM users u JOIN orders o ON u.user_id = o.user_id WHERE u.status = 'active' AND o.order_date >= '2024-01-01' ORDER BY o.order_date DESC;

By following these guidelines, you can write SQL code that is clean, efficient, and easy to maintain.