Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View Fifan31's full-sized avatar

AIME Stéphan Fifan31

  • Toulouse, FRANCE
View GitHub Profile
# Configuration file for starship prompt
# see https://starship.rs/
# This file must be copied into ~/.config/starship.toml
# Get editor completions based on the config schema
"$schema" = 'https://starship.rs/config-schema.json'
# Inserts a blank line between shell prompt
add_newline = false
@Fifan31
Fifan31 / decorators.py
Created March 2, 2021 16:19
Some python decorators
import functools
import time
def timer(func):
"""Print the runtime of the decorated function"""
@functools.wraps(func)
def wrapper_timer(*args, **kwargs):
start_time = time.perf_counter() # 1
value = func(*args, **kwargs)
end_time = time.perf_counter() # 2
@Fifan31
Fifan31 / git-large-files.sh
Created June 1, 2018 08:09
Show largest file in git repo
#!/bin/bash
#set -x
# Shows you the largest objects in your repo's pack file.
# Written for osx.
#
# @see https://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
# @author Antony Stubbs
LANG=C
class DottedKeyDict(dict):
def get(self, path, default = None):
keys = path.split(".")
val = None
for key in keys:
if val:
if isinstance(val, list):
val = [ v.get(key, default) if v else None for v in val]
else:
@Fifan31
Fifan31 / merge_lists.txt
Last active December 8, 2016 10:30
Python - merge 2 lists
list1 = ['a', 'c', 'e']
list2 = ['b', 'd', 'f']
list3 = [ item for tmp in zip(list1, list2) for item in tmp]
# list3 = ['a', 'b', 'c', 'd', 'e', 'f']
@Fifan31
Fifan31 / function.sh
Last active September 27, 2016 07:19
Shell functions intialisation. Put this script in /etc/profile.d/
setproxy()
{
proxyhostport="my.proxy.com:portnbr"
authok=0
while [ $authok -eq 0 ] ; do
echo "Setting proxy environment variables:"
echo -n " Username: "
read -e username
echo -n " Password: "
read -es password
@Fifan31
Fifan31 / gist:bbb4f57f2e63fe80b7a10f71c721093f
Created April 5, 2016 12:07
Convert exception stacktrace to String object
/**
* Creates and returns a {@link java.lang.String} from <code>t</code>’s stacktrace
* @param t Throwable whose stack trace is required
* @return String representing the stack trace of the exception
*/
public String getStackTrace(Throwable t) {
StringWriter stringWritter = new StringWriter();
PrintWriter printWritter = new PrintWriter(stringWritter, true);
t.printStackTrace(printWritter);
printWritter.flush();
@Fifan31
Fifan31 / gist:7c9e2fffdb7a71202cfca7a1e3297e32
Created June 7, 2016 12:40
Utilisation de gdal_cal.py avec le typage des données
gdal_calc.py -A IMG.tif -B IMG.tif --B_band=2 --outfile=titi.tif --calc="1.0*((A.astype(float)*A.astype(float))+(B.astype(float)*B.astype(float)))" --type=Float32 --overwrite
@Fifan31
Fifan31 / list_targets.sh
Created February 3, 2016 08:40 — forked from pvdb/list_targets.sh
List all targets (sometimes incorrectly referred to as "goals") in a GNU Makefile
#
# this gist can be used to list all targets, or - more correctly - rules,
# that are defined in a Makefile (and possibly other included Makefiles)
# and is inspired by Jack Kelly's reply to a StackOverflow question:
#
# http://stackoverflow.com/questions/3063507/list-goals-targets-in-gnu-make/3632592#3632592
#
# I also found this script - http://www.shelldorado.com/scripts/cmds/targets - which does
# something similar using awk, but it extracts targets from the "static" rules from a single
# Makefile, meaning it ignores any included Makefiles, as well as targets from "dynamic" rules
import logging
import sys
 
class StreamToLogger(object):
"""
Fake file-like stream object that redirects writes to a logger instance.
"""
def __init__(self, logger, log_level=logging.INFO):
self.logger = logger
self.log_level = log_level