Skip to content

Instantly share code, notes, and snippets.

View edgarogh's full-sized avatar

Edgar Onghena edgarogh

View GitHub Profile

Keybase proof

I hereby claim:

  • I am edgarogh on github.
  • I am edgaronghena (https://keybase.io/edgaronghena) on keybase.
  • I have a public key ASC4Nz7OVdQrgtsL94sOHVs_gl3YODNQ-n-wzZ8juHq8Owo

To claim this, I am signing this object:

import { Req, Res } from "./express.types";
import { NextFunction } from "express";
/**
* This middleware adds two functions to the response object to make it easier
* to build a JSON API.
*/
export default function jsonApiMiddleware() {
return (req: Req, res: Res, next: NextFunction) => {
res.jsonData = (json) => {
{
"type": "object",
"additionalProperties": true,
"dependencies": {
"slot": {
"type": "object",
"required": [
"features"
],
"properties": {
type MessageDefs = {
// This whole object will be passed as the first argument of the socket.io packet
'user.get': {
id: string;
// Except for the optional `ack`, which itself represents the first argument of the acknowledgment
ack: User;
}
@edgarogh
edgarogh / spotifyPause.md
Last active February 1, 2024 18:12
Start Spotify w/ Play/Pause key

spotifyPause.sh

This short script allows the Play/Pause keyboard key to be also used to start Spotify (or any player of your choice with a bit of tweaking). I'm using Cinnamon's settings to reassign keys, but other distros may also have this feature

Setup

  • Download/copy the script somewhere on your system
  • chmod +x ./spotifyPause.sh to make it runnable
  • Add the new keybinding [Cinnamon only]
  • Open cinnamon-settings keyboard (you can search for "Keyboard" in the start menu search if you don't like terminals)
@edgarogh
edgarogh / ScopedState.tsx
Created October 13, 2019 16:03
Scoped useState in React - Share useState values between a component's children - Never ever tested, probably doesn't even work
import React, { createContext, Dispatch, ReactNode, SetStateAction, useContext, useState } from 'react';
export interface ScopeValue<V> {
value: V;
setValue(value: V): void;
}
export interface Scope {
(props: { children: ReactNode }): JSX.Element;
}
This file has been truncated, but you can view the full file.
echo "H4sIAEn/rFsAA3R9BVhUz/f33WXBBRGXFMRYSspALOwFSVFcg1BEV0BMFFEUC5ZQKXFtDBADO1CxA2xUUFDEwMDAbgzs98Cc+f2/l5fheT7M3rOzc2fOnJozc3dj3Qa4CwUCjv6pcX242iv5cbO6axnSS2Z5/q+OjHPiNOF/K64lpwHX6v+pV7+sEfBL8f/uw3EigJOQXNcvW3D8UvCfUp1j/w2o6cMrOU76v8/V9lX8g9DFP0bxSuV8zbpSlaTN+5wQPyfX6lt3LdcazStl2F9a0vGJEMOQXr905filCEt51YzQ2tehjt3rruuXvb5xvJJ+bjB8TqMBfrD+JFgOwfux+FJjxPFKOg8dJk8I7tq5w+TQdpMnTImKbhft1LVd187tp09t71jXJwnW9fDxratP+SjFPhtwRAZq37dW2rvujlPrar5/u1/HvEMzVm9+d/QjvPlKQBrRqf3MnbTBjUUDxZxcJOM2JbnHJ8kkIs6KkxSIxWbZUEEZL4kTmtfeSlcudpEoJQaaMsFGoczcWJLMXRwqdI4TNRbtGMxJFifFmakp19jpaqwYLJBrcWItgRK6q1krVmIVFyfj/ogqCwQGEk4g0eIMXRI5F5kgnXMSBARIlf0knlKxhEs0FSuVUk5oLNSTKqVSSxelVCgQcYvVbcSctG5KZEqBhkwuEyQVchGcsbMWDERTVvuGlp5QKdbWBU6IPkkkQuUIQXypWoIcFAY+Z84lGcg4Q3Ec11bMiQ3sNqosFkyMU6UUGAiEUKOAk2ZLz4gkUs5ZLMr19FzBCdMkcqlSUyzSS5KOhzZ1ZRIl59DGwGU2J5Uu0hWLgX1CPWW8lFMppWJOZiCRSCVKV6VI0zKOWxBtqYyTlDvoca7KsPUioXQhzI5LgFDpLOrEKTillrkgUSRy1nCVO5xJdxGViBr3s9A0VsqHKJWJYt0CmGJhIjBJJRNLBPHq7WULlUJlnUwKxKIQG22JSKar3uaAjZssiRPruUhlEk7OKZNklUqHbInEsx
@edgarogh
edgarogh / README.md
Created March 2, 2020 19:34
Algebraic Data Type TypeScript implementation -- c.f. OCaml / Rust / ...

Algebraic Data Type TypeScript implementation

  • ADT "constructor"
  • Very elementary type-safe function-based "match"
const { readFileSync, writeFileSync } = require('fs');
const lines = readFileSync('/dev/stdin', 'utf8').split('\n');
/**
* @param {string} line
*/
function indent(line) {
try {
const indent = /^( *).*$/g.exec(line)[1].length;
/**
* @param {HTMLTableRowElement} tr
*/
const stringOfTr = (tr) => Array.from(tr.children)
.map((el) => JSON.stringify(el.innerText))
.join(',')
/**
* @param {HTMLTableElement} table
*/