Sunday, December 24, 2023

Rearrange pages from front and back pdf files which are scanned from two-sided papers

 


  1. Merge 0001.pdf and 0002.pdf into one.
  2. Make a list of indexes. Interleave two indexes. First one is 0 to 19. Second one is reversed as 39 to 20.
  3. Rearrange the merged.pdf as the ordered_indexes list.


I scanned both-sided papers into two pdf files, front pages and reversed back pages. Merge and rearrange pages from two pdf files into one pdf file.


script methods

  1. https://unix.stackexchange.com/questions/53295/how-to-merge-2-pdf-files-with-interleaving-pages-order

tools

  1. https://pdfsam.org/pdfsam-basic/


RearrangePdf-PdfFilePath_Output-PdfFilePath_OrdersList_Input.py


In [4]: from PyPDF2 import PdfFileMerger



In [6]: merger = PdfFileMerger()


In [11]: pdfs = ['/Users/.../Downloads/0001.pdf', '/Users/.../Downloads/0002.pdf']


In [12]: for f in pdfs: merger.append(f)


In [13]: merger.write("a.pdf")


In [14]: merger.close()


In [15]: from PyPDF2 import PdfFileReader, PdfFileWriter


In [16]: reader = PdfFileReader('a.pdf')


In [35]: f_page_idxes = range(20) ; b_page_idxes = reversed(range(20, 40)) ; fb_page_idxes = zip(f_page_idxes, b_page_idxes)


In [41]: ordered_idxes = list(itertools.chain(*fb_page_idxes))


In [42]: writer = PdfFileWriter()


In [43]: for p in ordered_idxes: writer.addPage(reader.getPage(p))


In [45]: with open("arranged_pdf.pdf", "wb") as f: writer.write(f)


Thursday, November 16, 2023

Custom GPT chatbots for websites

  Open AI announced GPTs. GPT store, GPT4 turbo at Open AI dev day. 

We can build custom GPT chatbot for websites from https://docenty.ai/ .

Sunday, June 11, 2023

Vercel database Prisma setup

 


PrismaClientKnownRequestError:
Invalid `prisma.workspace.findMany()` invocation:
The table `public.workspaces` does not exist in the current database.
at pn.handleRequestError (/vercel/path0/node_modules/@prisma/client/runtime/library.js:176:6477)
at pn.handleAndLogRequestError


npx prisma migrate dev

% npx prisma migrate dev

Environment variables loaded from .env

Prisma schema loaded from prisma/schema.prisma

Datasource "db": PostgreSQL database "verceldb", schema "public" at "ep-delicate-dust-021378.us-east-1.postgres.vercel-storage.com:5432"


Error: P3014


% npx prisma migrate resolve --applied 20220223015914_init_database

Environment variables loaded from .env

Prisma schema loaded from prisma/schema.prisma

Datasource "db": PostgreSQL database "verceldb", schema "public" at "ep-delicate-dust-021378.us-east-1.postgres.vercel-storage.com:5432"

Migration 20220223015914_init_database marked as applied.

% npx prisma migrate resolve --applied 20220508151141_add_domain_verification_columns

Environment variables loaded from .env

Prisma schema loaded from prisma/schema.prisma

Datasource "db": PostgreSQL database "verceldb", schema "public" at "ep-delicate-dust-021378.us-east-1.postgres.vercel-storage.com:5432"

Migration 20220508151141_add_domain_verification_columns marked as applied.



Prisma Migrate could not create the shadow database. Please make sure the database user has permission to create databases. Read more about the shadow database (and workarounds) at https://pris.ly/d/migrate-shadow


Original error:

db error: ERROR: permission denied to create database

   0: schema_core::state::DevDiagnostic

             at schema-engine/core/src/state.rs:266



Put env vars to vercel except VERCEL_ prefixed env vars

The value is not a valid System Environment name


Sunday, April 30, 2023

Using async in inline Editor of GCP Dialogflow. But, timeout too short.

 


Using async in inline Editor of GCP Dialogflow 

/* experimental: [asyncawait] */

https://stackoverflow.com/questions/42637630/does-jshint-support-async-await/48772304#48772304


to know queryText from the user

https://stackoverflow.com/questions/60408929/how-do-you-read-query-the-response-body-in-api-v2-of-dialogflow-fulfillment


function handleRequest(request, response) { const queryText = request.body.queryResult.queryText; // use the queryText variable to process the user's input }


sample code (without async)

https://github.com/priyankavergadia/AppointmentScheduler-GoogleCalendar/blob/master/index.js


Dialogflow CX timeout only 30 sec

Dialogflow ES timeout only 15 sec

https://groups.google.com/g/dialogflow-cx-edition-users/c/jajSEPqhYZE


Following code didn't work.

  async function answerQuestion(agent) {

    const response = await axios.post(

...    {

      message: JSON.stringify(request.body.queryResult.queryText)

    },

    {

      headers: { 'Content-Type': 'application/json' },

      timeout: 2 * 60 * 1000

    }

    );

    agent.setContext({ name: "Question", result: response });

    agent.add(`${response.data.data.answer} \n\n ${response.data.data.sources}`);

  }