Skip to content

Instantly share code, notes, and snippets.

View andypayne's full-sized avatar

Andy Payne andypayne

View GitHub Profile
@andypayne
andypayne / test_argparse.py
Created June 15, 2021 18:19
Longer arguments with python argparse
import sys
import argparse
parser = argparse.ArgumentParser(description='Test argparse',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--str',
dest='string_arg',
metavar='string_arg',
default=None,
@andypayne
andypayne / yolov3.cfg
Created May 21, 2020 14:44
yolov3.cfg configured for testing
[net]
# Testing
batch=1
subdivisions=1
width=608
height=608
channels=3
momentum=0.9
decay=0.0005
angle=0
@andypayne
andypayne / blenderpy_cube.py
Created May 5, 2020 13:55
A cube in Blender Python
import bpy
sz = 2
verts = [(0,0,0), (0,sz,0), (sz,sz,0), (sz,0,0), (0,0,sz), (0,sz,sz), (sz,sz,sz), (sz,0,sz)]
faces = [(0,1,2,3), (7,6,5,4), (0,4,5,1), (1,5,6,2), (2,6,7,3), (3,7,4,0)]
amesh = bpy.data.meshes.new("Cube")
anobj = bpy.data.objects.new("Cube", amesh)
anobj.location = bpy.context.scene.cursor_location
# 20Newsgroups dataset sorted by date, deduplicated: http://qwone.com/~jason/20Newsgroups/20news-bydate.tar.gz
# Using some code to re-encode text files from the 20Newsgroups dataset resulted in an encoding error:
# 'utf-8' codec can't decode byte 0xa0 in position 1000: invalid start byte
# The original code:
for path, subdirs, files in os.walk(DATA_PATH):
for name in files:
fullpath = pathlib.PurePath(path, name)
try:
with codecs.open(fullpath, 'r', encoding = 'utf8') as file:
@andypayne
andypayne / slack_request_verification.md
Last active April 17, 2020 02:35
Note - Verification of Slack Requests

When writing a Slack integration or app, Slack's servers will make requests to your web service. In order to verify the integrity and authenticity of requests from Slack, the body of each request is signed, and the signature is included in the request headers. The X-Slack-Signature header field contains an HMAC-SHA256 keyed hash of the request body.

If you're using Node.js, here's a way to verify the requests.

1. Get access to the raw body of each request

If you're using Express then you may be using body-parser to reformat the request body as JSON when applicable. In that case, a verify function will need to be passed so that it can save the raw body before processing. Here's an example:

@andypayne
andypayne / intrusions.md
Created April 15, 2020 19:47
Quick intrusion evidence in CloudWatch

Filtering web server logs for a couple examples of suspicious activity for reporting in AWS CloudWatch:

fields @timestamp, @message
| filter @message like /(?i)(\/etc\/passwd)|(\<script\>alert)/
| sort @timestamp desc
| stats count() by bin(60s)
# -4
define :mood_neg_4 do
with_fx :reverb, room: 1 do
[1, 3, 4, 6].each do |d|
(range 3, 0).each do |i|
play_chord (chord_degree d, :c, :diminished, 3, invert: i)
sleep 0.2
end
end
end