Skip to content

Instantly share code, notes, and snippets.

View ChristianRich's full-sized avatar

Christian Rich ChristianRich

View GitHub Profile
@ChristianRich
ChristianRich / ES5-ES6-ES2017-ES2019 omit & pick
Created December 30, 2022 14:17 — forked from bisubus/ES5-ES6-ES2017-ES2019 omit & pick
ES5/ES6/ES2017/ES2019 omit & pick
@ChristianRich
ChristianRich / .ts
Created October 23, 2022 23:21
Node.js read/write file promise wrapper
import fs from 'fs';
import path from 'path';
export const write = (
data: string,
filename: string,
dir: string = process.cwd(),
): Promise<string> =>
new Promise((resolve, reject) => {
const dest = path.resolve(`${dir}/${filename}`);
@ChristianRich
ChristianRich / js
Created July 21, 2022 15:10
Array methods at a glance
// The filter() method creates a new array filled with elements that pass a test provided by a function
[1, 2, 3, 4, 5].filter((n) => n > 3); // [4,5]
// The find() method returns the value of the first element that passes the test
[1, 2, 3, 4, 5].find((n) => n > 3); // 4
//. The every() method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.
[1, 30, 39, 29, 10, 34].every((n) => n < 40); // true
const myObj = { firstName: 'John', lastName: 'Doe' };
for (const [key, value] of Object.entries(myObj)) {
console.log(`${key} ${value}`); // John Doe
}
@ChristianRich
ChristianRich / workflow.yml
Created January 31, 2020 12:36
Github action: Build and deploy static website to AWS S3
name: Build and deploy
on:
push:
branches:
- master
jobs:
build:
name: Build
runs-on: ubuntu-18.04
strategy:
@ChristianRich
ChristianRich / create-table.sh
Last active December 20, 2018 22:50
AWS create DynamoDB tables on localhost
cd ~/dynamodb_local_latest
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb
aws dynamodb create-table \
--endpoint-url http://localhost:8000 \
--table-name pricing-api-tst-menu-dyn \
--attribute-definitions \
AttributeName=id,AttributeType=S \
AttributeName=storeId,AttributeType=S \
--key-schema \
@ChristianRich
ChristianRich / gist:6cfa2fdc6daaa921073c450be02e6925
Created October 3, 2018 04:30
Node.js output complex object to console without stringifying
import util from 'util';
console.log(util.inspect(myObject, false, null, true /* enable colors */))
@ChristianRich
ChristianRich / error-code.test.js
Last active September 7, 2018 04:24
Chai as promised - assess type Error and status code
import { describe, it } from 'mocha';
import chai, { expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);
describe('Example', () => {
it('should return 404', () =>
expect(foo()).to.eventually.be.rejected
.and.be.an.instanceOf(Error)
@ChristianRich
ChristianRich / createTable.sh
Last active August 30, 2018 05:58
Query DynamoDB for items within a given date time range using a global secondary index and a range key
#!/bin/bash
# You may want to remove the `--endpoint-url http://localhost:8000` line for actual AWS deployment
aws dynamodb create-table \
--endpoint-url http://localhost:8000 \
--table-name exampleTableName \
--attribute-definitions \
AttributeName=id,AttributeType=S \
AttributeName=status,AttributeType=S \
AttributeName=createdDateTime,AttributeType=S \
--key-schema \
@ChristianRich
ChristianRich / index.js
Last active July 18, 2017 05:04
Intercept all HTTPx traffic for logging and debugging purposes. This snippet should be a part of your server startup script.
import * as httpInterceptor from 'global-request-logger';
const debug = require('debug')('my:app');
if(process.env.DEBUG){
httpInterceptor.initialize();
httpInterceptor.on('success', (req, res) => {
const protocol = (req.port === 443 ? 'https://' : 'http://');