Skip to content

Instantly share code, notes, and snippets.

View kouzouigh's full-sized avatar

Ouzouigh Kamel kouzouigh

View GitHub Profile
@kouzouigh
kouzouigh / AlgDT.scala
Created July 16, 2021 13:22 — forked from mbbx6spp/AlgDT.scala
An introduction to algebraic data types (basics) in Scala...some things need to get cleaned up, but only after you grasp the basics. Part 1
package net.susanpotter.algdt
sealed trait Order {
def execute: Unit // ignore that Unit return type is not a great idea...
}
case class MarketOrder extends Order {
def execute {
println "executing market order"
}
@kouzouigh
kouzouigh / presenter.kt
Created April 11, 2021 13:46 — forked from lievendoclo/presenter.kt
Presenter in Clean Architecture
// shared datastructures
data class ResponseModel(val value: String)
data class JsonResponse(val jsonValue: String)
// example 1
interface FooUseCase {
fun <T> T doSomething(presenter: (ResponseModel -> T))
}
@kouzouigh
kouzouigh / ZipUnzip.groovy
Created April 8, 2021 09:14 — forked from bitsnaps/ZipUnzip.groovy
Zip and UnZip files using Groovy
import java.util.zip.*
String zipFileName = "file.zip"
String inputDir = "logs"
def outputDir = "zip"
//Zip files
ZipOutputStream zipFile = new ZipOutputStream(new FileOutputStream(zipFileName))
new File(inputDir).eachFile() { file ->
@kouzouigh
kouzouigh / generate_csr.groovy
Last active April 8, 2021 09:13
Generate CSR with with openssl executed with groovy script
(1..150).each {
def command = ["openssl", "req", "-nodes", "-newkey", "rsa:2048", "-keyout", "/tmp/csr/example${it}.key", "-out", "/tmp/csr/csr_example_${it}.csr", "-subj", "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=example${it}.com"]
def sout = new StringBuilder(), serr = new StringBuilder()
def proc = command.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitFor()
println "out> $sout\nerr> $serr"
}
@kouzouigh
kouzouigh / read-certificate-with-ssl.groovy
Created November 24, 2020 08:44
Read x509 certificate by using OpenSSL with Groovy
def cert = "-----BEGIN CERTIFICATE-----\n" +
"MIIDojCCAoqgAwIBAgIUE6k0hxK8Iy2XJYZK8fVJaQGLIHIwDQYJKoZIhvcNAQEL\n" +
"BQAwUDELMAkGA1UEBhMCRlIxGTAXBgNVBAgMEMODwo5sZS1kZS1GcmFuY2UxDjAM\n" +
"BgNVBAcMBVBhcmlzMRYwFAYDVQQKDA1NeSBDb21wYW55IEluMB4XDTIwMTEyNDA4\n" +
"NDMwMloXDTIxMTEyNDA4NDMwMlowUDELMAkGA1UEBhMCRlIxGTAXBgNVBAgMEMOD\n" +
"wo5sZS1kZS1GcmFuY2UxDjAMBgNVBAcMBVBhcmlzMRYwFAYDVQQKDA1NeSBDb21w\n" +
"YW55IEluMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArZng3abWPwQp\n" +
"EB7u3qFhVctDhdY2eo1PxNZ0rbc7SSOUEBsoZTZHmO/tExmHx8FOtRthFa1RTjYH\n" +
"SNBR6pYiOUiSE7xDrkvNSNdtQWbP8fpK53m0eWqtjXoyl7nbJ+r5tQaFmisuGlBe\n" +
"3AVQvs9nxRtHQ7iTZD0sG0BSyh0lLRDKbLP9C88sIh0jO8PtqAzSMKERts4bj7OZ\n" +
@kouzouigh
kouzouigh / docker-compose.yml
Created September 21, 2020 13:43 — forked from brunosimioni/docker-compose.yml
Docker Compose to Prometheus, PushGateway and Grafana setup
version: '2.1'
networks:
monitor-net:
driver: bridge
volumes:
prometheus_data: {}
grafana_data: {}
//http://chrisbroadfoot.id.au/2008/08/06/groovy-threads/
//http://docs.groovy-lang.org/latest/html/gapi/groovy/transform/Synchronized.html
//https://github.com/jenkinsci/jenkins-scripts/blob/master/scriptler/findOfflineSlaves.groovy
import java.util.concurrent.locks.ReentrantLock
ReentrantLock.metaClass.withLock = {
lock()
try {
it()
@kouzouigh
kouzouigh / HttpClientAutoConfiguration.java
Created May 4, 2020 07:35 — forked from jkuipers/HttpClientAutoConfiguration.java
Spring Boot auto-configuration example for an Apache Components HTTP client and its usage in all RestTemplates created by the RestTemplateBuilder, plus trace logging support
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.client.RestTemplateCustomizer;
@kouzouigh
kouzouigh / Httpie SSL POST
Created October 30, 2019 09:20
Httpie SSL POST request with SSL and Json as file
http --cert=mycert.crt --cert-key=mykey.key --verify=ca-bundle POST https://example.test/api < /path/to_file.json
@kouzouigh
kouzouigh / JsonSchemaGenerator.java
Created October 9, 2019 13:02
Writing Json Schema with Bean Validation Constraints
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator;
import com.fasterxml.jackson.module.jsonSchema.customProperties.ValidationSchemaFactoryWrapper;
import lombok.Data;
@Data
class MyClass {
@Size(min=14, max=14)