Skip to content

Instantly share code, notes, and snippets.

View technige's full-sized avatar
🇪🇺

Nigel Small technige

🇪🇺
View GitHub Profile
@technige
technige / alt
Created July 12, 2023 12:27
Alt switcher for bash
#!/usr/bin/env bash
MENU=$1
OPTION=$2
MENU_PATH=${HOME}/.alt/${MENU}
cd ${MENU_PATH}
if [ ! -z "$OPTION" ]
then
from argparse import ArgumentParser
from io import BytesIO
from PIL.Image import open as open_image
def image_to_ansi(data, scale=1):
# TODO: optimise this algorithm - it's pretty brute-force right now
image = open_image(BytesIO(data))
width, height = image.size
@technige
technige / elk-docker-howto.md
Last active November 18, 2021 17:08
How to run Elasticsearch and Kibana in local Docker containers

How to run Elasticsearch and Kibana in local Docker containers

This document contains step-by-step notes for how to run Elasticsearch and Kibana in local Docker containers.

This assumes three terminal windows are available: A (control), B (Elasticsearch) and C (Kibana). Note also that the stack version included here may be varied, although it should remain identical across both components.

1. Create a Docker network

In terminal A, run:

@technige
technige / parse-uri.js
Last active March 23, 2021 14:28
Basic URI parser in JS
// JS version of Python partition function
function partition(s, delimiter) {
const i = s.indexOf(delimiter);
if (i >= 0) return [s.substring(0, i), s[i], s.substring(i + 1)];
else return [s, "", ""];
}
// JS version of Python rpartition function
function rpartition(s, delimiter) {
const i = s.lastIndexOf(delimiter);
@technige
technige / rfc3986.py
Created February 4, 2021 08:59
Implementation of RFC 3986 -- Uniform Resource Identifier (URI): Generic Syntax
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2012-2015, Nigel Small
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@technige
technige / ocsp-test.java
Last active June 25, 2020 11:36
Tests for OCSP stapling
package tech.nige.demo;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.security.NoSuchAlgorithmException;
import java.security.cert.Certificate;
public class SocketDemo {
from dataclasses import dataclass, fields
def neodataclass(_cls=None, *, init=True, repr=True, eq=True, order=False,
unsafe_hash=False, frozen=False):
""" Provides a wrapper around dataclass that silently filters out
any keyword arguments provided to __init__ that do not exist as
fields for that class.
"""
@technige
technige / boltproxy.py
Created June 15, 2017 08:54
Simple proxy server for the Bolt protocol.
#!/usr/bin/env python
# coding: utf-8
# Copyright 2017, Nigel Small
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from __future__ import print_function
import random
from time import time
from py2neo import Graph, GraphError
def deprecated(message):
""" Decorator for deprecating functions and methods.
::
@deprecated("'foo' has been deprecated in favour of 'bar'")
def foo(x):
pass
"""