Skip to content

Instantly share code, notes, and snippets.

@nikcorg
nikcorg / git-cz
Last active Oct 5, 2022
Git commitizen/conventional commits helper
View git-cz
#!/usr/bin/env bash
##
## Helper script for Commitizen or Conventional Commits style git commits
##
## Options
## -h this help
## -a commit all
## -s <scope> set the scope for the commit
## -r reuse the scope from the previous commit
@nikcorg
nikcorg / ANSI.md
Created Mar 10, 2022 — forked from fnky/ANSI.md
ANSI Escape Codes
View ANSI.md

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 Mar 11, 2021
Serve a file or an empty response using netcat
View quickserve.sh
#!/usr/bin/env bash
# Serve a file as HTTP response using netcat
set -eu
# Error outcomes
EX_UNAVAILABLE=69
# Initial values
View summed-area-table.ts
// 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 Jul 31, 2020
GSM 7 Bit Decoder
View gsm7bit-decoder.js
// 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 Sep 24, 2018
Playing with Maybe in Go
View main.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 Mar 27, 2018
Inspirobot background images
View inspirobot-bg.sh
#!/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"
View dump.lua
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 Apr 16, 2016
Proxy pattern for transforming props passed to react-document-meta
View document-meta-proxy.js
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 />;
View index.html
<!doctype html>
<html>
<head>
<title>TableSort Demo</title>
<body>
<table>
<thead>
<tr>
<th class="default-sort">Weekday</th>
<th>Date</th>