Skip to content

Instantly share code, notes, and snippets.

View miluna's full-sized avatar

Miguel Angel Luna miluna

View GitHub Profile
@miluna
miluna / csv_to_mdtable.py
Last active March 27, 2019 16:54
This script helps you transform a csv table to a md table
import csv
import sys
def format_csv(input_file):
header = []
final_output = []
# Analyzing and formatting data
with open(input_file) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=';')
@miluna
miluna / binarysearch.js
Created June 10, 2019 11:26
This algorithm is traversing a given array in search of a target value. It divides the array in halves in order to optimize the search
/**
* This algorithm is traversing a given array in search of a target value.
* It divides the array in halves in order to optimize the search
* @param list array that is going to be processed
* @param value that is being searched
*/
function binarySearch (list, value) {
// initial values for start, middle and end
let start = 0
let stop = list.length - 1
@miluna
miluna / twopointer.js
Created June 10, 2019 11:26
This algorithm is traversing the list from two beginning and end searching for pairs that sum to the target value parameter
/**
* This algorithm is traversing the list from two beginning and end searching for
* pairs that sum to the target value parameter
* @param list sorted array of numbers
* @param target sum number to find
**/
function findPairs(list, target) {
const result = [];
let left = 0;
@miluna
miluna / AuthContext.tsx
Created June 26, 2019 23:23
An AuthContext and Provider using Firebase onAuthStateChanged event and React Hooks
import React, { useState, useEffect, Props } from 'react';
import firebase from '../config/firebase';
export const AuthContext = React.createContext({ currentUser: undefined })
export const AuthProvider = (props: Props<any>) => {
const [currentUser, setUser] = useState();
useEffect(() => {
@miluna
miluna / ProtectedRoute.tsx
Created June 26, 2019 23:25
A React ProtectedRoute component that uses AuthContext
import React from 'react';
import { Route, Redirect, RouteProps } from 'react-router';
import { AuthContext } from './AuthContext';
const ProtectedRoute = ({ component: Component, ...rest }: RouteProps) => (
<Route {...rest} render={(props) => (
<AuthContext.Consumer>
{(context) => context.currentUser
? Component
@miluna
miluna / JwtUtil.java
Created June 15, 2020 16:18
Jwt utilities for Spring boot applications
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import java.util.*;
@miluna
miluna / JwtTokenAuthenticationFilter.java
Created June 15, 2020 16:20
JwtTokenAuthenticationFilter for Spring Boot applications
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@miluna
miluna / kubernetes_cheat_sheet.txt
Last active December 2, 2021 15:23
Kubernetes Cheat Sheet
# get info
kubectl get pods
kubectl get services
kubectl get networkpolicy
kubectl get deployments
kubectl get ingress
kubectl get namespaces
kubectl get nodes
kubectl get rs
kubectl get configmaps
@miluna
miluna / sample_kubernetes_deployment.yml
Last active December 2, 2021 15:05
Sample Kubernetes Deployment yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: <ms-name>
labels:
app: <ms-name>
spec:
selector:
matchLabels:
app: <ms-name>
@miluna
miluna / sample_kubernetes_service.yml
Created December 2, 2021 14:47
Sample Kubernetes Service yml
apiVersion: v1
kind: Service
metadata:
name: <ms-name>
spec:
type: NodePort
ports:
- port: 80
protocol: TCP
targetPort: 8080