Skip to content

Instantly share code, notes, and snippets.

View glegoux's full-sized avatar
💻

Gilles Legoux glegoux

💻
View GitHub Profile
@glegoux
glegoux / screen-physical-size.py
Created June 13, 2018 19:50
[Python] Get screen physical size
#!/usr/bin/env python3
import subprocess
r = 1
screens = [l.split() for l in
subprocess.check_output(["xrandr"]).decode("utf-8").strip().splitlines()
if " connected" in l]
@glegoux
glegoux / httpserver.bash
Last active June 12, 2018 16:55
[Bash,Python] Python HTTP server on particular internet address and port
#!/usr/bin/env bash
#
# httpserver.bash
#
# usage: bash httpserver.bash [IP_ADDRESS] [PORT]
# By default it serves HTTP on 127.0.0.1 port 8000.
#
# A HTTP server is based on TCP protocol.
# You can run only one service on the same port and same network interface.
# But you can run 2 HTTP Servers on the same port for 2 different network
@glegoux
glegoux / tab_title.bash
Last active May 22, 2018 11:48
[Bash] Set the title of your terminal tab
#!/usr/bin/env bash
# Set the title of your terminal tab
title="$1"
echo -n -e "\033]0;${title}\007"
@glegoux
glegoux / os-resources.bash
Last active May 22, 2018 11:46
[Bash] Know operating system and resources on a computer running on GNU/Linux
#!/usr/bin/env bash
#
# Know operating system and resources on a computer running on GNU/Linux
echo "* kernel version"
uname -srov
echo "* distribution version"
cat /etc/os-release
echo "* hardware platform version"
uname -mi
@glegoux
glegoux / get-current-shell.sh
Last active May 22, 2018 11:46
[Sh] Get current shell in session result: sh (or dash), bash, zsh, ksh, tcsh, fish
#!/usr/bin/env sh
#
# You can see all available shell with cat /ect/shell .
# The Linux available shells are: sh (or dash), bash, zsh, ksh, tcsh, fish
ps -p $$ --no-headers -o cmd
# or ps | grep -E "^$$" | awk '{print $NF}'
@glegoux
glegoux / udpclient.py
Last active April 20, 2018 04:34
[Python] Run UDP client for UDP socket server
#!/usr/bin/env python3
#
# udpclient.py
#
# Required that UDP server runs on 127.0.0.1 port 8000.
# See Gist udpserver.py.
#
# Send UDP message to UDP server.
#
# usage: python3 udpclient.py
@glegoux
glegoux / udpserver.py
Last active April 20, 2018 04:32
[Pyhton] Run UDP server via socket server
#!/usr/bin/env python3
#
# udpserver.py
#
# See Gist udpclient.py to send a UDP message.
#
# Run UDP server on 127.0.0.1 port 8000.
#
# usage: python3 udpserver.py
@glegoux
glegoux / setup-ssh-key.md
Last active September 11, 2017 23:49
SSH key authentication for GitHub repository

1) Generate your pair of SSH keys:

ssh-keygen -t rsa -b 4096 -C "<email>@example.com"

Add a passphrase is better. Here your pair of keys:

  • private key: without extension (keep that secret only for you)
  • public key : with extension .pub (for everybody)
@glegoux
glegoux / compress-img.bash
Last active August 30, 2017 07:37
[Bash] Reduce images to send a batch of images by email for example
#!/usr/bin/env bash
#
# compress-img.bash
#
# Reduce size by 50% for each given image by copying that in
# a new folder ./compressed.
#
# You can reduce size or quality of each image, if you don't want,
# send a link to application where there are your images. And this
# script is usless for your use case.
@glegoux
glegoux / pdf-to-booklet.bash
Last active August 25, 2017 07:34
[Bash] Convert document pdf with A4 format as a booklet with A5 format
#!/usr/bin/env bash
#
# pdf-to-booklet.bash
#
# Convert document pdf with A4 format as a booklet with A5 format.
# A output/ folder will be created in the current directory containing:
# - input.pdf : original modified pdf document (with blank pages, to have a
# number of pages which is a multiple of 4).
# - output.pdf : booklet
#