Skip to content

Instantly share code, notes, and snippets.

View namila007's full-sized avatar
😾
Focusing

Namila Bandara namila007

😾
Focusing
View GitHub Profile
@namila007
namila007 / readme.md
Last active August 24, 2023 09:36
docker wsl daemon expose
  1. docker run -d --restart=always -p 127.0.0.1:23750:2375 -v /var/run/docker.sock:/var/run/docker.sock alpine/socat tcp-listen:2375,fork,reuseaddr unix-connect:/var/run/docker.sock

  2. netsh interface portproxy add v4tov4 listenport=23750 listenaddress=<PUBLIC IP> connectaddress=127.0.0.1 connectport=23750 . PUBLIC-IP= local network IP

  3. firewall inbound rule to expose 23750 port

@namila007
namila007 / app.js
Last active June 8, 2020 20:45
aws-tutorial
const config = require("./config/config")
const express = require("express")
const bodyParser = require("body-parser")
const morgan = require('morgan')
const cors = require("cors")
const router = require("./router/router")
const helmet = require('helmet')
const app = express()
@namila007
namila007 / dockerInstall.sh
Last active July 22, 2020 20:40
install docker and node, vscode in 1 Go
# Uninstall old versions
sudo apt-get remove docker docker-engine docker.io containerd runc
# SETUP REPO
# Update the apt package index:
sudo apt-get update
# Install packages to allow apt to use a repository over HTTPS:
sudo apt-get install \
@namila007
namila007 / generic.java
Created July 15, 2019 06:50
Finding a max int value in given list of objects using its variable name
private <E> int findtheLastNoFromtheList( List<E> list, String getFieldName )
{
if ( list.isEmpty() )
{
return 0;
}
int maxCount = 0;
try
{
@Override
@ResponseStatus(HttpStatus.BAD_REQUEST)
protected ResponseEntity<Object> handleMethodArgumentNotValid( MethodArgumentNotValidException e,
HttpHeaders headers, HttpStatus status, WebRequest request )
{
ApiError apiError = createError( MESSAGE_FOR_INVALID_BODY_ERROR, HttpStatus.BAD_REQUEST, e );
return new ResponseEntity<>( apiError, apiError.getStatus() );
}
@PostMapping
public ResponseWrapper<Author> createAuthor( @Valid @RequestBody Author author )
{
return new ResponseWrapper<>( authorMainService.add( author ), HttpStatus.OK );
}
@ExceptionHandler(ConstraintViolationException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public ResponseEntity<Object> handleConstraintViolationException( ConstraintViolationException e )
{
ApiError apiError = createError( MESSAGE_FOR_INVALID_PARAMETERS_ERROR, HttpStatus.BAD_REQUEST, e );
return new ResponseEntity<>( apiError, apiError.getStatus() );
}
@GetMapping(value = "/{id}")
public ResponseWrapper<Author> getAuthorById(
@Valid @Pattern(regexp = REGEX_FOR_NUMBERS, message = MESSAGE_FOR_REGEX_NUMBER_MISMATCH) @PathVariable(value = "id") String id )
{
return new ResponseWrapper<>( authorMainService.getById( Integer.parseInt( id ) ), HttpStatus.OK );
}
@ResponseStatus(HttpStatus.NOT_FOUND)
public class ResourceNotFoundException extends RuntimeException
{
public ResourceNotFoundException( String exception )
{
super( exception );
}
}
@Data
class ApiError
{
private HttpStatus status;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DATE_FORMAT)
private LocalDateTime timestamp;
private String message;
private String debugMessage;