Skip to content

Instantly share code, notes, and snippets.

Archiving all the things!

Nick Sweeting pirate

Block or report user

Report or block pirate

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
# This is a decorator that checks the function parameters as runtime against their type hints.
# @enforce_types
# def example(a: str, b: int):
# return 'Success!'
# if __name__ == '__main__':
# example('abc', 123)
# example(123, 'abc') # this throws a TypeError
NoneType = type(None)
JsonValue = Union[str, int, float, bool, NoneType]
SocketMessage = Dict[str, JsonValue]
socket_routes = {
'/table/<table_id>/': [PresenceManager, TimeSync, PokerTable],
'/tournament/<table_id>/': [PresenceManager, Tournament, PokerTable],
'/speedtest/': [SpeedTest],
"""Run some code after the response is returned to the user in django
Great for analytics or other slow tasks that you don't want to block the response
to the user for.
class HttpResponseWithCallback(HttpResponse):
def __init__(self, *args, **kwargs):
self.callback = kwargs.pop('callback')
super().__init__(*args, **kwargs)
pirate / full-page.js
Last active Jun 19, 2018
Requested behavior for --full-page CLI option for chrome --headless --screenshot.
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('', {waitUntil: 'networkidle2'});
await page.screenshot({path: 'screenshot.png', fullPage: true});
await browser.close();
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
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}) =>
<button onClick={action1}>Do first action</button>
<button onClick={action2}>Do second action</button>
View reduxify.js
import {connect} from 'react-redux'
export const reduxify = (container) =>
View reduxify-testing.js
const mapStateToProps = (state) => ({
// some complex logic that needs to be tested
const Component = reduxify({
mapDispatchToProps: (dispatch) => ({...}),
render: (props) =>
View reduxify-example.js
const SomeComponent = reduxify({
mapStateToProps: (state) => ({...}),
mapDispatchToProps: (dispatch) => ({...}),
render: ({}) =>
You can’t perform that action at this time.