Skip to content

Instantly share code, notes, and snippets.

View lionello's full-sized avatar
🇭🇰

Lio李歐 lionello

🇭🇰
View GitHub Profile
@lionello
lionello / stashd.d
Last active August 7, 2022 18:32
Tool to find GIT stashes containing changes to specified file(s)
#!/usr/bin/env rdmd
// Get rdmd from https://dlang.org/download.html (or brew, nix, apt, yum)
// Copyright Lionello Lunesu. Placed in the public Domain.
// https://gist.github.com/lionello/84cad70f835131198fee4ab7e7592fce
import std.stdio : writeln;
int main(string[] args) {
import std.process : pipeProcess, wait, Redirect;
@lionello
lionello / fish_prompt.fish
Last active April 7, 2020 04:48
My FISH prompt (avoids shortened path names, unless too long or in subshells)
# name: Classic + Vcs (custom)
# author: Lily Ballard & Lionello Lunesu
function fish_prompt --description 'Write out the prompt'
set -l last_pipestatus $pipestatus
set -l normal (set_color normal)
# Color the prompt differently when we're root
set -l color_cwd $fish_color_cwd
set -l prefix
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lionello
lionello / mknix.sh
Created November 26, 2018 06:56
Little bash script to generate shell.nix default.nix
#!/usr/bin/env bash
usage () {
echo "Usage: $(basename $0) [--direnv] [--shell] [--default] -p|--packages packages... [--test]"
exit 0
}
error () {
echo "Error: $1"
exit 1
@lionello
lionello / express-async.js
Last active January 5, 2019 03:56
Add support for async middleware and handlers to Express
/**
* Wrap an Express middleware or handler for async support.
* @param {function} fn The middleware or handler to wrap
* @returns {function} Wrapped function
*/
exports.wrap = function(fn) {
if (fn.length === 4) {
// Wrap error handler
return (err, req, res, next) => {
const r = fn(err, req, res, next)
@lionello
lionello / ECMath.sol
Last active June 11, 2023 05:44
ECDSA verification and recovery for curve secp256r1
/*
MIT License
Copyright (c) 2018 Lionello Lunesu
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@lionello
lionello / qr.js
Last active November 10, 2018 01:57
Tiny QR code generator for showing text/urls in the terminal
#!/usr/bin/env node
const QR = require("qr-image");
const arrayOf = (len, filler) => new Array(len).fill(filler);
const text = process.argv[2];
const matrix = QR.matrix(text, "L");
const topBottomPad = arrayOf(4, arrayOf(matrix[0].length, 0));
const rowPad = arrayOf(4, 0);
@lionello
lionello / .direnvrc
Last active August 6, 2019 08:37 — forked from adisbladis/.direnvrc
Direnv nix cache. Put this file in your HOME folder.
#!/bin/bash
#
# Cache nix-shell environment
#
# - watches shell.nix (or default.nix), ~/.direnvrc and .envrc
# - based on https://github.com/direnv/direnv/wiki/Nix
#
use_nix() {
local shell_file=$(test -f shell.nix && echo shell.nix || echo default.nix)
if [[ ! -f "$shell_file" ]]; then return; fi
@lionello
lionello / main.go
Created August 20, 2018 06:20
Graceful shutdown of a Go HTTP server
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
@lionello
lionello / ethereum-test-template.js
Last active July 31, 2018 08:07
Small JS template for writing Ethereum/Solidity tests
/* Use this with an overmind Procfile like this:
geth: geth --dev --rpc console
jest: pnpx jest --watchAll
*/
const ChildProcess = require('child_process')
const Web3 = require('web3')
const Assert = require('assert')
function addressOf(contract) {
return contract.options.address