Skip to content

Instantly share code, notes, and snippets.

View loreb's full-sized avatar

Lorenzo Beretta loreb

View GitHub Profile
@loreb
loreb / wtf.txt
Created August 25, 2021 19:01
prompt may be given but -n given
Just in case this happens to somebody else in the future, since search engines were not terribly helpful...
if you run "sudo -n (whatever)" and get back
error: prompt may be needed but -n given
... and search sudo's sources, and the message is not there...
try "type sudo", chances are you're using UserLAnd on Android and they have
nosudo installed as /usr/local/bin/sudo for some reason;
running /usr/bin/sudo does what you wanted.
@loreb
loreb / manpage-compression-worth-it.sh
Created May 17, 2021 15:43
Script to check if it's worth it to compress man pages
#! /bin/sh
# https://paludis.exherbo.org/faq/misfunctionality.html#wgetresume
# true<<TIL => shellcheck usefully complains...
til() { : ; }
til<<TIL
No Automatic Documentation Compression
Non-Problem: Paludis doesn't compress documentation or man pages with gzip/bzip/whatever.
Rationale: The space savings on an average system are very small, to non-existent for most filesystems. Most documentation and man pages are only about one block in size, so compression won't gain you anything except for wasted CPU cycles.
@loreb
loreb / shuf.go
Created March 8, 2016 16:24
GNU shuf in go, out of boredom during a stupid accident
// A reimplementation of GNU shuf (think *BSD)
// -- there was a shuffle(1) ages ago, but it got deleted.
// GNU shuf goes out of its way to optimize anything it can
// -- just see its treatment of --random-source!
// this is *much* more simple minded - TLDR: use GNU shuf.
// Seriously, its inspiration comes from:
// 1. shuf on *BSD without installing coreutils;
// 2. my router abandoning me for >30 minutes.
package main
@loreb
loreb / .Xresources
Created April 8, 2015 19:35
My *horrible* ~/.Xresources, (ab)using cpp to select themes and with every possible idea dumped in (and commented out); I'm switching to something saner (see line 75).
!!!!!!!!!!!!!!!!!!!!!!!!!!
! /etc/X11/app-defaults/ !
!!!!!!!!!!!!!!!!!!!!!!!!!!
xvt*background: #000000
xvt*foreground: #fefefe
yeahconsole*restart: 1
yeahconsole*toggleKey: Alt+y
@loreb
loreb / getarc4random
Created December 17, 2014 20:22
get arc4random*.c from libressl - quick hack
#! /bin/sh
# Self-contained - get arc4random for emergencies.
set -e # Not in "#!" to test different shells.
# TODO figure out the source files automagically?
test 0 -eq $(ls|wc -l) || { echo>&2 "run $0 in an empty directory"; exit 100; }
# Fix $OS if needed (eg "win")
if [ x = x"$OS" ] ; then
OS=$(uname -s)
@loreb
loreb / Spritz.sh
Created December 17, 2014 20:19
abomination: Spritz/RS14 in portable /bin/sh
#! /bin/sh
# "Spritz - a spongy RC4-like stream cipher and hash function"
# http://people.csail.mit.edu/rivest/pubs/RS14.bib.txt
# In case you're insane enough to use it, keep in mind that the registers
# (i,j,...) have NO PREFIX, so you'll have to add it(_spritz_i, ...).
# This script is meant to run on any POSIX shell with local variables
# ("local" is not included in POSIX. Idiots!) and POSIX commands (printf(1)).
# Bash,dash,mksh,zsh: see how fast they Absorb()/Drip() compared to vim...
@loreb
loreb / sane_gnu_info
Created January 18, 2014 14:37
A better reader for GNU info pages that went straight into my ~/bin/, courtesy of robot_t on https://news.ycombinator.com/item?id=7069889 (ps support OpenBSD!)
#! /bin/sh
# This is my ~/bin/info
exec /usr/bin/info "$@" | exec less # linux
exec /usr/local/bin/info "$@" | exec less # *BSD
# References:
# https://news.ycombinator.com/item?id=7072844
# https://news.ycombinator.com/item?id=7075802
# THANK YOU robot_t on ycombinator!!!
@loreb
loreb / dmc_uintmax_max.c
Created October 28, 2013 17:26
If this gets accepted it will be my first time reporting a compiler bug XD (edit: and **if** it can be submitted without a bugzilla account or whatever)
/* Digital Mars bug */
/* From stdint.h:
#define UINTMAX_MAX 18446744073709551615
... except that "number is not representable":
the compiler rejects integer literals bigger than ULONG_MAX,
which is 32 bits on windows XD
*/
#include <stdint.h>
#include <limits.h>
@loreb
loreb / getpeerid()
Created September 22, 2013 16:46
Something I had never thought about, quoted from http://micro.nicholaswilson.me.uk/post/33359696556/cute-little-thought-its-obvious-why-there-arent [foreshortened, Nicholas Wilson] Methinks there should be an errno value for this...
Cute little thought: It’s obvious why there aren’t APIs for finding out, for example, the current credentials of the process on the other end of a UNIX-domain socket (there might be several processes on the end!) Less obviously, there could be no process on the other end: suppose you have a socket at your end, and the remote end is dup’ed into two related processes. You pass in an fd (with an SCM_RIGHTS message), then close it. It’s not open in your process, and it can’t be associated with either receiving process (either one of them could read it first). So, who ever’s on the other end of the passed fd is in the unusal situation of having a valid, connected socket with absolutely no process on the other end! Quirky.
@loreb
loreb / arc4.sh
Created September 22, 2013 16:40
OpenBSD's arc4.c rewritten in striictly POSIX /bin/sh, mostly to survive some **loud** TV show (I'll go to hell for this :) TODO wtf is up with zsh?
#! /bin/sh
# Ispirato dal papa in Sardegna XD
# -- per la cronaca, ha finito prima lui, ma di poco.
#/* $OpenBSD: arc4.c,v 1.3 2007/09/11 12:07:05 djm Exp $ */
#/*
# * Copyright (c) 2003 Markus Friedl <markus@openbsd.org>
# *
# * Permission to use, copy, modify, and distribute this software for any
# * purpose with or without fee is hereby granted, provided that the above
# * copyright notice and this permission notice appear in all copies.