Skip to content

Instantly share code, notes, and snippets.

View Resethel's full-sized avatar
🙂

Raphaël Ollando Resethel

🙂
  • SnT, University of Luxembourg
  • Luxembourg
View GitHub Profile
@Resethel
Resethel / str_enum.py
Last active August 17, 2022 12:58
[StrEnum] Re-implementation of StrEnum for imports in python 3.8.6+ version #Python #Python3.8
"""
Re-implementation of StrEnum for imports in python 3.8.6+ version
From https://github.com/clbarnes/backports.strenum/blob/main/backports/strenum/strenum.py
"""
from enum import Enum
class StrEnum(str, Enum):
"""
@Resethel
Resethel / fastCopy.java
Created June 29, 2021 13:48
[Java Fast Copy using NIO] Use NIO to fast copy files with java. #java #file #copy #NIO #Windows
/**
* Perform a faster file copy under windows of a file, has the piece of code
* {@code inChannel.transferTo(0, inChannel.size(), outChannel);} seems to
* struggle.
* @param in the source file object
* @param out the destination file object
*/
public static void fastCopy(File in, File out) throws IOException
{
FileChannel inChannel = new FileInputStream(in).getChannel();
@Resethel
Resethel / Pair.java
Last active June 28, 2021 07:29
[Pair of object] A convenience class to represent pairs #java #pairs
import java.text.MessageFormat;
import java.util.Objects;
/**
* A convenience class to represent pairs (tuples of 2 values)
* @param <T> the type to be used by the pair
*/
public class Pair<T>
{
// ===== ( Members ) ================================================================================================
@Resethel
Resethel / get_pid_by_name.py
Last active June 2, 2021 14:46
[Search PID by name] Search the PID of a program by name and returns a list of the PID. #python3 #unix
def get_pid_by_name(name: str):
"""
Search the PID of by name of the program
return: a generator with the list of pids
"""
processes = subprocess.check_output(["ps", "-fea"]).decode(sys.stdout.encoding).split('\n')
for p in processes:
args = p.split()
for part in args:
if name in part:
@Resethel
Resethel / Search_dict_element_with_keys.py
Last active March 25, 2020 09:13
[Recursive dict element search] Recursively search for a dictionnary element under the given keys. #python #recursive #search #dictionnary
def search_dict_element_with_keys(dictionnary, *keys):
"""Recursively search for a dictionnary for the dict[n0][n1][...][n(k-1)][nk] element."""
dict_value = dictionnary.get(keys[0], None)
# If the sub element is a dictionnary key and there are still keys to iterate through
if isinstance(dict_value, dict) and len(keys) > 1:
return get_dict_element_at(dict_value, *keys[1:])
# elif the value is not a dictionnary but there are still keys to iterate through, that means that we reached a dead end
elif dict_value is not None and len(keys) > 1:
@Resethel
Resethel / mv.bat
Created November 8, 2019 14:45
[Copy file with extension from a folder to another] Copying a batch of file recursively from a folder to another under windows
for /R c:\source %%f in (*.xml) do copy %%f x:\destination\
@Resethel
Resethel / sensor_filter.py
Last active October 10, 2019 13:58
[Filters Python] Set of filters for sensor acquisition in Python #python #sensor #sensoracquisition
# SMA:
n = 10
array_meanA = array('f', [])
for h in range(n):
array_meanA.append(14.0) # Initialise the array with 10 values of '14'.
for x in range(n):
getSensorData() # Get some data.eg tempPiFloat
array_meanA[n] = tempPiFloat # tempPiFloat slots into end of array.
for h in range(n):
array_meanA[h] = array_meanA[(h+1)] # Shift the values in the array to the left
@Resethel
Resethel / config.py
Last active January 30, 2020 10:16
[Python configuration module] Definition of a python module that load a configuration file and makes it available to any other modules. #python3 #module #configuration
#!/usr/bin/env python3
# Loads and manage configuration
"""A module that manage a configuration file and makes it accessible to any other modules."""
import configparser
import logging
import os.path
class Config:

Introduction

  • C-a == Ctrl-a
  • M-a == Alt-a

General

:q        close
:w        write/saves
:wa[!]    write/save all windows [force]
:wq       write/save and close
@Resethel
Resethel / git_cheat_sheet.md
Last active August 5, 2019 14:35 — forked from akras14/Getting-Cheat-Sheet.md
[GIT cheatsheet] A git cheatsheet by alexkras

Git Cheat Sheet

Commands

Getting Started

git init

or

git clone url