Skip to content

Instantly share code, notes, and snippets.

@ppulwey
ppulwey / create_vcards_from_csv.js
Created January 19, 2023 14:16
Create multiple vCards with Name, Address, Phone and Email from a CSV file
const fs = require('fs');
const csvFile = fs.readFileSync('contacts.csv', 'utf8');
const csvData = csvFile.split('\n').map(row => row.split(';'));
const vcardData = [];
for (let i = 1; i < csvData.length; i++) {
vcardData.push('BEGIN:VCARD');
vcardData.push('VERSION:4.0');
import * as fs from 'node:fs';
import * as https from 'node:https';
const download = async (url: string, targetPath: string): Promise<void> => {
return new Promise<void>((resolve, reject) => {
if (!url.startsWith('https')) {
const err = new Error('URL must start with https');
reject(err);
}
type MyCookies = {
cookieOne: string;
cookieTwo: string;
};
const myMiddleware = () => {
return (request: Request, response: Response, next: NextFunction) => {
getCookies<MyCookies>(request)
next();
};
const myMiddleware = () => {
return (request: Request, response: Response, next: NextFunction) => {
const cookie1Value = getCookies<MyCookies>(request)?.cookieOne;
const cookie2Value = getCookies<MyCookies>(request)?.cookieTwo;
// OR
const cookies = getCookies<MyCookies>(request);
if (cookies === null) {
next(); // or whatever maybe return 401
return;
import { Request } from 'express';
const getCookies = <T extends Record<string, string>>(req: Request) => {
const cookieString = req.headers.cookie;
if (cookieString === undefined) {
return null;
}
const parsedCookies: Record<string, string> = {};
axios.post('http://localhost:3030', payload, { withCredentials: true });
fetch('http://localhost:3030', {
method: 'post',
credentials: 'include',
body: JSON.stringify(payload),
});
app.use(cors({ credentials: true, origin: 'http://localhost:3000' }));
router.post(
'/',
(req: Request, res: Response, next: NextFunction) => {
res
.cookie('cookieOne', 'value1')
.cookie('cookieTwo', 'value2')
.json({ data:'hello!' });
}
);
@ppulwey
ppulwey / Electron_React_Local_DB.md
Last active January 17, 2022 13:13
How to get an React Electron app with local DB (NEDB)

How to get an React Electron app with local DB (NEDB)

  • Create app with yarn create electron-app my-new-app --template=typescript-webpack
  • Install node packaged
    • ajv
    • nedb-promises
    • react
    • react-dom

src > Database > Schemas > SchemaName.ts