Skip to content

Instantly share code, notes, and snippets.

@andytwoods
andytwoods / LICENSE-MIT
Last active March 27, 2024 21:04 — forked from electricg/LICENSE-MIT
Stopwatch in javascript
Copyright (c) 2010-2015 Giulia Alfonsi <electric.g@gmail.com>
Modified work Copyright 2017 Andy 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
@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 / 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%
# 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 / 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 / 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>
@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: