Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@andytwoods
andytwoods / adv_simulation.py
Last active November 17, 2022 18:47
dnd advantage vs regular vs disadvantage
import random
from collections import Counter
simulations = 1000000
def dice_roll():
return random.randint(1, 20)
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "r", function()
local current_focus = hs.application.frontmostApplication();
hs.application.launchOrFocus('Google Chrome');
local browser = hs.appfinder.appFromName('Google Chrome')
hs.timer.doAfter(.5, function()
hs.eventtap.keyStroke({"cmd"}, "r", 1000, browser);
F2::
; Save current window
WinActivate,ahk_class Chrome_WidgetWin_1
; ---------------------------------------
; Refresh Chrome
Process, Exist, chrome.exe
If(ErrorLevel) {
WinActivate, ahk_pid %ErrorLevel%
@andytwoods
andytwoods / MyValidator.py
Last active November 28, 2020 20:47
PlainASCIIUsernameValidator
@deconstructible
class PlainASCIIUsernameValidator(validators.RegexValidator):
regex = good_username_regex
message = _(
'Enter a valid username. This value may contain only English letters and numbers'
)
flags = re.ASCII
def random_username():
return uuid.uuid4().hex[:username_max_length]
@andytwoods
andytwoods / tobrowser.py
Created September 18, 2020 13:49
django testing, open a response in a browser
import tempfile
import webbrowser
import time
def tobrowser(response):
html_txt = response.content.decode("utf-8")
tmp = tempfile.NamedTemporaryFile(delete=False)
path = tmp.name + '.html'
f = open(path, 'w')
@andytwoods
andytwoods / MinimalSplitDateTimeMultiWidget.py
Last active March 21, 2023 21:09
Django splitDateTime widget, no JS, using modern HTML for time and date selectors
from datetime import datetime
from django.utils.timezone import make_aware
from django.forms import TextInput, MultiWidget, DateTimeField
# nightmare discussion here https://stackoverflow.com/questions/38601/using-django-time-date-widgets-in-custom-form
class MinimalSplitDateTimeMultiWidget(MultiWidget):
def __init__(self, widgets=None, attrs=None):
if widgets is None:
@andytwoods
andytwoods / django_bootstrap4_pagination.html
Last active June 11, 2020 14:22
django bootstrap 4 pagination using fontawesome 4
{% if is_paginated %}
<div class="col-12 text-center mx-auto ">
<div class="btn-group text-center" role="group">
<a class='btn btn-secondary'
{% if page_obj.has_previous %}href="?page={{ page_obj.previous_page_number }}"
{% else %} disabled
{% endif %}>
<i class="fal fa-angle-double-left"></i>
</a>
# USAGE
# python multi_object_tracking_fast.py --prototxt mobilenet_ssd/MobileNetSSD_deploy.prototxt --model mobilenet_ssd/MobileNetSSD_deploy.caffemodel --video race.mp4
# import the necessary packages
from imutils.video import FPS
import multiprocessing
import numpy as np
import argparse
import imutils
import dlib
@andytwoods
andytwoods / eyetracking.py
Last active April 9, 2019 19:04
tobii_vr_custom_json_analytics
# MIT License
#
# Copyright (c) 2019 Andy Thomas Woods
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@andytwoods
andytwoods / expansion_panel_issue
Last active November 10, 2018 13:00
ExpansionPanel Issue
// instantiating the expansion panel with the below. Note the 500ms delay then adding another item.
// body: (){
// List<MinimalModel> items = [MinimalModel(),MinimalModel()];
//
// Timer(Duration(milliseconds: 500), (){
// items.add(MinimalModel()); //should be wrapped with setState
// });
//
// return ExpansionPanelIssue(items);
// }()