Skip to content

Instantly share code, notes, and snippets.

{
## deno extension settings
"deno.enable": true,
"deno.unstable": true,
## editor settings
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.defaultFormatter": "denoland.vscode-deno"
}
import { readFile } from 'node:fs';
const readFileCallback = (err: Error | null, data: string | Buffer) => {
if (err) {
console.log(err);
return;
}
// process data ...
console.log(data.length);
type PromiseFunc = (...args: any[]) => Promise<any>;
type TryCatch<Func extends PromiseFunc> = (
...args: [...Parameters<Func>]
) => Promise<[Error | null, Awaited<ReturnType<Func>> | null]>;
const trycatch =
<Func extends PromiseFunc>(f: Func): TryCatch<Func> => async (...args) => {
try {
const v = await f(...args);
const readFile = async (file: string): Promise<string | Error> => {
try {
return await Deno.readTextFile(file);
} catch (err) {
return err;
}
};
const main = async () => {
const file = Deno.env.get("FILE");
const readFile = async (file: string): Promise<[Error | null, string]> => {
try {
const text = await Deno.readTextFile(file);
return [null, text];
} catch (err) {
return [err, ""];
}
};
const main = async () => {
const readFile = async (file: string): Promise<string> =>
await Deno.readTextFile(file);
const main = async () => {
const file = Deno.env.get("FILE");
if (!file) {
console.log("file name required.");
return;
}
#!/bin/bash
################################################################################
##
## The following creates AWS resources for the project
##
################################################################################
. .env # populate parameters from .env file
PROJECT=my-awesome-project
TABLE=my-awesome-table
API_RESOURCE=my-awesome-resource
STAGE=some-stage
FRONTEND_BUCKET_NAME=my-frontend-assets-bucket
DISTRIBUTION_ENABLED=false
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
ProjectName:
Description: Project name used to identify created AWS resources
Type: String
Resources:
WebACL:
Type: AWS::WAFv2::WebACL
Distribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Comment: !Sub ${ProjectName} project distribution
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
- OPTIONS