Skip to content

Instantly share code, notes, and snippets.

View strikaco's full-sized avatar
💋
Chaotic Good

Johnny strikaco

💋
Chaotic Good
View GitHub Profile
@strikaco
strikaco / iotest.py
Created January 16, 2017 04:38
Python - Are Threads or Processes more appropriate for disk I/O-bound operations?
from threading import Thread
from multiprocessing import Process
from os import remove
from time import time
class IOTest:
max_workers = 10
max_lines = 10000000
@strikaco
strikaco / search.py
Last active January 21, 2017 12:08
Alternate implementation of NLTK's concordance() - no dependencies needed!
def concordance(string, search_term, width=25):
"""
Alternative implementation of NLTK's concordance() that
allows printing to stdout or saving to a variable and
does not require NLTK.
Just feed it a raw string, JSON string, etc. with any line
breaks stripped out.
"""
# Offset tracks our progress as we parse through the string
@strikaco
strikaco / JsonHandler.py
Created October 12, 2017 16:52
Django Model JsonHandler
class JsonHandler(object):
"""
Handles serialization/deserialization of attributes in the JSON blob.
Requires a field of type TextField named 'blob' on the source model.
These are not searchable unless you do FTS on the obj.blob field!
"""
def __init__(self, node, *args, **kwargs):
# Must set via dict interface or else it triggers __setattr__
from django.test import TestCase
from pandas import DataFrame
from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import Pipeline
import numpy
import os
@strikaco
strikaco / cim.txt
Last active October 11, 2018 00:24
CIM Format (JSON)
{"Dataset name": "Alerts", "Possible values": [], "Model": "Alerts", "Expected values": [], "Data type": "string", "Description": "The application involved in the event, such as win:app:trendmicro, vmware, nagios.", "Field name": "app"}
{"Dataset name": "Alerts", "Possible values": [], "Model": "Alerts", "Expected values": [], "Data type": "string", "Description": "The body of a message.", "Field name": "body"}
{"Dataset name": "Alerts", "Possible values": [], "Model": "Alerts", "Expected values": [], "Data type": "string", "Description": "The destination of the alert message, such as an email address or SNMP trap. You can alias this from more specific fields, such as dest_host, dest_ip, or dest_name.", "Field name": "dest"}
{"Dataset name": "Alerts", "Possible values": [], "Model": "Alerts", "Expected values": [], "Data type": "string", "Description": "The business unit associated with the destination. This field is automatically provided by asset and identity correlation features of applications like ClownS
@strikaco
strikaco / sqlalchemy_example.py
Created October 17, 2020 20:38 — forked from ronreiter/sqlalchemy_example.py
SQLAlchemy Example
from sqlalchemy import Column, Integer, String, ForeignKey, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, backref, sessionmaker, joinedload
# For this example we will use an in-memory sqlite DB.
# Let's also configure it to echo everything it does to the screen.
engine = create_engine('sqlite:///:memory:', echo=True)
# The base class which our objects will be defined on.
Base = declarative_base()
@strikaco
strikaco / graph.json
Created October 17, 2020 20:42 — forked from eyaler/graph.json
Force-Directed Graph with Drag/Zoom/Pan/Center/Resize/Labels/Shapes/Filter/Highlight
{
"graph": [],
"links": [
{"source": 0, "target": 1},
{"source": 0, "target": 2},
{"source": 0, "target": 3},
{"source": 0, "target": 4},
{"source": 0, "target": 5},
{"source": 0, "target": 6},
{"source": 1, "target": 3},
@strikaco
strikaco / test.py
Created December 6, 2020 01:59 — forked from OrganicPanda/test.py
A basic CherryPy/SQLAlchemy example site to demonstrate a multi-user issue
import cherrypy
import sqlalchemy
from sqlalchemy import Table, Column, ForeignKey, MetaData, Integer, String
from sqlalchemy.orm import scoped_session, sessionmaker, mapper, relationship
from sqlalchemy.orm.properties import ColumnProperty
from sqlalchemy.orm.util import object_mapper
# The base class from which all entities will extend
class BaseEntity(object):
def __repr__(self):
@strikaco
strikaco / components.py
Created April 1, 2022 18:31
Python - Component dataclasses as class properties
from dataclasses import dataclass, field, fields, replace, asdict
_MISSING = object()
@dataclass
class Component(object):
"""
Collection of attributes.
"""
_key: str = field(default=None, hash=False, repr=False, compare=False)
@strikaco
strikaco / values.py
Created April 14, 2022 02:23
Value Container
from dataclasses import dataclass, field, asdict
from enum import Enum, auto
class Scale(Enum):
NONE = 0
LOW = 25
MEDIUM = 50
HIGH = 75
MAX = 100