Skip to content

Instantly share code, notes, and snippets.

View railsstudent's full-sized avatar
🏠
Researching third-party library

Connie Leung railsstudent

🏠
Researching third-party library
View GitHub Profile
@railsstudent
railsstudent / gist:390bafc8d404678f9934b5719e5cbe75
Last active June 16, 2020 03:59
Use FileSaver to open File object
openFile(name: string) {
if (this.formData[name]) {
const file = this.formData[name] as File
if (file) {
const { name: filename } = file
saveAs(file, filename)
}
}
}
@railsstudent
railsstudent / gist:b599c43a71331d6f037b022a63a9f704
Created June 16, 2020 03:56
Use FileSaver to open File object
openFile(name: string) {
if (this.formData[name]) {
const file = this.formData[name] as File
const { name: filename } = file
saveAs(file, filename);
}
}
@railsstudent
railsstudent / download-open-file.js
Last active June 16, 2020 03:54
use file-saver to open file
import { saveAs } from 'file-saver'
interface FileDownloadResponse<T> {
body: T | null;
contentDisposition: string;
contentType: string;
}
private getFileNameFromContentDisposition(res: FileDownloadResponse<Blob>) {
const { contentDisposition } = res;
@railsstudent
railsstudent / openFile.js
Created June 16, 2020 03:45
use file-saver to open file
// private getFileNameFromContentDisposition(res: FileDownloadResponse<Blob>) {
// const { contentDisposition } = res;
// const matches = /filename=([^;]+)/gi.exec(contentDisposition);
// const tempFilename = ((matches && matches[1]) || 'untitled').trim();
// const filename = tempFilename.replace(/["]/g, '');
// return filename;
// }
// static openFile(response: FileDownloadResponse<Blob>) {
// if (response && response.body) {
@railsstudent
railsstudent / openFile.js
Created June 16, 2020 03:45
use file-saver to open file
// private getFileNameFromContentDisposition(res: FileDownloadResponse<Blob>) {
// const { contentDisposition } = res;
// const matches = /filename=([^;]+)/gi.exec(contentDisposition);
// const tempFilename = ((matches && matches[1]) || 'untitled').trim();
// const filename = tempFilename.replace(/["]/g, '');
// return filename;
// }
// static openFile(response: FileDownloadResponse<Blob>) {
// if (response && response.body) {
@railsstudent
railsstudent / create-entities-index.ts
Last active April 3, 2020 03:48
Generate file to export TypeORM entities in an ts file
// https://medium.com/@p3rf/solving-issue-with-entities-loading-for-a-nx-dev-monorepo-setup-with-nest-js-and-typeorm-282d4491f0bc
// npm install --save-dev fast-glob
// ...
// "scripts": {
// ...
// "create-entities-index": "ts-node --pretty --project=tools/tsconfig.tools.json tools/create-entities-index.ts",
// ...
// }
@railsstudent
railsstudent / sheetjs_write_xlsx.ts
Last active December 30, 2019 06:29
use sheetjs to write and save a xlsx file
// https://github.com/SheetJS/sheetjs/tree/6551dd0e051acac5031ffb728a16932bbf34c80a
// npm install xlsx
import * as XLSX from 'xlsx';
const { writeFile, utils } = XLSX;
console.log('Create workbook');
const wb = utils.book_new();
@railsstudent
railsstudent / docker-compose.dev.yml
Created May 26, 2019 11:17
docker file to setup postgresql and mailhog
version: '3'
services:
postgres:
image: postgres:alpine
ports: ['5432:5432']
environment:
POSTGRES_PASSWORD: postgres
mailhog:
image: mailhog/mailhog
@railsstudent
railsstudent / unsaved-changes-guard.ts
Created March 18, 2019 03:43 — forked from Splaktar/unsaved-changes-guard.ts
Guard against navigating away when there are unsaved changes
import {CanDeactivate, Router} from '@angular/router';
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {Observer} from 'rxjs/Observer';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
export interface CanComponentDeactivate {
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
}
crypto = require('crypto');
function buildMerkleRoot(targetHash, proof) {
const bigEndianMerkleRoot = proof.reduce((merkleHash, p) => {
if ('append' in p) {
return Buffer.concat([merkleHash, Buffer.from(p.append, 'hex')]);
} else if ('prepend' in p) {
return Buffer.concat([Buffer.from(p.prepend, 'hex'), merkleHash]);
} else if ('sha256' in p) {
return crypto.createHash('sha256').update(merkleHash).digest();