Skip to content

Instantly share code, notes, and snippets.

View manuel-mauky's full-sized avatar

Manuel Mauky manuel-mauky

View GitHub Profile
@manuel-mauky
manuel-mauky / UseMediaExample.tsx
Created June 15, 2020 18:18
React-Hooks-Article: useMedia hook
import React, { useEffect, useState } from "react"
const useMedia = (query: string): boolean => {
const [matches, setMatches] = useState(false)
useEffect(() => {
const queryObject = window.matchMedia(query)
setMatches(queryObject.matches)
const listener = (e: MediaQueryListEvent) => {
@manuel-mauky
manuel-mauky / LoadDataFunction.tsx
Created June 15, 2020 18:16
React-Hooks-Article: Load data Function component with cleanup
useEffect(() => {
const controller = new AbortController()
fetch("/some-data.json", { signal: controller.signal })
.then((response) => response.json())
.then((data) => {
setData(data)
})
return () => {
@manuel-mauky
manuel-mauky / LoadDataFunction.tsx
Created June 15, 2020 18:11
React-Hooks-Article: Load data in function component with useState and useEffect
import React, { useEffect, useState } from "react"
export const LoadDataFunction = () => {
const [data, setData] = useState()
useEffect(() => {
fetch("/some-data.json")
.then((response) => response.json())
.then((data) => {
setData(data)
@manuel-mauky
manuel-mauky / LoadDataClass.tsx
Last active June 15, 2020 18:19
React-Hooks-Article: Load data in class component
import React from "react"
export class LoadDataClass extends React.Component {
componentDidMount(): void {
fetch("/some-data.json")
.then((response) => response.json())
.then((data) => {
this.setState({ data })
})
}
@manuel-mauky
manuel-mauky / ExpansionBoxFunction.tsx
Created June 15, 2020 18:01
React-Hooks-Article: Expansion Box implemented as Function with useState Hook
import React, { FC, useState } from "react"
import "./expansion-box.css"
type Props = {
title: string
}
export const ExpansionBoxFunction: FC<Props> = (props) => {
const [expanded, setExpanded] = useState(false)
@manuel-mauky
manuel-mauky / ExpansionBoxClass.tsx
Created June 15, 2020 17:59
React-Hooks-Article: Expansion Box implemented as Class
import React from "react"
import "./expansion-box.css"
type Props = {
title: string
}
type State = {
expanded: boolean
}
@manuel-mauky
manuel-mauky / App.java
Created April 26, 2016 16:43
JavaFX Controller is removed by garbage collector while the fxml file is still shown
package org.example;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class App extends Application {
@manuel-mauky
manuel-mauky / TestApp.java
Last active February 10, 2016 09:52
ComboBox Eventhandling when ENTER is pressed
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.event.EventType;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
@manuel-mauky
manuel-mauky / MvvmfxExampleApp.java
Last active April 5, 2018 02:53
mvvmFX example implementing a registration form. Dependencies needed: `de.saxsys:mvvmfx` and `eu.lestard:advanced-bindings`
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import de.saxsys.mvvmfx.FluentViewLoader;
public class MvvmfxExampleApp extends Application {
public static void main(String... args) {
@manuel-mauky
manuel-mauky / jdk8_completablefuture_monad_laws.java
Last active January 6, 2017 14:58
Does JDK8's CompletableFuture class satisfy the Monad laws? Yes, it does.
/**
* ```
* Does JDK8's CompletableFuture class satisfy the Monad laws?
* =================================================
* 1. Left identity: true
* 2. Right identity: true
* 3. Associativity: true
*
* Yes, it does.
* ```