Other articles


  1. Bash: Imploser une liste

    list_implode () {
        SEPARATOR="$1"; shift
        LIST=( "$@" )
        RESULT="$(printf "${SEPARATOR}%s" "${LIST[@]}")"
        RESULT="${RESULT:${#SEPARATOR}}"
        echo "$RESULT"
    }
    
    LIST=( "foo" "bar" "with space" "fiz" "buz" )
    
    echo "$(list_implode ", " "${LIST[@]}")"
    

    Sortie :

    foo, bar, foo bar, fiz, buz
    
    read more
  2. Bash: Trouver si un élément est dans une liste

    function in_list {
        SEARCH="$1"; shift
        LIST=( "$@" )
        if [ -z "${LIST}" ] || [ -z "${SEARCH}" ]; then
          return 1
        fi
        for ITEM in ${LIST[@]}; do
            if [[ "${ITEM}" == "${SEARCH}" ]]; then
                return 0
            fi
        done
        return 1
    }
    
    LIST=( "foo" "bar" "with space" "fiz" "buz" )
    
    if (in_list "bar" "${LIST[@]}"); then
        echo "bar is in MY_LIST"
    fi
    

    Sortie :

    bar ...
    read more
  3. Un middleware WSGI pour overrider les methodes HTTP

    from webob import Request
    
    class HttpMethodOverrideMiddleware(object):
        """WSGI middleware for overriding HTTP Request Method for RESTful support.
    
        Overriding is authorized only for the HTTP POST method.
        HTML forms can override by providing an additional input.
        Javascript calls can override by providing a specific header.
        """
        def __init__(self, application,
            input_name='REQUEST_METHOD_OVERRIDE ...
    read more

blogroll

social