Skip to content

Instantly share code, notes, and snippets.

View reedsa's full-sized avatar

Stuart Reed reedsa

View GitHub Profile
@reedsa
reedsa / .gitignore
Last active September 22, 2023 21:40
ethereum chain id list to python enums
networks.py

React Hooks

Hooks in React enable usage of React state and lifecycle features without using a class. Released in React v16.8.0, Hooks resolve issues like sharing stateful logic across components.

Rather than writing higher-order components, a customized hook can be implemented outside of a component in order to reuse that logic and test it in isolation. This also means the components themselves become simpler to manage by breaking it into smaller pieces of state related functions.

Functional components have many benefits over using classes. The top-down approach in functional components means it's easier to read and comprehend. In a class, binding this can be difficult to keep track of and introduces potential for bugs. In addition, without classes there is no need to wire up the component lifecycle functions and write potentially complicated logic to identify changes in props or state.

Building a State Hook with useState

Cypress

Cypress is a testing framework. It takes a drastically different approach than Selenium based test frameworks like WebDriver. Unlike Selenium, which executes remote commands through network requests, Cypress runs a Node.js server process that runs in the same event loop as the application. This means Cypress can access everything within the application code. The DOM, window object, classes, functions, etc. are all available through the test code.

Cypress runs synchronously with the application and creates a highly reliable and natural way to write and run tests. With Cypress there's no longer a need for statements to wait for certain elements, it's all built in to the framework. You can use debugger statements within your tests or code and jump into the DevTools as the test runs.

Writing tests with Cypress

Testing practices generally follow the arrange/act/assert pattern. In Cypress, it is preferable to "arrange" by setting the desired state of the application with

Reselect

Reselect is a library from the React Community that helps obtain derived data from the Redux store. Reselect helps create memoized, composable selector functions.

In addition to the performance gains for large state trees or calculations, selectors can help reduce duplication across the Redux store and clean up code for deeply nested state properties.

React and Redux

In React, rendering a large number of components can be an expensive operation. With Redux, the input data is recalculated each time a component renders. This is fine in a basic application but performance can degrade as components become more complex.

@reedsa
reedsa / heroku-ci.md
Last active September 15, 2017 16:01

Introduction to Heroku Pipelines

A pipeline in Heroku creates a continuous delivery workflow for a single application codebase. It creates a grouping of application instances for different environments that represent various stages of a continuous delivery workflow.

The explicit stages defined in a pipeline are:

  • Review
  • Development
  • Staging
  • Production
@reedsa
reedsa / github-intro.md
Last active March 27, 2017 17:35
Introduction to GitHub

Introduction to GitHub

What is GitHub?

GitHub is a platform that hosts code for a Version Control System (VCS) called Git. It helps manage many features of Git that involve repositories, branches, commits, and Pull Requests. Encourages collaboration on projects with features like bookmarking repositories (using stars) or get notifications about updates (watch). Makes it easy to Fork a repository to provide a way for external parties to contribute to a codebase. Also provides labels for issues and Pull Requests to keep things organized.

@reedsa
reedsa / docker-intro.md
Last active January 13, 2017 20:43
Introduction to Docker

Introduction to Docker

What is Docker?

Simplifies how applications are run by isolating the processes in separate containers. Typically run one application process per container. Each container includes all application dependencies and libraries. Different flavors: Docker for Mac, Docker for Windows, Docker on Linux, Docker Toolbox

What is an image?

There are common public images available from a registry like DockerHub. These include things like nginx, MongoDB, and Redis. Images are made up of layers and all images have a base layer (Which might be the OS). Images enable a simple method of distribution and allow users to save each layer so they won’t need to be downloaded the next time the container is run. An image can be tagged with versions.

@reedsa
reedsa / new_task.py
Last active September 22, 2023 11:07
RabbitMQ Retry using Dead Letter Exchange in Python/Pika
#!/usr/bin/env python
# http://www.rabbitmq.com/tutorials/tutorial-two-python.html
import pika
import sys
connection = pika.BlockingConnection(pika.ConnectionParameters(
host='localhost'))
channel = connection.channel()
message = ' '.join(sys.argv[1:]) or "Hello World!"