Skip to content

Instantly share code, notes, and snippets.

View ToucheSir's full-sized avatar

Brian Chen ToucheSir

View GitHub Profile
@oxinabox
oxinabox / vectorprism.jl
Created August 9, 2023 11:19
VectorPrisms -- a way of viewing any simple nested struct as a vector
module VectorPrisms
function check_compatible(::Type{T}) where T
isconcretetype(T) || error("Type is not fully concrete")
for ft in fieldtypes(T)
check_compatible(ft)
end
end
check_compatible(::Type{<:Array}) = error("Type contains an array")
check_compatible(::Type{Nothing}) = error("Nothing is not supporting.")
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@oxinabox
oxinabox / active_rrule.jl
Created August 10, 2021 12:16
Sketch: Extension of rrule to take in the activity (i.e. if your want to get the derivative wrt this)
abstract type ActivityMarked{T} end
struct Active{T} <: ActivityMarked{T}
val::T
end
struct Dead{T} <: ActivityMarked{T}
val::T
end
@donnut
donnut / currying.md
Last active October 28, 2023 17:58
TypeScript and currying

TypeScript and currying

In functional programming you often want to apply a function partly. A simple example is a function add. It would be nice if we could use add like:

var res2 = add(1, 3); // => 4

var add10To = add(10);
var res = add10To(5); // => 15
@munificent
munificent / gist:9749671
Last active June 23, 2022 04:04
You appear to be creating a new IDE...
You appear to be advocating a new:
[ ] cloud-hosted [ ] locally installable [ ] web-based [ ] browser-based [ ] language-agnostic
[ ] language-specific IDE. Your IDE will not succeed. Here is why it will not succeed.
You appear to believe that:
[ ] Syntax highlighting is what makes programming difficult
[ ] Garbage collection is free
[ ] Computers have infinite memory
[ ] Nobody really needs:
@sebmarkbage
sebmarkbage / react-warning-descriptors.md
Created February 11, 2014 02:10
React Warning - Invalid access to component property

You're probably getting this warning because you're accessing methods on a component before it gets mounted. This will be soon be an unsupported use case.

The component that gets created by invoking the convenience constructor MyComponent(props, children) or using the JSX syntax <MyComponent /> is not guaranteed to be the instance that actually gets mounted. It's a description of what the actual mounted instance should look like.

Anti-pattern:

The component also doesn't have access to state or other important information such as the final props. As a consequence you shouldn't be calling custom methods on this object.

var MyComponent = React.createClass({