This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import pymysql | |
from sqlalchemy import create_engine | |
engine = create_engine('mysql+pymysql://<user>:<password>@<host>:<port>/<dbname>') | |
df = pd.read_sql_query('SELECT * FROM table', engine) | |
df.head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# author: @Daniel_Abeles | |
# date: 10/05/2017 | |
import numpy as np | |
import pandas as pd | |
class Headers(object): | |
''' Represents a header list ''' | |
__slots__ = ['_headers', '_key'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# author: @Daniel_Abeles | |
# date: 18/12/2017 | |
import asyncio | |
from aiohttp import ClientSession | |
from timeit import default_timer | |
import async_timeout | |
async def fetch_all(urls: list): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# author: @Daniel_Abeles | |
# date: 23/12/2017 | |
def inject_generic_repr(cls): | |
""" Injects a generic repr function """ | |
def generic_repr(that): | |
class_items = [f'{k}={v}' for k, v in that.__dict__.items()] | |
return f'<{that.__class__.__name__} ' + ', '.join(class_items) + '>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# author: @Daniel_Abeles | |
# date: 13/02/2018 | |
# assuming we have a data frame called "df" | |
# we can "groupby" by a column col1 | |
# and collect all the distinct values of col2 | |
df.groupby("col1").agg({ | |
"col2": lambda x: set(x) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ | |
* | |
0 | |
00 | |
0-0 | |
000 | |
0000 | |
00000 | |
000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
# Pickle deserialization RCE payload. | |
# To be invoked with command to execute at it's first parameter. | |
# Otherwise, the default one will be used. | |
# | |
import cPickle | |
import sys | |
import base64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def explode(df, by_column, new_col_name): | |
rows = [] | |
for row in df.itertuples(): | |
for value in getattr(row, by_column): | |
rows.append({ | |
new_col_name: value, | |
**{ | |
key: getattr(row, key) | |
for key in row._fields |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from matplotlib import pyplot as plt | |
plt.figure(figsize=(10,5)) | |
ax = df.column1.sort_values(ascending=False).head(10).plot.barh() | |
ax.set_title("My Awesome Title", fontsize=12) | |
for patch in ax.patches: | |
ax.text( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sanic import Sanic, Blueprint | |
from jinja2 import Environment, PackageLoader, select_autoescape | |
from sanic.response import html | |
def get_package_name(): | |
return __name__.split('.')[0] | |
class InjectJinjaSupport(object): |
OlderNewer