Skip to content

Instantly share code, notes, and snippets.

View chb0github's full-sized avatar

Christian Bongiorno chb0github

View GitHub Profile
@pedroxs
pedroxs / jq-filters.sh
Last active January 22, 2024 13:02
jq - recursive search for keys containing "string" stripping empty results
# 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'
// Groovy map-reduce example
// declare a closure
def half = { it ->
it / 2
}
// declare another closure
def sum = { result, i ->
result + i
@destan
destan / ParseRSAKeys.java
Last active March 29, 2024 10:43
Parse RSA public and private key pair from string in Java
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;
@magnetikonline
magnetikonline / README.md
Last active March 16, 2024 02:00
Bash string manipulation cheatsheet.

Bash string manipulation cheatsheet

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"}
@krsmes
krsmes / gist:1029712
Created June 16, 2011 17:11
lazy evaluation of blocks in a groovy string
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 }
@jehiah
jehiah / simple_args_parsing.sh
Created March 4, 2011 16:56
a simple way to parse shell script arguments
#!/bin/sh
#
# a simple way to parse shell script arguments
#
# please edit and use to your hearts content
#
ENVIRONMENT="dev"