Skip to content

Instantly share code, notes, and snippets.

View devrnt's full-sized avatar
🖐️

Jonas De Vrient devrnt

🖐️
View GitHub Profile
@devrnt
devrnt / launch.json
Last active May 11, 2019 12:13
Flutter VSCode configurations
{
"version": "0.2.0",
"configurations": [
{
"name": "Flutter Free",
"request": "launch",
"type": "dart",
"args": [
"--flavor",
"free"
import 'package:flutter/material.dart';
class FlavorConfig extends InheritedWidget {
final Widget child;
final FlavorBuild flavorBuild;
FlavorConfig({@required this.child, @required this.flavorBuild});
static FlavorConfig of(BuildContext context) =>
context.inheritFromWidgetOfExactType(FlavorConfig);
void main(){
final flavorConfig = FlavorConfig(
child: MyApp(),
flavorBuild: FlavorBuild.Free,
);
runApp(flavorConfig);
}
// If you want a pro version create a new main file like 'main_pro.dart'.
const config = require('../config/config');
const WebSocket = require('ws')
const wss = new WebSocket.Server({ port: config.port });
console.log('[WebSocket] Starting WebSocket server...');
wss.on('connection', (ws, request) => {
const clientIp = request.connection.remoteAddress;
console.log(`[WebSocket] Client with IP ${clientIp} has connected`);
const config = require('../config/config');
const WebSocket = require('ws');
const url = `ws://${config.Ip}:${config.port}`;
const connection = new WebSocket(url)
// Send message when the connection with the websocket is established
connection.onopen = () => {
connection.send(
// Send any json object to the websocket and other devices
@devrnt
devrnt / store.ts
Created November 14, 2021 19:37
Simple state management in React
import * as React from 'react';
/**
* The subscription callback
*/
export type Subscribe<T extends State = State> = (
value: Readonly<T>,
changes: Partial<T>
) => void;
@devrnt
devrnt / next-api-handler.md
Last active December 20, 2022 19:13
NextJS API handler

Next API handler

A simple NextJS API abstraction to enforce validation and conistent HTTP responses in REST API endpoints

Features

  • Out-of-the-box validation of both the request body and search params with Zod
  • Type safe request body and search params
  • Consistent HTTP 400 on validation errors, HTTP 500 on any other runtime error
  • Same NextJS API behaviour that you already love
@devrnt
devrnt / Wizard.tsx
Created June 25, 2024 19:49
Simple wizard
import { useState } from 'react';
type WizardConfig<T> = {
[K in keyof T]: {
previous?: ((activeStep: keyof T, payload?: any) => keyof T) | keyof T;
next?: ((activeStep: keyof T, payload?: any) => keyof T) | keyof T;
};
};
type BaseConfig = Record<string, any>;