Skip to content

Instantly share code, notes, and snippets.

View ocpu's full-sized avatar
🦊
Unsure of what is going on

Martin Hövre ocpu

🦊
Unsure of what is going on
  • Karlskrona, Sweden
  • 02:17 (UTC +02:00)
View GitHub Profile
@ocpu
ocpu / flags.ts
Last active March 18, 2021 11:47
import { parse } from "https://deno.land/[email protected]/flags/mod.ts";
interface FlagDefinitionObject<T, TCtor = new () => T> {
type: TCtor;
alias?: string | string[];
default?: T;
}
type FlagDefinition =
| BooleanConstructor
| StringConstructor
@ocpu
ocpu / KeyCombo.js
Created January 20, 2021 17:49
A representation of a keyboard combination that can test against a DOM KeyboardEvent
const keyToEventKeyMap = [
['Escape', 'Esc'],
[' ', 'Space'],
['ArrowLeft', 'Left'],
['ArrowRight', 'Right'],
['ArrowUp', 'Up'],
['ArrowDown', 'Down'],
['Enter', 'Return'],
['Add', 'Plus', '+'],
['Subtract', 'Minus', '-'],
/**
* @typedef TextSpecificity
* @property {number} exactWordMatches
* @property {number} exactWordMatchesInSequence
* @property {number} continuesWordMatches
*/
/**
* Searches with the given search string for items that matches it. It sorts
* the returned items where the most specific item is first and the least
* specific is last. If an item does not have any matching qualities it is
@ocpu
ocpu / add-monitor.sh
Last active January 12, 2021 20:41
use rofi/dmenu to configure/disconnect/modify a monitor with xrandr
#!/bin/bash
# Provides an interactive xrandr experience with dmenu or dmenu
# like programs
# If the Window Manager requires a restart / reload put the
# command here or leave blank
RESTART_WM_CMD="i3-msg restart"
# Any command that takes a pipe of newline separated options
# Such as for example dmenu and rofi -dmenu
D_MENU_CMD="rofi -dmenu"
xinput --set-prop 'DLL07BE:01 06CB:7A13 Touchpad' 'libinput Natural Scrolling Enabled' 1
xinput --set-prop 'DLL07BE:01 06CB:7A13 Touchpad' 'libinput Tapping Enabled' 1
@ocpu
ocpu / easy2drenderer.js
Created November 14, 2018 13:48
My version of a easy 2d canvas context renderer.
/**
* Creates a renderer for a CanvasRenderingContext2D (2d canvas context).
*
* @param {HTMLCanvasElement} canvas The canvas to render on.
* @author Martin Hövre <[email protected]>
* @license MIT
*/
function renderer2d(canvas) {
// The context for the renderer
const ctx = canvas.getContext('2d')
const query = db => (strings, ...values) => db.query(strings.join('?'), values)
function sqlQuery(db) {
return (strings, ...values) => {
const str = strings.join('?')
return db.query(str, values)
}
}
@ocpu
ocpu / argv.js
Last active December 25, 2019 20:28
Parse string input into a list of arguments based on bash parsing.
/**
* @typedef argvOutput
* @property {string[]} args The resulting arguments.
* @property {boolean} hasEnd If the last combined arg was closed.
*/
/**
* Turn a string input into a list of arguments.
*
* Parsing based on how bash parses arguments.
*
Redux

Modules: redux react-redux redux-thunk

Files:

functions/app/components/layout.js
// Other imports
@ocpu
ocpu / build.gradle
Created March 3, 2018 11:14
My personal build.gradle for minecraft modding
buildscript {
ext.modPath = ''
ext.modName = ''
ext.modVersion = ''
ext.forgeVersion = ''
ext.mcVersion = ''
repositories { maven { url = "http://files.minecraftforge.net/maven" } }
dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' }
}