Skip to content

Instantly share code, notes, and snippets.

View gordol's full-sized avatar

Gordo Lowrey gordol

View GitHub Profile
@gordol
gordol / prime-challenge.py
Last active September 28, 2019 06:02
A simple little module to complete the prime number challenge. Includes 4 tests. This could be made to be much much faster if we used PyPy and NumPy, but the challenge was to utilize the standard library only. To run the tests, run: `python -m unittest prime-challenge`
#!/usr/bin/env python
import itertools
import unittest
def primeGenerator():
"""
Yields an array of primes.
"""
"""
We are trying to determine which offenses can be matched to a candidate. Candidates names' often do not match exactly to criminal records, but still represent the candidate. We are given a JSON file of possible criminal offenses and a candidate's aliases. We use a point system to judge how well a record matches to a candidate.
The point system starts out at 100 (100% accurate) being an exact match. We can do 4 edit types to a record name to get to an exact match of one of the candidate's aliases.
Edits:
A middle name swapped with a first name subtracts 7 points
A first name nickname swap subtracts 5 points
A middle name nickname swap subtracts 3 points
from eventlet.green import socket
from helpers import dict_merge
SOH = u'\u0001'
ETX = u'\u0003'
alarm_category_code_mapping = dict(
name = 'alarm/warning category',
len = 2,
format = 'AA',
@gordol
gordol / udp-punch.py
Created October 4, 2017 11:02
Automated Bidirectional UDP NAT Traversal via SSH Wizardry
#!/usr/bin/env python3
"""
This is a 100% self-contained script to facilitate automated creation of bidirectional UDP pinholes.
It should work as a non-root user assuming you use a high port number.
All that is necessary is an SSH server with a Python environment.
This script is ran on the client, and then the client runs it on the server dynamically.
No permanent changes are made to the server.
Basically we just open UDP connection from both ends, to the same port, and then exchange some tokens to verify connectivity.
ModelView
---------
# field1 (->Model1), field2 (->Model2) filtered by field1 values
column_filter_by = ('field2')
form_widget_args = {
'field2': {
'data-filter-by': 'field1',
}
}
@gordol
gordol / pjl_generator.py
Created September 14, 2016 02:23
Generates commands to configure network settings on Brother Label Printers
#!/usr/bin/env python
def str_to_hex(string):
return "-".join("{:02x}".format(ord(c)) for c in str(string))
def chunks(s, n):
for start in range(0, len(s), n):
yield s[start:start+n]
delimiter = '%-12345X@PJL'
@gordol
gordol / example.py
Created August 23, 2016 23:31
Complex Flask-Admin View with custom filters and bulk action
class FilterLowercase(BaseMongoEngineFilter):
def apply(self, query, value):
flt = {'%s__icontains' % self.column: value}
return query.filter(**flt)
def operation(self):
return gettext('contains')
class FilterLowercaseNot(BaseMongoEngineFilter):
def apply(self, query, value):