Skip to content

Instantly share code, notes, and snippets.

@Rudge
Rudge / kotlin-helper.README
Last active December 30, 2018 23:41
kotlin - standard lib helper
╔══════════╦═════════════════╦═══════════════╦═══════════════╗
║ Function ║ Receiver (this) ║ Argument (it) ║ Result ║
╠══════════╬═════════════════╬═══════════════╬═══════════════╣
║ let ║ this@MyClass ║ String("...") ║ Int(42) ║
║ run ║ String("...") ║ N\A ║ Int(42) ║
║ run* ║ this@MyClass ║ N\A ║ Int(42) ║
║ with* ║ String("...") ║ N\A ║ Int(42) ║
║ apply ║ String("...") ║ N\A ║ String("...") ║
║ also ║ this@MyClass ║ String("...") ║ String("...") ║
╚══════════╩═════════════════╩═══════════════╩═══════════════╝
@Rudge
Rudge / gist:4ea34d7e443f56595b337179b2770eb8
Created February 16, 2018 21:52
Regex conditional address and different ports
^http(s)?://(.+\.)?(localhost(?::\d{1,50000})?|projeto-(\d{1,99}).homolog.infra(?::?\d{1,50000})?|127\.0\.0\.1(?::\d{1,50000})?)$
@Rudge
Rudge / Logstash conf for nginx log
Last active October 26, 2017 21:28
Logstash conf for nginx log
cat /etc/logstash/conf.d/20-nginx-filter.conf
filter {
if [syslog_program] == "nginx-access" {
grok {
match => [ "message" , "%{COMBINEDAPACHELOG}+%{GREEDYDATA:extra_fields}"]
overwrite => [ "message" ]
add_tag => [ "nginx_access" ]
}
grok {
match => [ "message" , "(?<timestamp>%{YEAR}[./-]%{MONTHNUM}[./-]%{MONTHDAY}[- ]%{TIME}) \[%{LOGLEVEL:severity}\] %{POSINT:pid}#%{NUMBER}: %{GREEDYDATA:errormessage}(?:, client: (?<client>%{IP}|%{HOSTNAME}))(?:, server: %{IPORHOST:server})(?:, request: %{QS:request})?(?:, upstream: \"%{URI:upstream}\")?(?:, host: %{QS:host})?(?:, referrer: \"%{URI:referrer}\")"]
@Rudge
Rudge / Syslog file with nginx - ELK server.
Last active November 9, 2022 06:49
Syslog file with nginx config to send for ELK server.
cat /etc/rsyslog.d/nginx.conf
$ModLoad imfile
# Default Apache Error Log
$InputFileName /var/log/nginx/error.log
$InputFileTag nginx-error-default:
$InputFileStateFile stat-nginx-error
$InputFileSeverity info
$InputFileFacility local3
@Rudge
Rudge / API GIthub and python parse
Last active October 31, 2017 20:16
API GIthub with curl and python parse
curl -H "Authorization: token " 'https://api.github.com/repos/organisation/repository/pulls?state=open' | python3 -c "import sys, json; print(json.load(sys.stdin)[0]['number'])"
curl -u rudge:cacb049a6364adec5fdadc158ee501c6e72ebcfe 'https://api.github.com/orgs/InternetGroup/repos?page=5' | python3 -c "import sys, json; git_res = json.load(sys.stdin); [print(res['name']) for res in git_res]" >> repos
python3 -c "import sys, requests; git_res = requests.get('https://api.github.com/orgs/InternetGroup/repos').json(); [print(res['name']) for res in git_res]" > repos
@Rudge
Rudge / redis commands
Last active October 19, 2017 14:28
Redis - eval commands list keys, show contents and set time expire in keys
eval "redis.call('keys','00*')" 0
EVAL 'local ids = redis.call("keys","00*"); return redis.call("MGET", unpack(ids));' 0
EVAL 'for i, name in ipairs(redis.call("KEYS", "0*")) do redis.call("EXPIRE", name, 10); end' 0
@Rudge
Rudge / cssh2
Last active October 21, 2016 13:04
Cluster ssh open many servers with same name, replace XXX with sequence numbers. Ex: cssh2 MY_USER my-server-XXX 10
#/usr/bin/sh
for i in `seq 1 $3`
do
SERVERS=$SERVERS" "$(echo $2 | sed -e "s/\XXX/$i/g")
done
cssh -l $1 $SERVERS
@Rudge
Rudge / Reload logback in runtime
Created July 15, 2016 12:01
Reload logback in runtime
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
context.reset();
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
configurator.doConfigure(new FileInputStream(new File(env.getProperty("logging.path"))));
@Rudge
Rudge / clone or copy many jobs jenkins
Last active May 20, 2016 20:31
Clone jobs in array to other view by jenkins api
export CLI_JENKINS="java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080 -i /var/lib/jenkins/.ssh/id_rsa"
declare -a arr=("")
for i in "${arr[@]}"
do
if $CLI_JENKINS get-job "$i-projeto-$PROJECT_NUMBER"
then
$CLI_JENKINS delete-job "$i-projeto-$PROJECT_NUMBER"
fi
#!/bin/bash
#sudo update-alternatives --config java
DEFAULT_JAVA="7"
if [ ! -z $1 ]; then
DEFAULT_JAVA=$1
fi
export JAVA_HOME=/usr/lib/jvm/java-$DEFAULT_JAVA-oracle/jre