Skip to content

Instantly share code, notes, and snippets.

View Den1al's full-sized avatar
🎯
Focusing

Den1al Den1al

🎯
Focusing
View GitHub Profile
@Den1al
Den1al / mysql-pandas-import.py
Last active December 14, 2017 15:57 — forked from stefanthoss/mysql-pandas-import.py
Import data from a MySQL database table into a Pandas DataFrame using the pymysql package.
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()
@Den1al
Den1al / pandas-http-headers.py
Last active February 13, 2018 17:02
Working with HTTP Headers in Pandas can be tricky, this snippet usually works for me to handle that task.
# 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']
@Den1al
Den1al / aiohttp-example.py
Last active June 22, 2023 12:53
concurrent http requests with aiohttp
# 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):
@Den1al
Den1al / generic-repr.py
Last active February 13, 2018 16:58
A decorator that injects a generic repr function to a class
# 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) + '>'
@Den1al
Den1al / pandas-groupby-collect-set.py
Last active January 14, 2022 17:25
Pandas collect-set operator on a groupby object
# 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)
})
@Den1al
Den1al / all.txt
Created March 18, 2018 12:26 — forked from jhaddix/all.txt
all wordlists for every dns enumeration tool... ever.
@
*
0
00
0-0
000
0000
00000
000000
@Den1al
Den1al / pickle-payload.py
Created September 27, 2018 13:20 — forked from mgeeky/pickle-payload.py
Python's Pickle Remote Code Execution payload template.
#!/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
@Den1al
Den1al / pandas-explode.py
Created November 29, 2018 09:05
An implementation of HIVE's explode function in pandas
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
@Den1al
Den1al / pandas-plot-bar-annotation.py
Created January 9, 2019 11:14
Pandas plot bar/barh annotation script
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(
@Den1al
Den1al / sanic-render-template.py
Created April 13, 2019 18:10
Injecting the render_template function to sanic apps and templates
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):