Skip to content

Instantly share code, notes, and snippets.

View glegoux's full-sized avatar
💻

Gilles Legoux glegoux

💻
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / impot.py
Last active June 13, 2018 19:57
[Python] Compute french taxes in euro
#!/usr/bin/env python3
#
# Compute french taxes in euro.
#
# usage:
# python3 impot.py <yearly_gross_salary>
TAXE_SLICES = [(9710, 0.14), (26818, 0.30), (71898, 0.41), (152260, 0.45)]
def get_taxe_amounts_per_slice():
@glegoux
glegoux / img-to-b64.sh
Last active June 25, 2018 21:53
[Bash] Convert image PNG to base 64 and copy
#!/usr/bin/env bash
cd $(dirname "$0")
img_file="$1"
# data:image/png;base64,<content base 64>
# data:image/svg+xml;base64,<content base 64>
base64 -w 0 "${img_file}" | xclip -selection c
@glegoux
glegoux / b64-to-img.sh
Last active June 25, 2018 21:55
[Bash] Convert base 64 to image PNG and create image file
#!/usr/bin/env bash
cd $(dirname "$0")
file_b64="$1"
image_file="${2:-image.png}"
cat "${file_b64}" | base64 -d > "${image_file}"