Skip to content

Instantly share code, notes, and snippets.

View wesleyegberto's full-sized avatar
🎯
Exploring

Wesley Egberto wesleyegberto

🎯
Exploring
View GitHub Profile
@wesleyegberto
wesleyegberto / JavaJacksonGenericTypeJsonTest.java
Created April 7, 2022 20:22
Snippet to parse string JSON to a generic class using Jackson lib for Java
class Event<T> {
T payload;
}
public <T> T parseJsonToClass(String json, Class<T> targetClass) throw JsonProcessingException {
var targetType = objectMapper
.getTypeFactory()
.constructParametricType(Event.class, targetClass);
return objectMapper.readValue(json, targetType);
@wesleyegberto
wesleyegberto / angular-cheatsheet.ts
Last active June 15, 2021 14:15
Angular Cheatsheet
/* *******************************************************************************************
* ANGULAR (2+) CHEATSHEET
* BASED ON https://angular.io/guide/cheatsheet
* DOCUMENTATION: https://angular.io/docs
* STYLE GUIDE: https://angular.io/guide/styleguide
* ******************************************************************************************* */
Original file can be seen [here](https://github.com/LeCoupa/awesome-cheatsheets/blob/master/frontend/angular.js)
```
@wesleyegberto
wesleyegberto / api-design-cheat-sheet.md
Created June 15, 2021 14:08
API Design Cheat Sheet

This is a copy, original file can be seen here

See also: Platform Building Cheat Sheet

API Design Cheat Sheet

  1. Build the API with consumers in mind--as a product in its own right.
    • Not for a specific UI.
    • Embrace flexibility / tunability of each endpoint (see #5, 6 & 7).
  • Eat your own dogfood, even if you have to mockup an example UI.
@wesleyegberto
wesleyegberto / NodeMultiStage.Dockerfile
Created May 19, 2020 18:37
Example of Dockerfile to build Node app using multistage to lower its image size (without the large node_node modules).
# Stage 1 - the build process
FROM node:10-alpine as build-deps
WORKDIR /src
COPY package.json package-lock.json ./
RUN npm i --silent
COPY . ./
RUN npm run build
# Stage 2 - the production environment
FROM nginx:1.12-alpine
@wesleyegberto
wesleyegberto / monitored_ab_stress.sh
Last active January 25, 2021 08:03
Script to start a server and run a monitored stress test using Apache Bench
# Script to run stress test agains a URL using Apache Bench
# Usage: sh monitored_ab_stress.sh "$CMD" <URL-stress> <output-results-filename>
# where CMD="java -jar my-app.jar"
# script origin at https://github.com/jkremser/micronaut-app-k8s/blob/master/plot-test.sh
#!/bin/bash
echo "=== Monitored Apache Bench Test - Started"
echo $@
URL_TEST=$2
@wesleyegberto
wesleyegberto / Dockerfile.dev
Created April 26, 2020 08:17
Dockerfile to build docker image for development (supports live reload and debug by attaching to the remote JVM)
# docker run -d --rm --name my-app --network dkrnet -p 8080:8080 my-app
FROM maven:3.6.3-jdk-13
COPY pom.xml /workspace/
COPY src /workspace/src/
WORKDIR /workspace/
CMD ["mvn", "compile", "quarkus:dev", "-Dquarkus.live-reload.password=123"]
@wesleyegberto
wesleyegberto / simple-control-value-acessor.ts
Created September 9, 2019 23:05
Base class to create Angular components
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { forwardRef, Type } from '@angular/core';
/**
* Function to create the basic provider to components which use `ngModel` as required by Angular.
* @param type component type which extends `SimpleControlValueAcessor`
*/
export function createProviders(type: Type<SimpleControlValueAcessor>) {
return [
{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => type), multi: true }
@wesleyegberto
wesleyegberto / profiling.vim
Created February 15, 2020 19:45
Script to profiling Vim to see what plugin are slowing thing down
" Source: https://stackoverflow.com/questions/12213597/how-to-see-which-plugins-are-making-vim-slow
:profile start profile.log
:profile func *
:profile file *
" At this point do slow actions
:profile pause
:noautocmd qall!
@wesleyegberto
wesleyegberto / jupyter_pandas_download_dataframe.py
Created February 11, 2020 00:08
Function to download a Pandas dataframe from a Jupyter notebook
def csv_download_link(df, csv_file_name, delete_prompt=True):
"""Display a download link to load a data frame as csv from within a Jupyter notebook"""
df.to_csv(csv_file_name, index=False)
from IPython.display import FileLink
display(FileLink(csv_file_name))
if delete_prompt:
a = input('Press enter to delete the file after you have downloaded it.')
import os
os.remove(csv_file_name)