Assignment | |
---|---|
Assign value to variable if variable is not already set, value is returned.Combine with a : no-op to discard/ignore return value . |
${variable="value"} : ${variable="value"} |
This file contains 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 characters
# recursive search for keys containing "string" stripping empty results | |
jq '.. | objects | with_entries(select(.key | contains("ftp"))) | select(. != {})' | |
# same, but output propper array | |
jq '[ .. | objects | with_entries(select(.key | contains("ftp"))) | select(. != {}) ]' | |
# or | |
jq 'map( .. | objects | with_entries(select(.key | contains("ftp"))) | select(. != {}) )' | |
# transform input from {type: a, amount: 1} to {a: 1} and sum all values by type | |
jq '[ .[] | {(.type): .amount} ] | map(to_entries) | add | group_by(.key) | map({key: .[0].key, value: map(.value) | add}) | from_entries' |
This file contains 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 characters
// Groovy map-reduce example | |
// declare a closure | |
def half = { it -> | |
it / 2 | |
} | |
// declare another closure | |
def sum = { result, i -> | |
result + i |
This file contains 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 characters
import java.io.IOException; | |
import java.net.URISyntaxException; | |
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
import java.security.KeyFactory; | |
import java.security.NoSuchAlgorithmException; | |
import java.security.PrivateKey; | |
import java.security.interfaces.RSAPublicKey; | |
import java.security.spec.InvalidKeySpecException; | |
import java.security.spec.PKCS8EncodedKeySpec; |
This file contains 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 characters
def lazy = { {w->w<<it()}.asWritable() } | |
def x = "it is now ${System.currentTimeMillis()}" | |
def y = "it is now ${{it->it<<System.currentTimeMillis()}.asWritable()}" | |
def z = "it is now ${lazy{System.currentTimeMillis()}}" | |
// change to x,y,z - x prints the same number all 5 times | |
(1..5).each { println z; sleep 250 } |
This file contains 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 characters
#!/bin/sh | |
# | |
# a simple way to parse shell script arguments | |
# | |
# please edit and use to your hearts content | |
# | |
ENVIRONMENT="dev" |