Skip to content

Instantly share code, notes, and snippets.

View heyaphra's full-sized avatar

Aphra Bloomfield heyaphra

View GitHub Profile
@heyaphra
heyaphra / PolarCoordinate.dart
Created May 27, 2023 18:08 — forked from timsneath/PolarCoordinate.dart
Demonstrates a polar coordinate system with Flutter
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/gestures.dart';
const double kTwoPi = 2 * math.pi;
class SectorConstraints extends Constraints {
const SectorConstraints({
@heyaphra
heyaphra / pagination_tests.py
Created March 17, 2023 01:08 — forked from jmoz/pagination_tests.py
A unittest for Python Pagination class.
import unittest
from pagination import Pagination
class PaginationTest(unittest.TestCase):
def test_start(self):
p = Pagination(15, per_page=5, current_page=1)
self.assertEqual(0, p.start)
p.current_page = 2
@heyaphra
heyaphra / pagination_tests.py
Created March 17, 2023 01:08 — forked from jmoz/pagination_tests.py
A unittest for Python Pagination class.
import unittest
from pagination import Pagination
class PaginationTest(unittest.TestCase):
def test_start(self):
p = Pagination(15, per_page=5, current_page=1)
self.assertEqual(0, p.start)
p.current_page = 2
@heyaphra
heyaphra / LICENSE
Created December 15, 2021 04:01 — forked from garethr/LICENSE
A script for customers to use the Snyk API to get a list of projects impacted by the Log4Shell vulnerability
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@heyaphra
heyaphra / Subscriber.js
Last active October 12, 2020 16:31
Addressing React and WebSocket Rendering Bottlenecks - Subscriber
// pubsub/Subscriber.js
import { Component, cloneElement, Children } from "react";
import { publisher } from ".";
class Subscriber extends Component {
state = { data: null };
onMessage = msg => {
this.setState({ data: msg.data });
@heyaphra
heyaphra / subscribe.js
Created October 7, 2020 00:07
Addressing React and WebSocket Rendering Bottlenecks - subscribe
// pubsub/subscribe.js
import React from "react";
import { Subscriber } from "./Subscriber";
export const subscribe = (Comp, topic) => {
return (
<Subscriber topic={topic}>
<Comp />
</Subscriber>
@heyaphra
heyaphra / Publisher.js
Created October 7, 2020 00:06
Addressing React and WebSocket Rendering Bottlenecks - Publisher
// pubsub/publisher.js
import EventEmitter from 'eventemitter3';
const eventEmitter = new EventEmitter();
const publisher = {
subscribe: (event, fn) => eventEmitter.on(event, fn),
unsubscribe: (event, fn) => eventEmitter.off(event, fn),
send: (event, payload) => eventEmitter.emit(event, payload)
@heyaphra
heyaphra / ExampleComponent.js
Last active October 6, 2020 23:29
Addressing React and WebSocket Rendering Bottlenecks - Example Subscribed Component
// components/MyComponent/index.js
import React from "react";
import { subscribe } from "../../pubsub";
export const MyComponent = props => subscribe(({ topic, data }) => {
return <span>{data + " | "} {props.passedDownByProvider}</span>
}, props.topic);
@heyaphra
heyaphra / Provider.js
Last active October 6, 2020 23:07
Addressing React and WebSocket Rendering Bottlenecks - Provider
// context/Provider.js
import React, { Component } from "react";
import io from "socket.io-client";
import { Context } from "./";
import { publisher } from "../pubsub";
const { REACT_APP_SOCKET_PORT: SOCKET_PORT } = process.env;
const SOCKET_HOST = window.location.hostname;