Skip to content

Instantly share code, notes, and snippets.

View danibrear's full-sized avatar
🤓
Nerdin' out

Danielle "Dani" Brear danibrear

🤓
Nerdin' out
View GitHub Profile
@danibrear
danibrear / Chunk Single Line
Created December 11, 2018 23:45
Wanted to see if I could do it.
const chunk = (arr, size) => arr.reduce((a, n) => a[a.length-1].length < size ? [...a.slice(0,-1), [...a[a.length-1], n]] : [...a, [n]], [[]]);
const a = [1,2,3,4,5,6,7,8,9]
console.log(chunk(a, 2)); // -> [[1, 2], [3, 4], [5, 6], [7, 8], [9]]
console.log(chunk(a, 3)); // -> [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
console.log(chunk(a, 4)); // -> [[1, 2, 3, 4], [5, 6, 7, 8], [9]]
@danibrear
danibrear / Example.ts
Last active December 3, 2020 13:53
Amplify Auth Field-Level Authorization Example
// From https://docs.amplify.aws/cli/graphql-transformer/auth#field-level-authorization
// The code where this exception is thrown is: https://github.com/aws-amplify/amplify-js/blob/d9aa32837f15f408daba0a0104bb27042b9331da/packages/api-graphql/src/GraphQLAPI.ts#L314
type User @model {
id: ID!
username: String
ssn: String @auth(rules: [{ allow: owner, ownerField: "username" }])
}
@danibrear
danibrear / example-migration.js
Last active April 7, 2021 21:49
This is an example migration for adding a status attribute to a hypothetical Todo table.
/* eslint-disable @typescript-eslint/no-var-requires */
/**
* How to run:
* - export AWS_PROFILE
* - export AWS_REGION=us-east-1
*/
const DynamoDB = require("aws-sdk/clients/dynamodb");
const dynamodb = new DynamoDB();
const DocumentClient = new DynamoDB.DocumentClient();