Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View Eddy-Barraud's full-sized avatar

Eddy Barraud Eddy-Barraud

  • IFPEN
  • Paris, France
  • 09:21 (UTC +02:00)
View GitHub Profile
@Eddy-Barraud
Eddy-Barraud / round_on_error.py
Last active October 20, 2023 08:22
A python function to correctly print a value with its error in scientific format and the correct number of significant figures.
# Return the power of ten of a string in scientific notation
# "3.42e3" --> 3
def get_power_of_ten(scientific_notation):
# Split the scientific notation into coefficient and exponent parts
coefficient, exponent = scientific_notation.split('e')
return int(exponent)
# Returns the value with significant figures up to the error position
# Example round_on_error(2.586e-1, 3.304e-2) => 2.6e-01 ± 3.3e-02
def round_on_error(val, err):
#!/bin/bash
#SBATCH --time=10-00:0:0
#SBATCH --ntasks=1
#SBATCH --nodes=1
#SBATCH --cpus-per-task=12
#SBATCH --mem-per-cpu=1024
#SBATCH -J hPSP2
# exit when any command fails
set -e

sudo rm /etc/resolv.conf && sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf' && sudo chattr +i /etc/resolv.conf

If you are experiencing disconnections when you resume your always connected laptop/tab after sleep you can do the following :

Firstly, if you are using Windows 10 Home edition, enable gpedit by visiting this post : trevalim.fr/informatique/gpedit-on-windows-10-home/

After that, go inside Policy Plus and enable this rule System/PowerManagement/SleepOptions/Allow network connectivity during connected standby (battery):

rule

Now you are sure that the device won't disconnect during sleep.

On top of that, you can disable hibernation (after long period of sleep) by enabling the "deactivate hibernation" option and specifying a time of 0sec for the delay.

To enable Gpedit on windows 10 HOME run the following :

Copy this inside a bat file :

@echo off 
pushd "%~dp0" 

dir /b %SystemRoot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~3*.mum >List.txt 
dir /b %SystemRoot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientTools-Package~3*.mum >>List.txt 
@Eddy-Barraud
Eddy-Barraud / zstd-extract.sh
Last active November 22, 2020 10:17
Compress using fast ZSTD and show progress with dialog
#!/bin/bash
filePath=$(wslpath "$1")
fileName=$(basename $filePath)
#cd $filePath/..
( pv -n $fileName | tar xf - -I"zstd -T0" ) 2>&1 | dialog --gauge "Progress..." 6 50

cat $file | tr " " "\n" | sort | uniq -c | sort

$file : Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse accumsan lobortis iaculis. Vestibulum eu condimentum sem. Nunc ut ipsum ipsum. Vestibulum venenatis suscipit ligula vel finibus. Donec dictum eros massa, nec congue justo rutrum et. Donec dictum sagittis dui a mollis. Nullam sed ipsum dapibus, tincidunt turpis a, vestibulum mauris. Cras quis dapibus diam. Donec tempus faucibus odio nec fringilla. Praesent feugiat mi libero, at placerat ante semper quis. Vestibulum id cursus eros.
$cat $file | tr " " "\n" | sort | uniq -c | sort
      1 Cras
      1 Lorem
      1 Suspendisse
[..]
      2 dictum
 2 nec

To expose a port inside a running docker container, you can create a temporary container connected to the same network. We will use socat to link the desired port to another exposed port.

docker run --rm --net some-network -p [exposed-port]:1234 verb/socat TCP-LISTEN:1234,fork TCP-CONNECT:[container-IP]:[container-port]

Then, for example, you can ssh forward this port to your localhost 80 port: ssh -N -L 80:127.0.0.1:[exposed-port] [server-IP]

runas /u:[my account]@outlook.com cmd.exe

This is a registry tweak tip

Windows is hidding a lot of options from the advanced power settings window. You can show options by going inside regedit at : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\PowerSettings Inside this folder there are a lot of subdirectories. Click on each one you want, 44f3beca-a7c0-460e-9df2-bb8b99e0cba6 for Intel Graphics as an example. You will find a