Skip to content

Instantly share code, notes, and snippets.

Avatar
🇭🇰

Lio李歐 lionello

🇭🇰
View GitHub Profile
View .bash_profile
if [ "$(uname -s)" != "Linux" ] && [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
source ~/.profile
PATH=/usr/local/sbin:$PATH
function __smile() { if [ $? -ne 0 ]; then echo ":("; else echo ":)"; fi }
GIT_PS1_SHOWDIRTYSTATE=true
PS1="\n\$(__smile)\[\e[1m\]\w\[\e[0m\]\$(__git_ps1)\n\$ "
@lionello
lionello / stashd.d
Last active May 11, 2021
Tool to find GIT stashes containing changes to specified file(s)
View stashd.d
#!/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 Apr 7, 2020
My FISH prompt (avoids shortened path names, unless too long or in subshells)
View fish_prompt.fish
# 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
View Coul_Buck.ipynb
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 Nov 26, 2018
Little bash script to generate shell.nix default.nix
View mknix.sh
#!/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 Jan 5, 2019
Add support for async middleware and handlers to Express
View express-async.js
/**
* 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 Jun 18, 2019
ECDSA verification and recovery for curve secp256r1
View ECMath.sol
/*
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 Nov 10, 2018
Tiny QR code generator for showing text/urls in the terminal
View qr.js
#!/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 Aug 6, 2019 — forked from adisbladis/.direnvrc
Direnv nix cache. Put this file in your HOME folder.
View .direnvrc
#!/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 Aug 20, 2018
Graceful shutdown of a Go HTTP server
View main.go
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"