This file contains hidden or 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 stockBuySell = (days) => { | |
const best = days.reduce((bestResult, price, i) => { | |
const buyDays = days.slice(i+1) | |
if (buyDays.length) { | |
const highest = Math.max.apply(null, days.slice(i+1)) | |
const roi = highest - price | |
if (roi > bestResult.roi) { | |
bestResult = {buyDay: i, sellDay: days.indexOf(highest), roi} | |
} | |
} |
This file contains hidden or 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
{ | |
"scripts": { | |
"format": "prettier --write \"**/*.{js,jsx,json,md}\"", | |
"format-watch": "npm run format && onchange \"**/*.{js,jsx,json,md}\" -- prettier --write {{changed}}", | |
}, | |
"devDependencies": { | |
"onchange": "^7.0.2", | |
"prettier": "^2.0.5" | |
} | |
} |
This file contains hidden or 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 { ThemeProvider } from "theme-ui" | |
import theme from "../components/theme" | |
import { UserProvider } from "../components/context/UserContext" | |
function MyApp({ Component, pageProps }) { | |
return ( | |
<ThemeProvider theme={theme}> | |
<UserProvider user={pageProps.user}> | |
<Component {...pageProps} /> | |
</UserProvider> |
This file contains hidden or 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' | |
export default (props) => { | |
const words = props.children.split(' ') | |
return <>{words.map((word, i) => word + (i > words.length-((props.widows || 1)+1) ? '\u00a0' : ' ')).join('')}</> | |
} |
This file contains hidden or 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 PropTypes from 'prop-types' | |
import React from 'react' | |
class ResponsiveWidows extends React.Component { | |
constructor() { | |
super() | |
this.state = {} | |
} | |
componentDidMount() { |
This file contains hidden or 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 loadTemplates() { | |
var toLoad = [], | |
loadAll = $.Deferred(); | |
$.each(arguments, function(i, templateName) { | |
var filepath = '/path/to/templates/' + templateName + '.html', | |
loadTemplate = $.Deferred(); | |
toLoad.push(loadTemplate); |
This file contains hidden or 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
public static void waitForPageLoad(WebDriver drv) { | |
sleep(50); // Make sure new page init has started... | |
try { | |
(new WebDriverWait(drv, 5)) | |
.until(new ExpectedCondition<Boolean>() { | |
public Boolean apply(WebDriver d) { | |
return ((JavascriptExecutor)d).executeScript("return document.readyState").equals("complete"); | |
} | |
}); | |
} catch (TimeoutException ex) { |
This file contains hidden or 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
[alias] | |
recent = "!git for-each-ref --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)' | head -n 10" | |
co = checkout | |
cob = checkout -b | |
coo = !git fetch && git checkout | |
br = branch | |
brd = branch -d | |
brD = branch -D | |
merged = branch --merged | |
st = status |
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>title</title> | |
</head> | |
<body> | |
<p>Simple jQuery Pattern for doing cool data-binding stuff using <code>jQuery.on()</code> and </code>jQuery.trigger()</code></p> | |
<h1>Messages</h1> | |
<div id="output"></div> |
This file contains hidden or 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
/** | |
* imageFill.js | |
* Author & copyright (c) 2013: John Polacek | |
* Dual MIT & GPL license | |
* | |
* This gist is out of date now. I've turned this into a proper Github project at http://johnpolacek.github.io/imagefill.js/ | |
* | |
*/ | |
;(function($) { |