Skip to content

Instantly share code, notes, and snippets.

View mkoistinen's full-sized avatar

Martin Koistinen mkoistinen

  • Chapel Hill, NC, USA
View GitHub Profile
@mkoistinen
mkoistinen / exchange.py
Created November 24, 2023 23:46
Gift Exchange gift-chain generator
"""
This code is for generating a single, circular "loop" of names of family
members for gift giving as part of a Secret Santa tradition.
The input is a file named "family.json". The JSON file should be of a single
mapping where the keys are the family members, and the values would be a
that contains the key "group".
The purpose of the "group" is to define households of people so that this code
can prevent people within the same household getting one another as recipients.
@mkoistinen
mkoistinen / ninjaflex.ini
Created November 29, 2019 18:28
NinjaFlex Settings for Prusa MK3S
# generated by PrusaSlicer 2.1.0+ on 2019-11-29 at 18:25:13 UTC
bed_temperature = 60
bridge_fan_speed = 30
compatible_printers =
compatible_printers_condition = ! (printer_notes=~/.*PRINTER_VENDOR_PRUSA3D.*/ and printer_notes=~/.*PRINTER_MODEL_MK(2.5|3).*/ and single_extruder_multi_material)
compatible_prints =
compatible_prints_condition =
cooling = 0
disable_fan_first_layers = 1
end_filament_gcode = "; Filament-specific end gcode"
@mkoistinen
mkoistinen / Sainsmart TPU.ini
Created November 29, 2019 18:16
Sainsmart TPU for MK3S
# generated by PrusaSlicer 2.0.0+ on 2019-06-30 at 10:59:22
bed_temperature = 65
bridge_fan_speed = 40
compatible_printers =
compatible_printers_condition =
compatible_prints =
compatible_prints_condition =
cooling = 0
disable_fan_first_layers = 4
end_filament_gcode = "; Filament-specific end gcode"
@mkoistinen
mkoistinen / rate_measured.py
Created August 6, 2019 14:15
Decorator to measure call rate
# -*- coding: utf-8 -*-
import random
import json
import sys
import time
def rate_measured(report_period=10, report_function=None):
"""
@mkoistinen
mkoistinen / .gitprompt
Created September 11, 2018 21:29
Useful Base Prompt for both virtualenvs and Git
# Adds the current branch to the bash prompt when the working directory is
# part of a Git repository. Includes color-coding and indicators to quickly
# indicate the status of working directory.
#
# To use: Copy into ~/.bashrc and tweak if desired.
#
# Based upon the following gists:
# <https://gist.github.com/henrik/31631>
# <https://gist.github.com/srguiwiz/de87bf6355717f0eede5>
# Modified by me, using ideas from comments on those gists.
Verifying that "mkoistinen.id" is my Blockstack ID. https://onename.com/mkoistinen
@mkoistinen
mkoistinen / gist:2d8509b0b0be45ed76fed95f89b8596d
Created November 29, 2016 22:46
How to use allow subdomains with CORS
# Basically, since we can't use '*' as a wildcard according to the CORS spec, we need to use
# Nginx to conditionally apply it to the "right" subdomains. This should allow all subdomains
# of `yourtld.tld`.
location ~* ^.+\.(ttf|oft|eot|woff|svg)$ {
#
# NOTE: CORS standards allow a specific protocol/host combination,
# 'null', or '*' only. So, wildcard subdomains won't work.
#
# Have a look here:
class CustomPKMixin(object):
"""
Allows a normal SingleObjectMixin view.
"""
pk_field = None
def get_object(self, queryset=None):
"""
Returns the object the view is displaying.
@mkoistinen
mkoistinen / home_tags.py
Last active May 26, 2016 14:49
templatetag to get a page object by its ID
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import template
from classytags.arguments import Argument
from classytags.core import Options
from classytags.helpers import AsTag
@mkoistinen
mkoistinen / hostels.admin.py
Created May 25, 2016 02:00
Barebones Hostels App and CMSPlugin:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
from .models import Hostel, Room
class RoomInlineAdmin(admin.TabularInline):