Skip to content

Instantly share code, notes, and snippets.

View anthony2025's full-sized avatar
🛵

Anthony Ascencio anthony2025

🛵
  • Alexandria, VA
View GitHub Profile
[error] cats.effect.IOFiber@494388963 RUNNING
[error] ├ flatMap @ TestApp$.$anonfun$loop$2(TestApp.scala:27)
[error] ├ >> @ TestApp$.loop$lzycompute(TestApp.scala:27)
[error] ├ map @ TestApp$.loop$lzycompute(TestApp.scala:26)
[error] ├ flatMap @ TestApp$.$anonfun$loop$2(TestApp.scala:27)
[error] ├ flatMap @ TestApp$.$anonfun$loop$2(TestApp.scala:27)
[error] ├ >> @ TestApp$.loop$lzycompute(TestApp.scala:27)
[error] ├ >> @ TestApp$.loop$lzycompute(TestApp.scala:27)
[error] ├ map @ TestApp$.loop$lzycompute(TestApp.scala:26)
[error] ├ flatMap @ TestApp$.$anonfun$loop$2(TestApp.scala:27)
@Daenyth
Daenyth / monad-li-seme.md
Last active May 11, 2023 15:12
What's a monad

"Monad" is a word that describes a set of behaviors

In scala, we use the Monad[Foo] typeclass from cats to define instances of this behavior.

The essence of its behavior is the ability to describe a series of computations, where one computation depends on the result of the computation that came before it.

For example, Monad[Option] shows that the Option[A] data type can be used to describe computations of A which may result in no value.

@ehpc
ehpc / ramda-promises-compose.js
Last active July 17, 2023 03:29
How to compose promises with Ramda
// Custom promise-based compose
const composeWithPromise = (...args) =>
R.composeWith((f, val) => {
if (val && val.then) {
return val.then(f);
}
if (Array.isArray(val) && val.length && val[0] && val[0].then) {
return Promise.all(val).then(f);
}
return f(val);
@Daenyth
Daenyth / Pull.md
Last active November 9, 2023 17:14
Designing an fs2 `Pull` from scratch

The problem

I have some data which has adjacent entries that I want to group together and perform actions on. I know roughly that fs2.Pull can be used to "step" through a stream and do more complicated logic than the built in combinators allow. I don't know how to write one though!

In the end we should have something like

def combineAdjacent[F[_], A](
 shouldCombine: (A, A) => Boolean,
class Example extends React.Component<
Props,
State,
Snapshot
> {
static getDerivedStateFromProps(
nextProps: Props,
prevState: State
): $Shape<State> | null {
// ...
@bvaughn
bvaughn / updating-subscriptions-when-props-change-example.js
Last active March 27, 2022 09:29
Advanced example for manually updating subscriptions in response to props changes in an async-safe way
// This is an advanced example! It is not typically required for application code.
// If you are using a library like Redux or MobX, use the container component provided by that library.
// If you are authoring such a library, use the technique shown below.
// This example shows how to safely update subscriptions in response to props changes.
// In this case, it is important to wait until `componentDidUpdate` before removing a subscription.
// In the event that a render is cancelled before being committed, this will prevent us from unsubscribing prematurely.
// We also need to be careful about how we handle events that are dispatched in between
// `getDerivedStateFromProps` and `componentDidUpdate` so that we don't put stale values into the `state`.
@bvaughn
bvaughn / updating-external-data-when-props-changes-using-promises.js
Last active June 16, 2024 21:56
Example for loading new external data in response to updated props
// This is an example of how to fetch external data in response to updated props,
// If you are using an async mechanism that does not support cancellation (e.g. a Promise).
class ExampleComponent extends React.Component {
_currentId = null;
state = {
externalData: null
};
@bvaughn
bvaughn / eager-prefetching-async-data-example.js
Last active June 16, 2024 21:56
Advanced example for eagerly prefetching async data in a React component.
// This is an advanced example! It is not intended for use in application code.
// Libraries like Relay may make use of this technique to save some time on low-end mobile devices.
// Most components should just initiate async requests in componentDidMount.
class ExampleComponent extends React.Component {
_hasUnmounted = false;
state = {
externalData: null,
};
@aortbals
aortbals / squash-and-merge-cli.md
Last active January 16, 2024 10:46
Squash and Merge on the Command line

With the introduction of GitHub's Squash and Merge feature, this has become less prevelant, however it's still useful in scenarios where GitHub's interface is unavailable.

Let's talk through two ways to do a squash and merge on the command line.

Take 1: Interactive Rebase

When to use it

  • When you have not merged main into your feature branch
  • There are no merge conflicts
@mikeal
mikeal / r2.js
Last active April 21, 2023 17:13
HTTP Client Comparison
const r2 = require('r2')
let doJsonThing = async (path, propname) => {
let res = await r2(`http://api.com${path}`).json
return res[propname]
}