Skip to content

Instantly share code, notes, and snippets.

@e7d
e7d / parseDSV.js
Created August 12, 2014 10:05
[JavaScript] Parse delimiter-separated values (CSV, TSV...)
// Comma-separated values to JSON
function parseCSV(data) {
return parseDSV(data, ",");
}
// Tabulation-separated values to JSON
function parseTSV(data) {
return parseDSV(data, "\t");
}
@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
@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 / 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 / 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

### 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 / 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 / tailn.bashrc
Created June 16, 2017 08:28
Tail with proper line breaks in log file
# Tail with proper line breaks in log files
function tail_linebreak() {
tail $@ | sed "s/\\\n/\\n/g"
}
alias tailn=tail_linebreak
@e7d
e7d / custom.css
Last active August 16, 2017 10:13
Visual Studio Code Personalizations (CSS and JS)
/**
* @author Michaël "e7d" Ferrand
* @description custom style for Visual Studio Code
* @see https://gist.githubusercontent.com/e7d/34cf097cd1fc3a7bbb7300b8fcd70d1c
*/
/***** RESOURCES *****/
@font-face {
font-family: 'Font Awesome';