Skip to content

Instantly share code, notes, and snippets.

Fifan31

Block or report user

Report or block Fifan31

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Fifan31
Fifan31 / git-large-files.sh
Created Jun 1, 2018
Show largest file in git repo
View git-large-files.sh
#!/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
View DottedKeyDict.py
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 Dec 8, 2016
Python - merge 2 lists
View merge_lists.txt
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 Sep 27, 2016
Shell functions intialisation. Put this script in /etc/profile.d/
View function.sh
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:7c9e2fffdb7a71202cfca7a1e3297e32
Created Jun 7, 2016
Utilisation de gdal_cal.py avec le typage des données
View gist:7c9e2fffdb7a71202cfca7a1e3297e32
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 / gist:bbb4f57f2e63fe80b7a10f71c721093f
Created Apr 5, 2016
Convert exception stacktrace to String object
View gist:bbb4f57f2e63fe80b7a10f71c721093f
/**
* 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 / list_targets.sh
Created Feb 3, 2016 — forked from pvdb/list_targets.sh
List all targets (sometimes incorrectly referred to as "goals") in a GNU Makefile
View list_targets.sh
#
# 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
View Redirect stdout and stderr to a logger in Python
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
View xmldiff.py
import lxml.etree as le
from operator import attrgetter
import os
import tempfile
import difflib
def sortbyid(elem):
'''Function to sort XML elements by id
(where the elements have an 'id' attribute that can be cast to an int)
@Fifan31
Fifan31 / source.py
Created Jan 5, 2016 — forked from mammadori/source.py
Python: "source" a shell script and read variables
View source.py
from subprocess import Popen, PIPE
from os import environ
def source(script, update=True, clean=True):
"""
Source variables from a shell script
import them in the environment (if update==True)
and report only the script variables (if clean==True)
"""
You can’t perform that action at this time.