Skip to content

Instantly share code, notes, and snippets.

View ngoylufo's full-sized avatar

Ngoy Lufo ngoylufo

  • Qualimi
  • Johannesburg, South Africa
  • X @ngoylufo
View GitHub Profile
@ngoylufo
ngoylufo / gophish
Last active November 14, 2023 10:20
A simple script to download and install the latest version of go for linux (AMD64)
#!/bin/bash
GOHOME="${1:-/usr/local}"
gophish() {
TARBALL="https://dl.google.com/go/$LATEST.linux-amd64.tar.gz"
ARCHIVE="/tmp/go.tar.gz"
echo "Downloading $TARBALL to $ARCHIVE..."
if ! wget -qc "$TARBALL" -O "$ARCHIVE"; then
echo "Failed to download the Go tarball."
@ngoylufo
ngoylufo / gopher.sh
Last active November 14, 2021 15:12
Download latest version of Go using wget
#!/bin/bash
# Get latest version's filename
filename=$(wget -qc "https://golang.org/dl/" -O - | grep -Pom 1 'go1\.\d{0,2}(\.\d{0,2})?\.linux-amd64\.tar\.gz')
# Remove old go version
rm -rf /usr/local/go
# Download and install new version
wget -c "https://dl.google.com/go/$filename" -O - | tar -xz -C /usr/local
@ngoylufo
ngoylufo / queue.js
Last active August 8, 2021 23:52
The simplest version of an optionally typed queue I could muster.
import { is, splice, leftApply, rightApply } from "./misc/utils";
const queue = (obj) => rightApply(leftApply, obj);
const next = (elements) => elements.find((list) => list?.length) ?? [];
export default function Queue(type) {
const wrapped = queue({ type: is(type ?? Object), elements: [] });
return {
@ngoylufo
ngoylufo / globals.js
Last active May 4, 2021 15:39
An interface for parsing keys and mapping them to an object structure, with a few caveats.
const globals = {};
const shouldExtend = (reference, key) =>
Array.isArray(reference[key]) ||
!(reference.hasOwnProperty(key) && typeof reference[key] === "object");
const cleanPath = (array) =>
array.reduce((a, b) => (b !== "global" ? a : [...a, b.trim()]), "");
const set = (key, value) => {
<?php
class Label
{
private $label;
public function __construct(string $label)
{
$this->label = $label;
}
type Vector = [number, number];
/** Returns an array of length 2 representing a vector. */
export const vector = (x: number, y: number): Vector => [x, y];
/** Returns a uniform vector with its elements having the given value. */
export const uniform = (n: number) => vector(n, n);
/** Clones a given vector. */
export const clone = (a: Vector) => vector(a[0], a[1]);
@ngoylufo
ngoylufo / utils.py
Last active May 3, 2020 01:08
A collection of higher order utility functions written in python.
import functools
def identity(func):
return func
def partial(func, *args, **kwargs):
return functools.partial(func, *args, **kwargs)
@ngoylufo
ngoylufo / compose.py
Last active December 14, 2020 13:51
A simple compose function written in python.
import functools
def compose(*fns):
fns = reversed(fns)
def composed(arg):
return functools.reduce(lambda x, fn: fn(x), fns, arg)
return composed
@ngoylufo
ngoylufo / muti-window-app.js
Created April 9, 2020 12:01
A simple multi-window electron (8.2.1) app.
const { app, BroweserWindow } = require('electron');
/* Utilities */
const insert = (array, value, first = false) =>
first ? [value, ...array] : [...array, value];
const expulse = (array, prop, value) => array.filter(e => e[prop] !== value);
const repeat = (fn, n = 1, ...args) => {