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 React from "react"; | |
const Hello = ({ name }: { name: string }) => <span>Hello {name}</span>; | |
Hello.defaultProps = { name: "World" } | |
export default Hello; |
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 yaml | |
import sys | |
import os | |
from google.cloud import translate_v2 as translate | |
def translate_text(text, target_language): | |
if isinstance(text, str): | |
result = translate_client.translate(text, target_language=target_language) | |
return result['translatedText'] | |
elif isinstance(text, list): |
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 rotate = v => { | |
let n = v.length-1; | |
for (let y=0; y < Math.floor(v.length/2); y++) { | |
for (let x=0+y; x < v.length-y-1; x++) { | |
[v[y][x], v[n-x][y], v[n-y][n-x], v[x][n-y]] = [v[n-x][y], v[n-y][n-x], v[x][n-y], v[y][x]] | |
} | |
} | |
return v; | |
} |
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
// Our HashMap can have up to 5077 entries | |
const MAX_INDEX = 5077; | |
// helpers | |
let isMultipleOf = k => n => n%k === 0 | |
let isMultipleOfFour = isMultipleOf(4); | |
// hash function for strings using 4 char word folding | |
let hash = s => { | |
let total = 0; |
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
// Given an array of integers representing the number of consecutive 1s immediately stacked vertically at this index | |
// calculate the largest area by grabbing the largest of all rectangular areas calculated at each index. | |
let largestRowArea = row => { | |
let largestArea = 0; | |
row.forEach((value, i) => { | |
let area = value; | |
if (value != 0) { | |
for(let j=i-1; j>=0; j--) { | |
if (row[j] < value) break; | |
area += value; |
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 canReach([sx,sy], [dx,dy]) { | |
return Math.sqrt((sx-dx)**2 + Math.abs(sy-dy)**2) < 5 | |
} | |
function canToggle({ switch: current, hub, light: end }) { | |
if (canReach(current, end)) | |
return true; | |
if (hub.length == 0) return false; | |
for(let [i,node] of hub.entries()) { | |
if (canReach(current, node)) { |