This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mport { defineBackend } from "@aws-amplify/backend"; | |
import { EventSourceMapping, StartingPosition } from "aws-cdk-lib/aws-lambda"; | |
import { DynamoEventSource } from "aws-cdk-lib/aws-lambda-event-sources"; | |
import { auth } from "./auth/resource"; | |
import { data } from "./data/resource"; | |
import { myDynamoDBFunction } from "./functions/dynamoDB-function/resource"; | |
import { Effect, Policy, PolicyStatement } from "aws-cdk-lib/aws-iam"; | |
import { Stack } from "aws-cdk-lib"; | |
const backend = defineBackend({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ----------------------------------------- * | |
Lazy List Implementation | |
* ----------------------------------------- */ | |
// Haskell-like infinite List, implemented with es6 generators | |
// Lazyness lets you do crazy stuff like | |
List.range(0, Infinity) | |
.drop(1000) | |
.map(n => -n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const waterVolume = a => { | |
const max = Math.max(...a) | |
let sum = 0 | |
for (let i = max; i >0; i--) { | |
let started = false, tmpSum = 0 | |
for (let j = 0; j < a.length; j++) { | |
if (a[j] >= i) { | |
if (!started) { | |
started = true | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const encode = msg => { | |
const abc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
const morsecode =[ | |
'.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', | |
'..', '.---', '-.-', '.-..', '--', '-.', '---', '.--.', | |
'--.-', '.-.', '...', '-', '..-', '...-', '.--', '-..-', | |
'-.--', '--..' | |
] | |
const words = msg.toUpperCase().split(' ') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function Composition | |
const identity = x => x | |
const compose = (f, g) => x => f(g(x)) | |
const composer = fnArr => fnArr.reduce(compose, identity) | |
// Map implemented in terms of reduce | |
const mmap = fn => reducer => (acc, val) => reducer(acc, fn(val)) | |
// Filter implemented in terms of reduce | |
const mfilter = fn => reducer => (acc, val) => fn(val) ? reducer(acc, val) : acc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const findAnagramIndexes = (w1, w2) => { | |
let result = []; | |
let control = []; | |
for(let i = 0; i < w1.length; i++){ | |
if(control[i] === undefined) control[i] = w2.split(''); | |
for(let j = 0; j < control.length; j++) { | |
if(control[j] === null) continue; | |
if(Array.isArray(control[j]) && control[j].length === 0) continue; | |
let indexOfLetter = control[j].indexOf(w1[i]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const neighbours = (pos, transf) => { | |
const x = pos[0] | |
const y = pos[1] | |
return [[x-1, y-1],[x, y-1],[x+1, y-1],[x-1, y],[x,y],[x+1, y],[x-1, y+1],[x, y+1],[x+1, y+1]].map(transf) | |
} | |
const maxSumRect = (rows, cols, nums) => { | |
const revVirtMatrix = pos => [parseInt(pos / cols), pos % cols] | |
const virtualMatrix = pos => (pos[0] * cols + pos[1]) | |
return nums.reduce((max, val, idx) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app deps | |
sudo yum install git | |
# erlang deps | |
sudo yum groupinstall "Development Tools" | |
sudo yum install ncurses-devel | |
# erlang | |
wget http://www.erlang.org/download/otp_src_18.1.tar.gz | |
tar -zxvf otp_src_18.1.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from http://forwardjs.com/university/a-million-ways-to-fold-in-js | |
'use strict' | |
const first = (xs) => xs[0] | |
const rest = (xs) => xs.slice(1) | |
const concat = (xs1, xs2) => xs1.concat(xs2) | |
// recursion | |
const sum = (xs) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List | |
data Peg = Red | Green | Blue | Yellow | Orange | Purple deriving (Show, Eq, Ord) | |
type Code = [Peg] | |
data Move = Move Code Int Int deriving (Show, Eq) | |
colors :: [Peg] | |
colors = [Red, Green, Blue, Yellow, Orange, Purple] | |
exactMatches :: (Eq a) => [a] -> [a] -> Int |
NewerOlder