Skip to content

Instantly share code, notes, and snippets.

#include <CoDrone.h> // The codrone library that holds all the background files for this
void setup()
{
CoDrone.begin(115200);
//connect with drone controller have adress
// CoDrone.pair();
//connect with the nearest drone
CoDrone.pair(Nearest);
@MatthiasKainer
MatthiasKainer / greet.js
Created December 16, 2022 12:44
simple example for a CPU heavy webworker without blocking the browser
function heavyComputation(n) {
if (n <= 1) {
return n;
}
return heavyComputation(n - 1) + heavyComputation(n - 1);
}
onmessage = function (e) {
console.log('Worker: Message received from main script', e.data);
@MatthiasKainer
MatthiasKainer / tell-me-when-site-is-back.sh
Last active September 27, 2021 10:07
[MacOS][workflow] Notify me when a website is back again. Call like this: `./tell-me-when-site-is-back.sh https://matthias-kainer.de &` (replace my homepage with yours...)
#!/bin/bash
URL="$1"
while true; do
OUTPUT_FILE=$(mktemp)
HTTP_CODE=$(curl --silent --output $OUTPUT_FILE --write-out "%{http_code}" "$URL")
if [ $? -lt 399 ]
then
osascript -e "display notification \"$URL is back\""
break
import {
LitElement,
customElement,
html,
css,
property
} from "lit-element";
const blockStyle = css`:host { display: block; }`
import {
html,
css
} from "lit";
import {
pureLit
} from "pure-lit"
const blockStyle = css`:host { display: block; }`
import { html, LitElement } from "lit-element";
import { useState, useReducer } from "lit-element-state-decoupler";
import { pureLit } from "pure-lit";
import { LitElementWithProps } from "pure-lit/types";
type ListProps = { items: string[] };
const add = (state: string) => ({
update: (payload: string) => payload,
add: () => state,
@MatthiasKainer
MatthiasKainer / SpringRestTemplateLoggingRequestInterceptor.kt
Last active May 28, 2020 07:30
Logging everything from a Spring RestTemplate with Kotlin
package de.matthiaskainer.spring.net.resttemplate.logging
import mu.KotlinLogging
import org.springframework.http.HttpRequest
import org.springframework.http.client.ClientHttpRequestExecution
import org.springframework.http.client.ClientHttpRequestInterceptor
import org.springframework.http.client.ClientHttpResponse
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
const clickReducer = (state: number) => ({
add: (payload: number) => state + (payload as number ?? 0)
})
pureLit(
"todo-list",
(element: LitElementWithProps<ListProps>) => html`<ul>
${element.items.map(
(item) =>
html`<li
(element) => {
const { publish, getState } = useState(element, TodoReducer, { todos: [] });
return html`
<button @click="${() => publish("add", "lala")}">
Add value
</button>
<textarea>${getState().join(",")}</textarea>
`
}
const TodoReducer: Reducer<TodoState> = (state) => ({
add: (payload: string) => ({ ...state, todos: [...state.todos, payload as string] }),
remove: (payload: string) => ({
...state,
todos: [...state.todos.filter((todo) => todo !== payload)],
})
})
pureLit("reducer-todo", (element) => {
const { publish, getState } = useReducer(element, TodoReducer, { todos: [] } as TodoState);