Last active
          March 27, 2018 04:23 
        
      - 
      
 - 
        
Save iintothewind/c845ac6fbf40becaf4e3e577fb4d8150 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
Ivar Chen revised this gist
Mar 27, 2018 . 1 changed file with 16 additions and 27 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ #!/usr/bin/env bash export REQ_BASE="" export REQ_USER="" export REQ_PWD="" export REQ_METHOD="" function cf_lower() { echo "${1:-`cat`}" | tr '[:upper:]' '[:lower:]' @@ -12,23 +12,23 @@ function cf_upper() { echo "${1:-`cat`}" | tr '[:lower:]' '[:upper:]' } function cf_starts_with() { local str=$1 local pre=$2 [[ "$str" == ${pre}* ]] } function cf_compose_url() { local inputUrl=$1 local baseUrl=$2 if test $inputUrl && (cf_starts_with $inputUrl $baseUrl || [[ $inputUrl =~ http.?://.+ ]]); then echo $inputUrl else echo "$baseUrl$inputUrl" fi } # used after a pipe, for example: echo '{ "k": "v"}' | cf_jsonfmt function cf_jsonfmt() { if type python > /dev/null 2>&1; then python -mjson.tool @@ -48,36 +48,26 @@ function cf_req() { local u;local p;local l;local m;local d; while getopts ":u:p:l:m:d:" o; do case "${o}" in u) u=${OPTARG} ;; p) p=${OPTARG} ;; l) l=${OPTARG} ;; m) m=${OPTARG} ;; d) d=${OPTARG} ;; esac done if type curl > /dev/null 2>&1; then if (test $u || test $REQ_USER) && (test $p || test $REQ_PWD); then echo $(curl -k -s -u ${u:-$REQ_USER}:${p:-$REQ_PWD} -X `cf_upper ${m:-$REQ_METHOD}` -H "Accept: application/json" -H "Content-Type: application/json" $(cf_compose_url $l $REQ_BASE) -d @<(if test "GET" = `cf_upper ${m:-$REQ_METHOD}` || test "DELETE" = `cf_upper ${m:-$REQ_METHOD}`; then echo ""; else echo ${d:-`cat`}; fi)) else echo $(curl -k -s -X `cf_upper ${m:-$REQ_METHOD}` -H "Accept: application/json" -H "Content-Type: application/json" $(cf_compose_url $l $REQ_BASE) -d @<(if test "GET" = `cf_upper ${m:-$REQ_METHOD}` || test "DELETE" = `cf_upper ${m:-$REQ_METHOD}`; then echo ""; else echo ${d:-`cat`}; fi)) fi else echo "curl is not found in PATH" return 1 fi } # cf_req -d '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }'| cf_parse '["data"][0][0]["all_relationships"]' # $1 the key # $2 json string or read stdin from cat function cf_parse() { @@ -94,4 +84,3 @@ EOF return 1 fi }  - 
        
Ivar Chen revised this gist
Mar 24, 2018 . No changes.There are no files selected for viewing
 - 
        
