Skip to content

Instantly share code, notes, and snippets.

View sroebert's full-sized avatar

Steven Roebert sroebert

View GitHub Profile
@sroebert
sroebert / renderServerComponent.ts
Created June 12, 2024 05:00
A (hacky) way to render server components for React testing library.
import type { ReactElement, ReactNode } from 'react';
import React, { Children, cloneElement, isValidElement } from 'react';
import { render } from '@testing-library/react';
function setFakeReactDispatcher<T>(action: () => T): T {
/**
* We use some internals from React to avoid a lot of warnings in our tests when faking
* to render server components. If the structure of React changes, this function should still work,
* but the tests will again print warnings.
*
@sroebert
sroebert / LockableViewExample.swift
Created September 8, 2023 22:08
SwiftUI LockableView
import SwiftUI
import UIKit
struct ContentView: View {
@State private var isLocked = false
@State private var isSheetVisible = false
var body: some View {
LockableView(isLocked: isLocked) {
/*global Shelly, MQTT */
/**
* Variables
*/
let FIRMWARE_VERSION;
let MQTT_TOPIC_PREFIX;
let COMPONENT_CONFIG_DICT = {};
@sroebert
sroebert / shelly-plus-1-mqtt.js
Last active February 6, 2022 10:47
shelly-plus-1-mqtt-script
function announce(topicPrefix) {
MQTT.publish(topicPrefix + "/online", "true")
Shelly.call(
"Sys.GetConfig",
{},
function(systemConfig, errorCode, errorMessage, data) {
if (systemConfig.device !== undefined) {
data.payload.id = "shellyplus1-" + systemConfig.device.mac
data.payload.mac = systemConfig.device.mac