Skip to content

Instantly share code, notes, and snippets.

View officer-rosmarino's full-sized avatar
🎯
Focusing

Marco Galassi officer-rosmarino

🎯
Focusing
  • Italy
View GitHub Profile
@officer-rosmarino
officer-rosmarino / generate_pdf_server2client.js
Last active April 19, 2018 14:45
Generate a PDF on the server and send it to the client to be downloaded
'use script'
var pdfmake = require('pdfmake');
const express = require('express')
const app = express()
app.get('/generate-pdf', (req, res) => {
const doc = new pdfmake({
Roboto: { normal: new Buffer(require('pdfmake/build/vfs_fonts.js').pdfMake.vfs['Roboto-Regular.ttf'], 'base64') }
}).createPdfKitDocument({ content: 'test' })
@officer-rosmarino
officer-rosmarino / generate_pdf.js
Created April 19, 2018 14:28
Generate a PDF using pdfmake on the server with Node.js (no browser)
'use script'
var pdfmake = require('pdfmake');
var fs = require('fs');
const doc = new pdfmake({
Roboto: { normal: new Buffer(require('pdfmake/build/vfs_fonts.js').pdfMake.vfs['Roboto-Regular.ttf'], 'base64') }
}).createPdfKitDocument({ content: 'test' })
doc.pipe(fs.createWriteStream('myFile.pdf'))
doc.end()
@officer-rosmarino
officer-rosmarino / discover-schema.js
Last active September 12, 2018 13:33
Loopback: Discover a schema in a db.
/*
* Discovers a table schema and outputs it into a file: run this script via:
* $ node discover-schema.js
*/
var path = require('path');
var fs = require('fs');
var app = require('loopback');
var output_directory = path.resolve(__dirname, '..', '..', 'common', 'models');
@officer-rosmarino
officer-rosmarino / node-pg-pool-transaction-handling.js
Last active March 12, 2019 01:36
How to properly handle a transaction with node-pg-pool
'use strict'
const { Pool } = require('pg')
// create a pool instance.
// Refer to https://node-postgres.com/api/pool for more info on how to config pool
var pool = new Pool({
"host": "YOUR_HOST",
"port": YOURPORT,
"database": "DBNAME",
"user": "USERNAME",