Skip to content

Instantly share code, notes, and snippets.

View madagra's full-sized avatar

Mario Dagrada madagra

View GitHub Profile
@madagra
madagra / place_api.py
Created December 21, 2017 19:24
Simple Python wrapper for the Google Places API
import requests
import unittest
from urllib.parse import urlencode
class CheckResponse :
def __call__(self,fn) :
def fn_wrapper(*args) :
try :
response = fn(*args)
if "status" not in response or \
@madagra
madagra / hulk.py
Created May 7, 2018 15:50 — forked from rambabusaravanan/hulk.py
HULK Python Script : Denial-of-Service (DoS) attack
# ----------------------------------------------------------------------------------------------
# HULK - HTTP Unbearable Load King
#
# this tool is a dos tool that is meant to put heavy load on HTTP servers in order to bring them
# to their knees by exhausting the resource pool, its is meant for research purposes only
# and any malicious usage of this tool is prohibited.
#
# author : Barry Shteiman , version 1.0
# ----------------------------------------------------------------------------------------------
import urllib2
@madagra
madagra / lag_features.py
Last active April 26, 2020 10:59
Create lag features for time series analysis
import pandas as pd
from sklearn.preprocessing import StandardScaler
from statsmodels.tsa.stattools import pacf
def create_lag_features(y):
scaler = StandardScaler()
features = pd.DataFrame()
partial = pd.Series(data=pacf(y, nlags=48))
@madagra
madagra / ts_recursive_strategy.py
Created April 26, 2020 11:00
Recursive strategy time series forecasting
def recursive_forecast(y, model, lags,
n_steps=FCAST_STEPS, step="1H"):
"""
Parameters
----------
y: pd.Series holding the input time-series to forecast
model: pre-trained machine learning model
lags: list of lags used for training the model
n_steps: number of time periods in the forecasting horizon
def direct_forecast(y, model, lags,
n_steps=FCAST_STEPS, step="1H"):
"""
Parameters
----------
y: pd.Series holding the input time-series to forecast
model: a ML model not trained
lags: list of lags used for training the model
n_steps: how many steps forecast into the future
@madagra
madagra / dash_layout.py
Created May 18, 2020 18:56
dash_sample_layout
app = dash.Dash(__name__)
app.layout = html.Div(children=[
html.Div(dcc.Markdown(description)),
html.Hr(),
html.Div([
html.Div(id="parameters-box-id", children=[
dcc.Markdown(params_description),
dcc.Input(
id="tottime-input-id",
{
"name": "Device",
"children": [
{
"name": "Networking",
"children": [
{ "name": "Router", "children": [] },
{ "name": "Switch" },
{ "name": "Firewall", "children": [] }
]
{
"L0": [
{ "name": "device" }
],
"L1": [
{ "name": "Networking", "parent": "Device" },
{ "name": "Computer", "parent": "Device" }
],
"L2": [
{ "name": "Router", "parent": "Networking" },
import json
from anytree import Node, RenderTree
from anytree.search import find
class TaxonomyParser:
"""
This class is a wrapper on a Tree class from the anytree library to hold
different data hierarchies read from a JSON representation
"""
from anytree.exporter import DotExporter
COLOR_SCHEME = ["aliceblue", "antiquewhite", "azure", "coral", "palegreen"]
def export(self):
"""
Export tree into graphviz format in both *.dot file and image *.png file
"""
def nodeattr_fn(node):