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);
import {
html,
css
} from "lit";
import {
pureLit
} from "pure-lit"
const blockStyle = css`:host { display: block; }`
@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
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
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);
pureLit("dispatch-todo", (element) => {
const { publish, getState } = useState(element, { todos: [] } as TodoState);
return html`
<h2>Your todos</h2>
<todo-add
@add="${(e: CustomEvent) =>
publish({ todos: [...getState().todos, e.detail] })}"
></todo-add>
<todo-list
.items="${getState().todos}"
(element) => {
const { publish, getState } = useState(element, TodoReducer, { todos: [] });
return html`
<button @click="${() => publish("add", "lala")}">
Add value
</button>
<textarea>${getState().join(",")}</textarea>
`
}
import {
LitElement,
customElement,
html,
css,
property
} from "lit-element";
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,