Skip to content

Instantly share code, notes, and snippets.

Avatar

LiBe libetl

View GitHub Profile
@libetl
libetl / msw-to-intercept-connector.ts
Created February 28, 2023 20:57
msw-to-intercept-connector
View msw-to-intercept-connector.ts
import type { SetupWorkerApi } from 'msw'
export function connectWorkerToCypressIntercept(worker: SetupWorkerApi): void {
worker.events.on('request:start', request => {
if (!(window as any).cy) return
const cy = (window as any).cy
const mapping = Object.values(cy.state('routes')).map((route: any) => ({
alias: route.alias,
method: route.options.method,
matcher: new RegExp(
@libetl
libetl / RawSocketSender.kt
Last active January 31, 2023 18:31
fluent-logger-java jakarta EE
View RawSocketSender.kt
package com.mycompany.service.fluentd
// this class is a fork of the fluent-logger-java library
import org.msgpack.core.MessagePack
import java.io.BufferedOutputStream
import java.io.IOException
import java.math.BigInteger
import java.net.InetSocketAddress
import java.net.Socket
@libetl
libetl / CustomLogbackSystemFactory.kt
Created December 31, 2022 13:55
Custom logback Joran Configuration in spring boot 3
View CustomLogbackSystemFactory.kt
package com.company.myservice.tool
import ch.qos.logback.classic.Level
import ch.qos.logback.classic.Logger
import ch.qos.logback.classic.LoggerContext
import ch.qos.logback.classic.joran.JoranConfigurator
import ch.qos.logback.classic.turbo.TurboFilter
import ch.qos.logback.core.spi.FilterReply
import ch.qos.logback.core.status.Status
import ch.qos.logback.core.status.StatusUtil
@libetl
libetl / playground.tsx
Created March 31, 2022 16:15
My Design System playground
View playground.tsx
import * as React from "react";
import { promises as fs } from "fs";
import * as myDesignSystem from "my-design-system";
import { LiveProvider, LiveError, LivePreview, LiveContext } from "react-live";
import dynamic from "next/dynamic";
let monaco: any = undefined;
const MonacoEditor: typeof import("react-monaco-editor").default =
(typeof global.window === 'undefined') ? undefined : dynamic(import("react-monaco-editor")
.then((mod) => {
@libetl
libetl / add-mjs-extension-transformer.js
Created January 31, 2022 18:03
add-mjs-extension-transformer.js
View add-mjs-extension-transformer.js
const typescript = require("typescript");
const path = require("path");
module.exports = (_) => (transformationContext) => (sourceFile) => {
function visitNode(node) {
if (shouldMutateModuleSpecifier(node)) {
const factory = transformationContext.factory;
if (typescript.isImportDeclaration(node)) {
const newModuleSpecifier = factory.createStringLiteral(`${node.moduleSpecifier.text}.mjs`);
node = factory.updateImportDeclaration(node, node.decorators, node.modifiers,
node.importClause, newModuleSpecifier, node.assertClause);
@libetl
libetl / get-string.ts
Created October 29, 2021 17:14
webassembly-config
View get-string.ts
/**
* Reads a string from the memory table.
* When a web assembly returns a string, javascript only sees the pointer
* to the memory table, and has to read the value from the table.
*
* @param instance web assembly program instance (memory + code)
* @param pointer where does the string start in the memory table
* @returns a slice of the memory table starting from pointer and ending before \0
*/
export const getString = (instance: WebAssembly.Instance, pointer: number): string => {
@libetl
libetl / [page].tsx
Created August 31, 2021 14:51
dynamic site sections in next.js
View [page].tsx
import * as React from "react";
import { promises as fs } from "fs";
import { resolve } from "path";
import matter from "gray-matter";
import { MDXRemote } from "next-mdx-remote";
import { serialize } from "next-mdx-remote/serialize";
type PageProps = { documentProps: {
menu: Record<string, string>[];
frontMatter: {
@libetl
libetl / GrpcConfiguration.kt
Created March 29, 2021 18:12
GrpcConfiguration
View GrpcConfiguration.kt
package com.company.service.configuration
import com.google.protobuf.MessageLite
import io.grpc.BindableService
import io.grpc.Channel
import io.grpc.netty.NettyChannelBuilder
import io.netty.handler.ssl.ApplicationProtocolConfig
import io.netty.handler.ssl.ApplicationProtocolConfig.Protocol.ALPN
import io.netty.handler.ssl.ApplicationProtocolConfig.SelectedListenerFailureBehavior.ACCEPT
import io.netty.handler.ssl.ApplicationProtocolConfig.SelectorFailureBehavior.NO_ADVERTISE
@libetl
libetl / Helpers.kt
Last active December 1, 2020 08:49
React in Java
View Helpers.kt
package com.mycompany.react
import org.w3c.dom.html.HTMLElement
import java.lang.reflect.InvocationHandler
import java.lang.reflect.Method
import java.lang.reflect.Proxy
import kotlin.reflect.KClass
import kotlin.reflect.KType
import kotlin.reflect.full.createType
import kotlin.reflect.full.isSubtypeOf
@libetl
libetl / LoadYaml.kt
Created October 31, 2020 13:21
LoadYaml.kt
View LoadYaml.kt
package com.mycompany.library.tools
import org.springframework.boot.env.YamlPropertySourceLoader
import org.springframework.core.env.ConfigurableEnvironment
import org.springframework.core.env.Profiles
import org.springframework.core.io.ClassPathResource
object LoadYaml {
data class LoadOptions(