Skip to content

Instantly share code, notes, and snippets.

@e7d
e7d / gen-self-cert.sh
Last active May 18, 2021 13:40
Generate self-signed certificate with OpenSSL
#!/bin/bash
# read input
domain=$1
if [ -z $domain ]; then
read -p "domain: " domain
fi
rsa=$2
if [ -z $rsa ]; then
rsa=2048 # 2048 bits by default
### Keybase proof
I hereby claim:
* I am e7d on github.
* I am e7d (https://keybase.io/e7d) on keybase.
* I have a public key whose fingerprint is 6324 5E8E 75A6 2FA4 17C2 81D3 F320 BE00 7C0B 8881
To claim this, I am signing this object:
@e7d
e7d / README.md
Last active March 23, 2022 22:40
[Debian] Setup a Squid anonymous proxy
@e7d
e7d / humanFileSize.js
Last active April 11, 2017 15:30
Human readable file size, extending Number type prototype
Object.defineProperty(Number.prototype, 'fileSize', {
value: function humanFileSize(si = false) {
const divider = si ? 1e3 : 1024;
const i = Math.floor(Math.log(this) / Math.log(divider));
const fileSize =
(this / Math.pow(divider, i)).toFixed(2) +
' ' + ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'][i] +
(si ? 'i' : '');
return fileSize.toString();
},
@e7d
e7d / README.md
Last active February 6, 2017 15:33
Chroot SFTP users

Introduction

What we want is to allow John to connect through sftp only (no bash, no terminal) and to be limited to a set of folders.

In this example, we'll consider an existing user john, whose home directory is /home/john. You'll have to adapt the different commands to your specific case.

User preparation

We need our user to customized a bit. First of all the, its home directory must be owned by root: chown -c root:root /home/john

@e7d
e7d / sample.sh
Last active December 10, 2023 10:45
Bash "try catch"
#!/bin/bash
export AnException=100
export AnotherException=101
# start with a try
try
( # open a subshell !!!
echo "do something"
[ someErrorCondition ] && throw $AnException
@e7d
e7d / run.sh
Last active August 5, 2016 16:22
#!/bin/sh
run() {
echo -en "# "
($@ 2>&1; echo $?>~/_$$) | log
V=$(($(cat ~/_L$$;rm -f ~/_L$$) / $(tput cols)))
if test 0 -eq $(cat ~/_$$;rm -f ~/_$$); then
echo -e "\r\033["$V"A\033[1;32m✓\033[0m\r\033["$V"B"
else
echo -e "\r\033["$V"A\033[1;31m✕\033[0m\r\033["$V"B"
@e7d
e7d / cryptURI.js
Created July 9, 2015 09:20
Crypt URI with JavaScript
(function() {
String.prototype.asciiEncode = function() {
var i, result = [];
for (i = 0; i < this.length; i++) {
result.push("%", this.charCodeAt(i).toString(16));
}
return result.join('');
}
@e7d
e7d / README.md
Last active October 7, 2015 09:10
Setup an APT environment for all repositories

Automated install

Disclaimer

Read the install script before using it.
You may want to understand what the script is doing before executing it.
I will not be responsible for any damage caused to your server.

Installation script

@e7d
e7d / remove-old-kernels.sh
Last active August 29, 2015 14:23
Remove all unused kernels on Debian-based systems
#!/bin/sh
sudo apt-get remove $(dpkg -l|egrep '^ii linux-(im|he)'|awk '{print $2}'|grep -v `uname -r`)
update-grub