Skip to content

Instantly share code, notes, and snippets.

@NosearY
NosearY / JaxbXmlStreamMarshaller.kt
Last active March 29, 2023 13:13
XML Stream Marshaller
import jakarta.xml.bind.JAXBContext
import jakarta.xml.bind.JAXBElement
import jakarta.xml.bind.Marshaller
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.io.FileOutputStream
import javax.xml.namespace.QName
import javax.xml.stream.XMLOutputFactory
import javax.xml.stream.XMLStreamWriter
@NosearY
NosearY / locals.tf
Last active May 29, 2024 15:19
Flatten a map in terraform
locals {
nested_map = {
"app1" = {
"port" = 80
"image" = "nginx:latest"
"url" = [
"https://www.google.com",
"https://www.github.com",
"https://www.hashicorp.com"
]
@NosearY
NosearY / nginx.conf
Created March 4, 2022 02:28
sample nginx config
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
@NosearY
NosearY / httpd.conf
Created February 26, 2022 06:06
Allow CORS in Apache Web Server
<VirtualHost *:80>
DocumentRoot /var/www/html/
ServerName example.com
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
SetEnvIf Origin "http(s)?://(www\.)?(dev.test.co:18088|uat.test.co:18088|test.com)$" AccessControlAllowOrigin=$0
Header always set Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header always set Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token, token, x-locale"
Header always set Access-Control-Expose-Headers "Content-Security-Policy, Location"
Header always set Access-Control-Max-Age "600"
@NosearY
NosearY / cors.conf
Last active February 26, 2022 08:57
NGINX Whitelist CORS by Domain
if ($http_origin ~ '^https?://((sub1\.test\.com\)|(sub2\.test\.com))') {
set $cors 'true';
}
if ($cors = 'true') {
add_header 'Access-Control-Allow-Origin' "$http_origin" always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
# required to be able to read Authorization header in frontend