Skip to content

Instantly share code, notes, and snippets.

@nikcorg
nikcorg / berlin-jsconf-2014.md
Last active August 4, 2023 12:45
Slide decks of JSConf 2014
@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 / 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 / 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 / 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 / promisified-hyperquest.js
Last active May 10, 2018 05:44
Promisified Hyperquest -- A quick exercise wrapping Hyperquest in a Promise for an easy thenable API.
var concat = require("concat-stream");
var hyperquest = require("hyperquest");
var Promise = require("bluebird");
var stream = require("stream");
// Wait for the request to finish or fail
function promisify(req) {
return new Promise(function (resolve, reject) {
req.on("error", reject).pipe(concat({ encoding: "string" }, resolve));
@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"
@nikcorg
nikcorg / index.html
Last active January 14, 2017 17:09
Shakespearean insult generator
<html>
<head>
<meta charset="utf-8">
<title>Shakespearean insult generator</title>
<style>
* {
box-sizing: border-box;
font-family: "Comic Sans MS", "Comic Sans";
}
body {