Skip to content

Instantly share code, notes, and snippets.

View andysteel's full-sized avatar
🏠
Working from home

Anderson Dias andysteel

🏠
Working from home
View GitHub Profile
@andysteel
andysteel / main.ts
Created June 21, 2022 18:11
Bootstrapping Angular with standalone components
import { enableProdMode, importProvidersFrom } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { routes } from './app/app-routing.module';
import { AppComponent } from './app/app.component';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
@andysteel
andysteel / CustomExceptionControllerAdvice.java
Created May 10, 2022 00:24 — forked from susimsek/CustomExceptionControllerAdvice.java
Spring Boot File Content Type Validation With Annotation
@ControllerAdvice
public class CustomExceptionControllerAdvice {
@ExceptionHandler(MultipartException.class)
void handleMultipartException(MultipartException ex,HttpServletResponse response) throws IOException {
response.sendError(HttpStatus.BAD_REQUEST.value(),"Please select a file");
}
@ExceptionHandler(ConstraintViolationException.class)
public void handleConstraintViolationException(ConstraintViolationException ex,HttpServletResponse response) throws IOException {
@andysteel
andysteel / Jenkinsfile
Created September 19, 2021 21:26
A jenkins file example build a java project in a github monorepo with docker deploy
pipeline {
agent any
tools {
maven 'maven_3_8_2'
jdk 'JDK 11'
}
stages {
stage('Clone') {
@andysteel
andysteel / nginx_prevent_ddos.md
Last active February 21, 2022 17:44
Using NGINX to prevent DDoS Attacks

Using NGINX to prevent DDoS Attacks Nginx, a highly popular server system for Unix machines, comes with enough built-in functionality to greatly limit the effectiveness of DDoS attacks. These features could handle a DDoS attack by regulating the incoming traffic and by controlling the traffic as it is proxied to backend services.

Before you change any settings, make sure you make a quick backup of your server’s configuration. The following command works for this:

sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup-original Nginx worker connections One of the important parameters that we tweak is the number of worker process and number of worker connections in the Nginx configuration file /etc/nginx/nginx.conf.

We’ll gradually adjust the worker process and worker connections to a higher or lower value for handling DDoS attacks.

@andysteel
andysteel / remote_debug.md
Last active September 15, 2021 23:30
Debug remote Java applications and server app(Tomcat)

java -Xdebug -Xrunjdwp:transport=dt_socket,address=8998,server=y -jar myapp.jar

Configuring Eclipse to Debug a Remotely Running Application

1-Go to Run -> Debug Configurations
eclipse-run-debug-conf-menu-item

2-Create a new Remote Java Application configuration
find-remote-java-app-new

@andysteel
andysteel / ConnectionFactory.java
Created May 31, 2021 12:59
Oracle TNS connection for jdbc
package br.gov.anp.andersondias.Connection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionFactory {
public Connection getConnection() throws SQLException {
@andysteel
andysteel / Portable Node.js andNPM on windows.md
Last active May 19, 2021 00:19
Portable Node.js and NPM on windows
  1. Get node binary (node.exe) from http://nodejs.org/download/
  2. Create the folder where node will reside and move node.exe to it
  3. Download the last zip version of npm from http://nodejs.org/dist/npm
  4. Unpack the zip inside the node folder
  5. Download the last tgz version of npm from http://nodejs.org/dist/npm
  6. Open the tgz file and unpack only the file bin/npm (without extension) directly on the node folder.
  7. Add the the node folder and the packages/bin folder to PATH
  8. On a command prompt execute npm install -g npm to update npm to the latest version
@andysteel
andysteel / OracleOpenPort80Centos.md
Created May 13, 2021 02:27 — forked from jbaranski/OracleOpenPort80Centos.md
Open Port 80 Oracle Cloud Compute Instance (CentOS)

Open Port 80 Oracle Cloud Compute Instance (CentOS)

FYI This was harder than it needed to be:

  1. Looking at your instance info, find VNIC section, click "Public Subnet".
  2. Click on your security list.
  3. Add a new entry with the following options:
  • "Stateless" = No, "Source" = 0.0.0.0/0, "IP Protocol" = TCP, "Source Port Range" = All, "Destination Port Range" = 80
  1. SSH to your instance.
  2. While SSH'ed in your instance, run command firewall-cmd --permanent --add-service=http.
  3. While SSH'ed in your instance, run command firewall-cmd --reload.
  4. Now start Apache, NGINX, or whatever server you need to on port 80. You can now access from the internet.
@andysteel
andysteel / Example.java
Created May 11, 2021 01:35
Get client digital certificate
@POST
@Path("/getHelloWorld")
@Consumes(MediaType.APPLICATION_JSON)
public String helloWorld(@Context HttpServletRequest httpRequest) {
X509Certificate[] certs = (X509Certificate[]) httpRequest.getAttribute("javax.servlet.request.X509Certificate");
if (null != certs && certs.length > 0) {
return <<YOUR CODE HERE>>;
}
return <<YOUR CODE HERE>>;
}
@andysteel
andysteel / ConfigurationExample.java
Created May 11, 2021 01:16
Example of Uploading file with PUT method in Spring
@Configuration
public class ConfigurationExample {
@Bean(name = "multipartResolver")
public CommonsMultipartResolver createMultipartResolver() {
return new PostAndPutCommonsMultipartResolver();
}
}