Skip to content

Instantly share code, notes, and snippets.

View BenBrostoff's full-sized avatar
💭
@klaviyo / DFS + stocks, options trading

Ben Brostoff BenBrostoff

💭
@klaviyo / DFS + stocks, options trading
View GitHub Profile
@BenBrostoff
BenBrostoff / bash-iterative.sh
Last active September 20, 2020 19:53
Go through all the Python files
for i in $(find . -name '*.py'); do python-modernize -wn -f default "$i"; done
docker volume prune
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rm $(docker ps -q -f 'status=exited')
docker rmi $(docker images -q -f "dangling=true")
@BenBrostoff
BenBrostoff / test-async-act.js
Last active August 11, 2019 19:23
Test async act
it('should render with the correct text with sync act', () => {
act(() => {
ReactDOM.render(<AsyncApp/>, el);
});
expect(el.innerHTML).toContain('unloaded val');
});
it('should render with the correct text with async act', async () => {
await act(async () => {
ReactDOM.render(<AsyncApp/>, el);
@BenBrostoff
BenBrostoff / simply-async-act.js
Created August 11, 2019 12:28
Simply async act
export const AsyncApp = () => {
const [data, setData] = useState('unloaded value');
const [clickCount, setCount] = useState(0);
const simulatedFetch = async () => {
const fetchedValue = await Promise.resolve('fetched value');
await new Promise(res => {
setData(fetchedValue);
res();
});
};
@BenBrostoff
BenBrostoff / test-sync-act.js
Last active August 11, 2019 19:23
Pass / fail sync act
it('should render with the correct text without act', () => {
ReactDOM.render(<App/>, el);
expect(el.innerHTML).toContain('unloaded val');
});
it('should render with the correct text with act', () => {
act(() => {
ReactDOM.render(<App/>, el);
});
expect(el.innerHTML).toContain('sync val');
@BenBrostoff
BenBrostoff / simple-sync-act.js
Last active August 11, 2019 12:10
Simply sync act
export const App = () => {
const [data, setData] = useState('unloaded value');
useEffect(() => {
setData('sync val');
}, []);
return (
<div>
<h2>{data}</h2>
# Hacky MMR to TCX bulk -> get these from MMR CSV, run in terminal while loged in
listOfWork="
https://www.mapmyrun.com/workout/export/<id1>/tcx
https://www.mapmyrun.com/workout/export/<id2>/tcx
https://www.mapmyrun.com/workout/export/<id3>/tcx
"
for workout in "$listOfWork"
do
echo "$workout"
@BenBrostoff
BenBrostoff / promise.js
Created January 10, 2019 22:34
Normal promise
const getUserProfile = id => lookupProfile(id);
@BenBrostoff
BenBrostoff / promise.ts
Created January 10, 2019 22:33
TS promise
const getUserProfile = (id: number): Promise<UserProfile> => lookupProfile(id);
@BenBrostoff
BenBrostoff / apollo-example.ts
Last active January 10, 2019 20:13
Apollo TypeScript example (GitHub API) - taken from Apollo docs
// The Result type we expect back.
// See https://developer.github.com/v3/repos/#get
interface Result {
repo: {
id: number;
name: string;
description: string;
html_url: string;
};
}