Skip to content

Instantly share code, notes, and snippets.

View koca's full-sized avatar

Mesut Koca koca

View GitHub Profile
@Sh4yy
Sh4yy / clx.go
Created April 25, 2024 20:39
Generate CLI commands for common tasks.
package main
import (
"context"
"errors"
"fmt"
"io"
"log"
"os"
"runtime"
@yayiji
yayiji / oneshot.edn
Last active September 7, 2022 15:07
Oneshot Implementation by Karabiner-Elements
{:profiles
{:oneshot {:default true
:alone 300 ;
:held 150 ;
:delay 500 ; time after which the key press is delayed
:sim 50}} ; keys need to be pressed within this threshold to be considered simultaneous
:main [{:des "Symbol Mode"
:rules [:symbol-mode
[:q :grave_accent_and_tilde]
@souporserious
souporserious / build.mjs
Created February 24, 2022 02:48
Build script using esbuild and ts-morph to bundle library code.
import glob from 'fast-glob'
import { build } from 'esbuild'
import { Project } from 'ts-morph'
const project = new Project({
compilerOptions: {
outDir: 'dist',
emitDeclarationOnly: true,
},
tsConfigFilePath: './tsconfig.json',
@Akryum
Akryum / hookable.spec.ts
Created August 22, 2021 13:49
Type-safe hooks
import { Hookable } from '../src/hookable'
describe('hookable', () => {
test('hook with one callback', async () => {
const hooks = new Hookable<{
invert:(value: boolean) => boolean | Promise<boolean>
}>()
hooks.hook('invert', value => !value)
@martinwoodward
martinwoodward / setup.md
Last active December 3, 2023 17:01
Camera Setup
@souporserious
souporserious / build.js
Created May 23, 2021 16:46
Estrella build config
const { build } = require('estrella')
const { dependencies } = require('./package.json')
build({
entry: 'src/index.ts',
outfile: 'dist/index.js',
bundle: true,
platform: 'node',
external: Object.keys(dependencies),
})
@ryanflorence
ryanflorence / question.ts
Created January 12, 2021 21:48
generic generics?
// My DB has multiple collections (tables), they can extend
// this since the only difference is the data an collection,
// they're passed in as generics
export interface Record<TData, TCollection> {
data: TData;
ref: {
collection: {
id: TCollection;
};
id: string;
function partition(inputArray, callback) {
const result = {};
for (const [indexOfValue, value] of inputArray.entries()) {
const propertyKey = callback(value, indexOfValue);
if (propertyKey === null || propertyKey === '') {
continue;
}
if (!{}.hasOwnProperty.call(result, propertyKey)) {
result[propertyKey] = [];
}
import * as React from "react";
import { useMousePosition } from "~/hooks/useMousePosition";
/** Component to cover the area between the mouse cursor and the sub-menu, to allow moving cursor to lower parts of sub-menu without the sub-menu disappearing. */
export function MouseSafeArea(props: { parentRef: React.RefObject<HTMLDivElement> }) {
const { x = 0, y = 0, height: h = 0, width: w = 0 } = props.parentRef.current?.getBoundingClientRect() || {};
const [mouseX, mouseY] = useMousePosition();
const positions = { x, y, h, w, mouseX, mouseY };
return (
<div
@souporserious
souporserious / use-measure-example.jsx
Last active February 29, 2020 15:23
use-measure hook for collecting component measurements
// Handle outside and local measurements easily
function Singular({ ref, value }) {
const [width, setWidth] = useState(-1)
const [useMeasureRef, useMeasureEffect] = useMeasure()
useMeasureRef(ref)
useMeasureEffect(
([node]) => {
setWidth(node.offsetWidth)
},
[value]