Skip to content

Instantly share code, notes, and snippets.

package com.example;
import static java.util.Collections.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@tuxmonteiro
tuxmonteiro / Main.java
Created May 25, 2015 01:58
Getting PID on Java
/*
* Copyright (c) 2015 - Marcelo Teixeira Monteiro (tuxmonteiro)
* All rights reserved.
*
* This source is subject to the Apache License, Version 2.0.
*
* Please see the http://www.apache.org/licenses/LICENSE-2.0 for more
* information.
*
* Unless required by applicable law or agreed to in writing, software
@tuxmonteiro
tuxmonteiro / nginx-1.10.2-ssl_cert_cb_yield.patch
Created December 12, 2016 17:42
Nginx 1.10.2 patch to SSL dynamic cert load
# Based from https://github.com/openresty/openresty/blob/v1.11.2.2/patches/nginx-1.11.2-ssl_cert_cb_yield.patch
SSL: handled SSL_CTX_set_cert_cb() callback yielding.
OpenSSL 1.0.2+ introduces SSL_CTX_set_cert_cb() to allow custom
callbacks to serve the SSL certificiates and private keys dynamically
and lazily. The callbacks may yield for nonblocking I/O or sleeping.
Here we added support for such usage in NGINX 3rd-party modules
(like ngx_lua) in NGINX's event handlers for downstream SSL
connections.
#!/bin/bash
DOMAIN=$1
TOKEN="$GDNS_TOKEN"
CONTACT="root.${DOMAIN}."
GDNS="$GDNS_HOST"
CHALLENGE="$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | base64 -b300 | sed -e 's/\+/_/g' -e 's/[= ]//g' -e 's/\//_/g' | cut -c1-200)"
CURL="curl -v -HContent-type:application/json -HX-Auth-Token:${TOKEN}"
DOMAIN_DATA="{\"domain\": {\"name\": \"${DOMAIN}\", \"type\": \"MASTER\", \"ttl\": \"86400\", \"notes\": \"A domain\", \"primary_ns\": \"ns1.${DOMAIN}.\", \"contact\": \"${CONTACT}\", \"refresh\": 10800, \"retry\": 3600, \"expire\": 604800, \"minimum\": 10800,\"authority_type\": \"M\"}}"
private String buildFullHash(String body) throws IOException {
final ByteArrayOutputStream obj = new ByteArrayOutputStream();
final GZIPOutputStream gzip = new GZIPOutputStream(obj);
gzip.write(body.getBytes());
gzip.close();
byte[] fullhash = Base64.getEncoder().encode(obj.toByteArray());
return new String(fullhash);
}
@tuxmonteiro
tuxmonteiro / JMeterFromScratch.java
Created September 5, 2017 05:13
JMeterFromScratch.java
package com.blazemeter.demo;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.config.gui.ArgumentsPanel;
import org.apache.jmeter.control.LoopController;
import org.apache.jmeter.control.gui.LoopControlPanel;
import org.apache.jmeter.control.gui.TestPlanGui;
import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
@tuxmonteiro
tuxmonteiro / MapInline.java
Created January 25, 2018 20:31
Map put inline example
class MapInline {
private Map<> inline(String id) {
return Stream.of(new AbstractMap.SimpleImmutableEntry<>("environment", id)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
// OR Stream.of(id).collect(Collectors.toMap(i -> "environment", Function.identity()));
}
}
@tuxmonteiro
tuxmonteiro / extract-dockerfile-from-image.sh
Created January 28, 2018 23:38
Extract dockerfile from image
function dc_trace_cmd() {
local parent=`docker inspect -f '{{ .Parent }}' $1` 2>/dev/null
declare -i level=$2
echo ${level}: `docker inspect -f '{{ .ContainerConfig.Cmd }}' $1 2>/dev/null`
level=level+1
if [ "${parent}" != "" ]; then
echo ${level}: $parent
dc_trace_cmd $parent $level
fi
}
@tuxmonteiro
tuxmonteiro / tcp_flags.txt
Created August 1, 2018 11:55 — forked from tuxfight3r/tcp_flags.txt
tcpdump - reading tcp flags
##TCP FLAGS##
Unskilled Attackers Pester Real Security Folks
==============================================
TCPDUMP FLAGS
Unskilled = URG = (Not Displayed in Flag Field, Displayed elsewhere)
Attackers = ACK = (Not Displayed in Flag Field, Displayed elsewhere)
Pester = PSH = [P] (Push Data)
Real = RST = [R] (Reset Connection)
Security = SYN = [S] (Start Connection)
@tuxmonteiro
tuxmonteiro / CentOS-Docker
Created May 18, 2019 17:53 — forked from silveraid/CentOS-Docker
Creating minimal CentOS docker image from scratch
# Create a folder for our new root structure
$ export centos_root='/centos_image/rootfs'
$ mkdir -p $centos_root
# initialize rpm database
$ rpm --root $centos_root --initdb
# download and install the centos-release package, it contains our repository sources
$ yum reinstall --downloadonly --downloaddir . centos-release
$ rpm --root $centos_root -ivh centos-release*.rpm
$ rpm --root $centos_root --import $centos_root/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# install yum without docs and install only the english language files during the process