Skip to content

Instantly share code, notes, and snippets.

View vernondcole's full-sized avatar

Vernon Cole vernondcole

View GitHub Profile
@vernondcole
vernondcole / restart_your_minion.sls
Last active March 28, 2023 20:43
SaltStack state to restart a minion (using the minion you are restarting)
---
# salt state file for restarting a minion under its own control
{% set delay = salt['config.get']('minion_restart_in_seconds', 5) %}
restart-the-minion:
file.managed:
- name: /tmp/run_command_later.py
- source: salt://run_command_later.py
- mode: 775
@vernondcole
vernondcole / 0008_data_migrate.py
Created May 22, 2015 18:45
how to do a django data migration on a massive Postgres data table
#!/usr/bin/python3
# this migration will call itself as a command-line program.
from __future__ import unicode_literals, print_function
import datetime, subprocess, psycopg2, sys, time
from django.db import migrations
from django.conf import settings
CHUNK_SIZE = 1000
def call_yourself(apps, schema_editor):
@vernondcole
vernondcole / phi.py
Created April 18, 2014 21:54
Insane Decimal Math -- 624 digits of Phi
""" Really exercise the Decimal Math processor.
Calculates two weird identities of the irrational number Phi using an insane number of digits.
Phi**2 + Phi**-2 == 3
8 * Phi**2 - Phi**6 == 3
"""
from __future__ import print_function
digits = ("1.61803398874989484820458683436563811772030917980576286213544862270526046281890"
"244970720720418939113748475408807538689175212663386222353693179318006076672635"
@vernondcole
vernondcole / storedproctest.py
Last active August 29, 2015 14:00
stored procedure test for PEP-249 db-api operation
#
# The following is a snippit from the unit test for adodbapi.
#
# this code is for Microsoft SQL server -- I tried writing stored procedurs for MySQL and PostgreSQL, but failed.
#
# Please reply to me by sending me some actually valid stored procedurse for those engines.
#
# Thanks!
#
# {Yes, I know bare "assert" statements are old hat. The code has worked like that since 2002. I did not write it. Feel free to edit.}