Ivar Chen renamed this gist
Mar 24, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -67,9 +67,9 @@ function cf_req() { done if type curl > /dev/null 2>&1; then if (test $u || test $REQ_USER) && (test $p || test $REQ_PWD); then echo $(curl -k -s -u ${u:-$(echo $REQ_USER)}:${p:-$(echo $REQ_PWD)} -X `cf_upper ${m:-$(echo $REQ_METHOD)}` -H "Accept: application/json" -H "Content-Type: application/json" $(cf_composeUrl $l $REQ_BASE) -d @<(if test "GET" = `cf_upper ${m:-$(echo $REQ_METHOD)}` && "DELETE" = `cf_upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi)) else echo $(curl -k -s -X `cf_upper ${m:-$(echo $REQ_METHOD)}` -H "Accept: application/json" -H "Content-Type: application/json" $(cf_composeUrl $l $REQ_BASE) -d @<(if test "GET" = `cf_upper ${m:-$(echo $REQ_METHOD)}` && "DELETE" = `cf_upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi)) fi else echo "curl is not found in PATH"  - 
        
Ivar Chen revised this gist
Mar 24, 2018 . No changes.There are no files selected for viewing
 - 
        
Ivar Chen revised this gist
Mar 24, 2018 . 1 changed file with 21 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,40 +4,46 @@ export REQ_USER="neo4j" export REQ_PWD="admin" export REQ_METHOD="POST" function cf_lower() { echo "${1:-`cat`}" | tr '[:upper:]' '[:lower:]' } function cf_upper() { echo "${1:-`cat`}" | tr '[:lower:]' '[:upper:]' } function cf_startsWith() { local str=$1 local pre=$2 [[ "$str" == ${pre}* ]] } function cf_composeUrl() { local inputUrl=$1 local baseUrl=$2 if test $inputUrl && (cf_startsWith $inputUrl $baseUrl || cf_startsWith $inputUrl "http://"); then echo $inputUrl else echo "$baseUrl$inputUrl" fi } # used after a pipe, cat '{ "k": "v"}' | jsonfmt function cf_jsonfmt() { if type python > /dev/null 2>&1; then python -mjson.tool else echo "python is not found in PATH" return 1 fi } # -u : user name, default value: $REQ_USER # -p : password, default value: $REQ_PWD # -l : request url, it can be full url (startsWith http://baseurl.com) or sub-path (/data/resource), default value: $REQ_BASE # -m : request method, default value: $REQ_METHOD # -d : request body, defaut read from stdin by cat function cf_req() { local OPTIND=1 local u;local p;local l;local m;local d; while getopts ":u:p:l:m:d:" o; do @@ -61,20 +67,20 @@ function req() { done if type curl > /dev/null 2>&1; then if (test $u || test $REQ_USER) && (test $p || test $REQ_PWD); then echo $(curl -k -s -u ${u:-$(echo $REQ_USER)}:${p:-$(echo $REQ_PWD)} -X `cf_upper ${m:-$(echo $REQ_METHOD)}` -H "Accept: application/json" -H "Content-Type: application/json" $(cf_composeUrl $l $REQ_BASE) -d @<(if test "GET" = `cf_upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi)) else echo $(curl -k -s -X `cf_upper ${m:-$(echo $REQ_METHOD)}` -H "Accept: application/json" -H "Content-Type: application/json" $(cf_composeUrl $l $REQ_BASE) -d @<(if test "GET" = `cf_upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi)) fi else echo "curl is not found in PATH" return 1 fi } # req -d '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }'| parse '["data"][0][0]["all_relationships"]' # $1 the key # $2 json string or read stdin from cat function cf_parse() { if type python > /dev/null 2>&1; then python <<EOF import json @@ -84,7 +90,7 @@ except Exception as e: print("error: {}".format(e)) EOF else echo "python is not found in PATH" return 1 fi }  - 
        
Ivar Chen revised this gist
Mar 24, 2018 . 1 changed file with 26 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ export REQ_BASE="http://localhost:7474/db/data/cypher" export REQ_USER="neo4j" export REQ_PWD="admin" export REQ_METHOD="POST" function lower() { echo "${1:-`cat`}" | tr '[:upper:]' '[:lower:]' @@ -36,18 +37,33 @@ function jsonfmt() { fi } function req() { local OPTIND=1 local u;local p;local l;local m;local d; while getopts ":u:p:l:m:d:" o; do case "${o}" in u) u=${OPTARG} ;; p) p=${OPTARG} ;; l) l=${OPTARG} ;; m) m=${OPTARG} ;; d) d=${OPTARG} ;; esac done if type curl > /dev/null 2>&1; then if (test $u || test $REQ_USER) && (test $p || test $REQ_PWD); then echo $(curl -k -s -u ${u:-$(echo $REQ_USER)}:${p:-$(echo $REQ_PWD)} -X `upper ${m:-$(echo $REQ_METHOD)}` -H Accept:application/json -H Content-Type: application/json $(composeUrl $l $REQ_BASE) -d @<(if test "GET" = `upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi)) else echo $(curl -k -s -X `upper ${m:-$(echo $REQ_METHOD)}` -H Accept:application/json -H Content-Type: application/json $(composeUrl $l $REQ_BASE) -d @<(if test "GET" = `upper ${m:-$(echo $REQ_METHOD)}`; then echo ""; else echo ${d:-`cat`}; fi)) fi else echo "curl is nof found in PATH" @@ -73,4 +89,3 @@ EOF fi }  - 
        
Ivar Chen revised this gist
Mar 23, 2018 . 1 changed file with 22 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ #!/usr/bin/env bash export REQ_BASE="http://localhost:7474/db/data/cypher" export REQ_USER="neo4j" export REQ_PWD="admin" @@ -11,6 +11,22 @@ function upper() { echo "${1:-`cat`}" | tr '[:lower:]' '[:upper:]' } function startsWith() { local str=$1 local pre=$2 [[ "$str" == ${pre}* ]] } function composeUrl() { local inputUrl=$1 local baseUrl=$2 if test $inputUrl && startsWith $inputUrl $baseUrl; then echo $inputUrl else echo "$baseUrl$inputUrl" fi } function jsonfmt() { if type python > /dev/null 2>&1; then python -mjson.tool @@ -28,7 +44,11 @@ function jsonfmt() { #$4 REQ_PWD function post() { if type curl > /dev/null 2>&1; then if (test $3 || test $REQ_USER) && (test $4 || test $REQ_PWD); then echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X POST -H Accept:application/json -H Content-Type: application/json ${2:-$(composeUrl $2 $REQ_BASE)} -d @<(echo ${1:-`cat`})) else echo $(curl -s -X POST -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo ${1:-`cat`})) fi else echo "curl is nof found in PATH" return 1  - 
        
Ivar Chen revised this gist
Mar 22, 2018 . No changes.There are no files selected for viewing
 - 
        
Ivar Chen revised this gist
Mar 22, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,7 +28,7 @@ function jsonfmt() { #$4 REQ_PWD function post() { if type curl > /dev/null 2>&1; then echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X POST -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo ${1:-`cat`})) else echo "curl is nof found in PATH" return 1  - 
        
Ivar Chen revised this gist
Mar 22, 2018 . 1 changed file with 9 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,12 @@ function upper() { } function jsonfmt() { if type python > /dev/null 2>&1; then python -mjson.tool else echo "python is nof found in PATH" return 1 fi } @@ -25,6 +30,7 @@ function post() { if type curl > /dev/null 2>&1; then echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X POST -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo $1)) else echo "curl is nof found in PATH" return 1 fi } @@ -33,7 +39,7 @@ function post() { # $1 the key # $2 json string or cat function parse() { if type python > /dev/null 2>&1; then python <<EOF import json try: @@ -42,6 +48,7 @@ except Exception as e: print("error: {}".format(e)) EOF else echo "python is nof found in PATH" return 1 fi }  - 
        
Ivar Chen revised this gist
Mar 22, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,11 +4,11 @@ export REQ_USER="neo4j" export REQ_PWD="admin" function lower() { echo "${1:-`cat`}" | tr '[:upper:]' '[:lower:]' } function upper() { echo "${1:-`cat`}" | tr '[:lower:]' '[:upper:]' } function jsonfmt() {  - 
        
Ivar Chen revised this gist
Mar 22, 2018 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,8 @@ function jsonfmt() { } # post '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }' #$1 body, json string #$2 REQ_URL #$3 REQ_USER #$4 REQ_PWD  - 
        
Ivar Chen revised this gist
Mar 22, 2018 . 1 changed file with 4 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,7 @@ #!/usr/bin/env bash export REQ_URL="http://localhost:7474/db/data/cypher" export REQ_USER="neo4j" export REQ_PWD="admin" function lower() { echo "$1" | tr '[:upper:]' '[:lower:]' @@ -22,19 +20,18 @@ function jsonfmt() { #$2 REQ_URL #$3 REQ_USER #$4 REQ_PWD function post() { if type curl > /dev/null 2>&1; then echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X POST -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo $1)) else return 1 fi } # post '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }'| parse '["data"][0][0]["all_relationships"]' # $1 the key # $2 json string or cat function parse() { if type curl > /dev/null 2>&1; then python <<EOF import json  - 
        
Ivar Chen revised this gist
Mar 22, 2018 . 1 changed file with 17 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,6 +17,7 @@ function jsonfmt() { python -mjson.tool } #$1 json body #$2 REQ_URL #$3 REQ_USER @@ -25,12 +26,26 @@ function jsonfmt() { function req() { if type curl > /dev/null 2>&1; then echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X `upper ${5:-$(echo $REQ_DEFAULT_METHOD)}` -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo $1)) else return 1 fi } # req '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }'| get '["data"][0][0]["all_relationships"]' # $1 the key # $2 json string or cat function get() { if type curl > /dev/null 2>&1; then python <<EOF import json try: print(json.loads('''${2:-`cat`}''')${1:-""}) except Exception as e: print("error: {}".format(e)) EOF else return 1 fi }  - 
        
Ivar Chen revised this gist
Mar 21, 2018 . 1 changed file with 5 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,4 @@ #!/usr/bin/env bash export REQ_ERR_MSG="" export REQ_URL="http://localhost:7474/db/data/cypher" export REQ_USER="neo4j" @@ -36,7 +26,11 @@ function req() { if type curl > /dev/null 2>&1; then echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X `upper ${5:-$(echo $REQ_DEFAULT_METHOD)}` -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo $1)) return 0 else return 1 fi }  - 
        
Ivar Chen revised this gist
Mar 21, 2018 . 1 changed file with 21 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,22 +9,34 @@ function body() { echo '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }' } export REQ_ERR_MSG="" export REQ_URL="http://localhost:7474/db/data/cypher" export REQ_USER="neo4j" export REQ_PWD="admin" export REQ_DEFAULT_METHOD="POST" function lower() { echo "$1" | tr '[:upper:]' '[:lower:]' } function upper() { echo "$1" | tr '[:lower:]' '[:upper:]' } function jsonfmt() { python -mjson.tool } #$1 json body #$2 REQ_URL #$3 REQ_USER #$4 REQ_PWD #$5 REQ_METHOD function req() { if type curl > /dev/null 2>&1; then echo $(curl -s -u ${3:-$(echo $REQ_USER)}:${4:-$(echo $REQ_PWD)} -X `upper ${5:-$(echo $REQ_DEFAULT_METHOD)}` -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $REQ_URL)} -d @<(echo $1)) return 0 fi return 1 }  - 
        
Ivar Chen revised this gist
Mar 20, 2018 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ ERROR_MSG="" export NEO4J_URL="http://localhost:7474/db/data/cypher" export NEO4J_USER="neo4j" export NEO4J_PWD="admin" function body() { echo '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }' @@ -19,13 +19,12 @@ quote () { } function query() { if type curl > /dev/null 2>&1; then echo $(curl -s -u ${3:-$(echo $NEO4J_USER)}:${4:-$(echo $NEO4J_PWD)} -X POST -H Accept:application/json -H Content-Type: application/json ${2:-$(echo $NEO4J_URL)} -d @<(echo $1)) return 0 fi return 1 }  - 
        
Ivar Chen created this gist
Mar 20, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ #!/usr/bin/env bash ERROR_MSG="" export NEO4J_URL="http://localhost:7474/db/data/cypher" export NEO4J_USER="neo4j" export NEO4J_PASSWD="admin" function body() { echo '{ "query" : "MATCH (ee:Person) WHERE ee.name = \"Emil\" RETURN ee;", "params" : {} }' } function jsonfmt() { python -mjson.tool } quote () { local quoted=${1//\"/\"\\\"\"}; printf "'%s'" "$quoted" } function query() { if type curl > /dev/null 2>&1 && $# == 4; then echo $(curl -s -u $2:$3 -X POST -H Accept:application/json -H Content-Type: application/json $1 -d @<(echo $4)) return 0 fi return 1 }