Skip to content

Instantly share code, notes, and snippets.

@evancloutier
evancloutier / _app.tsx
Created October 23, 2020 18:27
Cookie Based Authentication in NextJS Application
const App: NextPage<Props> = ({ prop }) => {
const [{ authenticated, loading }, dispatch] = useReducer(
AuthenticationReducer,
{
authenticated: false,
loading: true,
}
);
useEffect(() => {
@evancloutier
evancloutier / application.tsx
Created September 17, 2020 00:37
React Navigation Tabs Setup
// This is the application
<Stack.Navigator
initialRouteName={signup ? "Signup" : "Dashboard"}
screenOptions={{
cardStyle: { backgroundColor: Colors.white },
headerShown: false
}}
mode="modal"
>
@evancloutier
evancloutier / example.ts
Last active September 1, 2020 14:23
Using React Navigation navigator outside of components
// We can create a `NavigationService` singleton that allow us to access the top-level navigator
// for navigation outside of our components.
// services/navigation.ts
import { NavigationContainerRef } from "@react-navigation/native";
export class NavigationService {
public static navigator: NavigationContainerRef;

Project Saving Snippet

Background

When we were in the final stages of the virtual piano project, one of the last steps was to map the user's finger points from the color frame to the depth frame. This would allow us to determine whether or not a key was actually being pressed (which is pretty important if you want a piano to actually play notes), rather than just being hovered over. Let's say your hand looked like this, where the green circles denote the centres of your fingertips:

Skeletonized hand

To determine if a particular key was being pressed, we needed to calculate the difference between the current depth at that finger point and the original depth at that point when there was nothing in that frame, which was stored in a 2D numpy array. If the difference was lower than a specified threshold, you're playing music.