Skip to content

Instantly share code, notes, and snippets.

View matheushent's full-sized avatar
💭
Building things and repeating

Matheus Tosta matheushent

💭
Building things and repeating
View GitHub Profile
@matheushent
matheushent / kubectl-apply-stdin.md
Created February 3, 2023 12:06 — forked from zulhfreelancer/kubectl-apply-stdin.md
How to run "kubectl apply -f" with inline YAML as stdin?
$ kubectl apply -f - <<EOF
<-- insert YAML content here -->
EOF

OR

$ cat file.yaml | kubectl apply -f -
@matheushent
matheushent / stack.py
Created October 20, 2021 00:30
CDK stack example for build WAF rules against CloudFront distribution
#CDK python WAF with CloudFront and regex and ip set rules (v1.102.0 of CDK and above)
from aws_cdk import (
core as cdk,
aws_cloudfront as cloudfront,
aws_cloudfront_origins as cloudfront_origins,
aws_s3 as s3,
aws_certificatemanager as acm,
aws_route53 as route53,
aws_wafv2 as wafv2,
@matheushent
matheushent / pytz-time-zones.py
Created September 7, 2020 16:58 — forked from heyalexej/pytz-time-zones.py
list of pytz time zones
>>> import pytz
>>>
>>> for tz in pytz.all_timezones:
... print tz
...
...
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
@matheushent
matheushent / issue.py
Last active April 19, 2020 18:53
Stand alone code for tensorflow issue #38518
import tensorflow_addons as tfa
import tensorflow as tf
def get_norm_layer(norm):
"""Utility function to get the normalization layer
"""
if norm == None:
return lambda: lambda x: x
elif norm == 'batch_norm':
@matheushent
matheushent / guided_relu.py
Created February 26, 2020 17:51 — forked from falcondai/guided_relu.py
Tensorflow implementation of guided backpropagation through ReLU
import tensorflow as tf
from tensorflow.python.framework import ops
from tensorflow.python.ops import gen_nn_ops
@ops.RegisterGradient("GuidedRelu")
def _GuidedReluGrad(op, grad):
return tf.select(0. < grad, gen_nn_ops._relu_grad(grad, op.outputs[0]), tf.zeros(grad.get_shape()))
if __name__ == '__main__':
with tf.Session() as sess:
from tensorflow.examples.tutorials.mnist import input_data
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
mnist = input_data.read_data_sets('mnist/', one_hot=True)
X = mnist.train.images
# 784 -> 128 -> 64 -> 128 -> 784
import tensorflow as tf
import matplotlib.pyplot as plt
from tensorflow.examples.tutorials.mnist import input_data
import numpy as np
tf.reset_default_graph()
mnist = input_data.read_data_sets('mnist/', one_hot=True)
# Test
@matheushent
matheushent / Hyper-parameter Optimization with Lightgbm using skopt.py
Created February 20, 2019 23:59
Hyper-parameter optimization of xgboost model for Santander competition
from warnings import filterwarnings
filterwarnings('ignore')
import pandas as pd
import numpy as np
from lightgbm import LGBMClassifier
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score
import warnings
warnings.filterwarnings('ignore')
import pandas as pd
import numpy as np
from tensorflow.python.keras import backend as K
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import InputLayer, Input
from tensorflow.python.keras.layers import Reshape, MaxPooling2D
from tensorflow.python.keras.layers import Conv2D, Dense, Flatten, Dropout
@matheushent
matheushent / CMBI.py
Created February 5, 2019 13:16
Iris classification
from sklearn import datasets
iris = datasets.load_iris()
X = iris.data
y = iris.target
from sklearn.preprocessing import StandardScaler
scaler_x = StandardScaler()