Skip to content

Instantly share code, notes, and snippets.

@nikcorg
nikcorg / git-commit
Last active November 3, 2022 13:52
Git commitizen/conventional commits helper
#!/usr/bin/env bash
## A utility for following the Conventional Commits style
##
## usage: __USAGE__
##
## Options
## -h this help
## -a commit all
## -s <scope> set the scope for the commit
@nikcorg
nikcorg / ANSI.md
Created March 10, 2022 18:42 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@nikcorg
nikcorg / quickserve.sh
Last active March 11, 2021 07:56
Serve a file or an empty response using netcat
#!/usr/bin/env bash
# Serve a file as HTTP response using netcat
set -eu
# Error outcomes
EX_UNAVAILABLE=69
# Initial values
@nikcorg
nikcorg / summed-area-table.ts
Last active February 5, 2019 00:02
Summed-area Table
// https://en.wikipedia.org/wiki/Summed-area_table
type Point = { x: number; y: number };
type DefaultingGetter<T> = (x: number) => T;
type DefaultingGetterFactory = <T>(xs: T[], def: T) => DefaultingGetter<T>;
interface Mapper {
toxy: (n: number) => Point;
toi: (x: number, y: number) => number;
}
@nikcorg
nikcorg / gsm7bit-decoder.js
Last active July 31, 2020 07:17
GSM 7 Bit Decoder
// This decoder is based on this answer https://stackoverflow.com/a/21115816
// It's not perfect, e.g. it does not accommodate the extended alphabet.
//
// Solution from SO answer paraphrased below:
//
// For input: C7F7FBCC2E03
// 1) Form tuples for hex numbers and reverse
// -> 03-2E-CC-FB-F7-C7
// 2) Convert hex to 8-bit binary octets
// -> 00000011-00101110-11001100-11111011-11110111-11000111
@nikcorg
nikcorg / main.go
Created September 24, 2018 12:51
Playing with Maybe in Go
package main
import (
"fmt"
"strings"
)
type Any interface{} // The lack of generics in Go is the pitfall
type Morphism func(Any) Any
@nikcorg
nikcorg / inspirobot-bg.sh
Created March 27, 2018 08:31
Inspirobot background images
#!/usr/bin/env bash
DUMP=/path_to_downloaded_images_storage_here
GENERATED_IMG_SRC=$(curl -s "http://inspirobot.me/api?generate=true")
if [ $? -eq 0 ]; then
BASENAME=$(basename $GENERATED_IMG_SRC)
OUT="$DUMP/$BASENAME"
TMP="/tmp/$BASENAME"
function dump(o, p)
p = p or ''
if type(o) == 'table' then
local s = '{\n'
local pp = p .. ' '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"' .. k .. '"' end
s = s .. pp .. '[' .. k .. '] = ' .. dump(v, pp)
@nikcorg
nikcorg / document-meta-proxy.js
Last active April 16, 2016 09:03
Proxy pattern for transforming props passed to react-document-meta
import React from "react";
import DocumentMeta from "react-document-meta";
const applyTransforms = ({ title, ...props }) => ({ ...props, title: `${title} - suffix` });
export default const ProxyComponent = (props) => <DocumentMeta {...applyTransforms(props)} extend />;
<!doctype html>
<html>
<head>
<title>TableSort Demo</title>
<body>
<table>
<thead>
<tr>
<th class="default-sort">Weekday</th>
<th>Date</th>