View full-page.js
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({width: 1440, height: 1200});
await page.goto('https://example.com', {waitUntil: 'networkidle2'});
await page.screenshot({path: 'screenshot.png', fullPage: true});
await browser.close();
})();
View mypy_check_order.py
"""
Minimum amount of code to reproduce a strange mypy edge case where the order
of checking isinstance seems to matter to the type inference.
To test it uncomment one of the __add__ examples and run:
pip3 install mypy
mypy mypy_check_order.py
"""
from decimal import Decimal
View action-creators.js
import {reduxify} from 'reduxify'
import {action1, action2} from 'myActions'
const MyComponent = reduxify({
mapDispatchToProps: ({action1, action2}),
render: ({action1, action2}) =>
<div>
<button onClick={action1}>Do first action</button>
<button onClick={action2}>Do second action</button>
</div>
View reduxify.js
import {connect} from 'react-redux'
export const reduxify = (container) =>
connect(
container.mapStateToProps,
container.mapDispatchToProps,
)(container.render)
View reduxify-testing.js
const mapStateToProps = (state) => ({
// some complex logic that needs to be tested
...
})
const Component = reduxify({
mapStateToProps,
mapDispatchToProps: (dispatch) => ({...}),
render: (props) =>
<div>...</div>
View reduxify-example.js
const SomeComponent = reduxify({
mapStateToProps: (state) => ({...}),
mapDispatchToProps: (dispatch) => ({...}),
render: ({}) =>
<div></div>
})
View react-redux-normal-example.js
const mapStateToProps = (state}) => ({
...
})
const mapDispatchToProps = (dispatch) => ({
...
})
const Component = (props) =>
<div></div>
View redux-connect-example.js
const ToggleableVideo = connect({
mapStateToProps: ({video}) => ({stream_id: video.my_stream_id}),
mapDispatchToProps: (dispatch) => ({
onStartStreaming() {
dispatch({type: 'START_STREAMING'})
},
}),
render: ({stream_id}) =>
stream_id ?
<VideoStream stream_id={stream_id}/>
View udp_chat.py
#!/usr/bin/env python3
"""UDP Broadcast Sender"""
import socket
import sys
PORT = 33333
def udp_send_socket():
View quit_while_youre_ahead.py
#!/usr/bin/env python3
# Gambling Statistics Problem:
# If you play roulette every day and quit whenever you're ahead by x amount,
# do you make money in the long run?
# Answer:
# No.
import random
STARTING_BALANCE = 100000