Skip to content

Instantly share code, notes, and snippets.

View iarp's full-sized avatar

Ian R-P iarp

  • Toronto, Ontario, Canada
View GitHub Profile
@iarp
iarp / a_reusable_celery.py
Last active August 26, 2019 16:12
Include celery tasks in a reusable django app without knowing the project name.
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', settings.SETTINGS_MODULE)
project = '.'.join(settings.SETTINGS_MODULE.split('.')[:-1])
@iarp
iarp / postgres backup.sh
Last active October 3, 2019 00:54
Used to crontab backup a postgres database
TIMESTAMP=$(date +%Y-%m-%d-%H.%M.%S)
TMP_DIR="/tmp"
BACKUP_DIR="/home/iarp/backups"
DATABASE="orhc_tryouts"
USERNAME="orhc_tryouts"
HOSTNAME="localhost"
echo "Backing up $DATABASE"
@iarp
iarp / backup.sh
Last active February 7, 2021 17:52
unraid mirroring script
# trap ctrl-c and call ctrl_c()
trap ctrl_c INT
function ctrl_c() {
exit
}
# check if there are arguments
if (( $# > 0 )); then
@iarp
iarp / celery-beat.conf
Last active March 2, 2018 22:54
Supervisord Setup for django celery worker
[program:celery-beat]
command=/home/iarp/venv-folder/bin/celery -A django_forms beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler
directory=/home/iarp/site-root
user=iarp
numprocs=1
stdout_logfile=/home/iarp/celery.beat.log
stderr_logfile=/home/iarp/celery.beat.log
autostart=true
autorestart=true
startsecs=10
@iarp
iarp / ddwrt-delete-traffic.sh
Last active October 10, 2019 02:41
THIS IS AN OLD SCRIPT! I have not used it in many years as I haved moved onto pfSense. The purpose was to remove traffic information from my WRT54GL because the memory had filled up.
#!/bin/sh
# Delete traffic data leaving X number of months, includes current month
# If command line parameter is not provided then default to 1, which keeps current month only
if [ $1 -gt 0 ]; then i=$1; else i=1; fi
# Get current date in a format compatable with the date -d switch
d=`date +%Y.%m.%d-%H:%M`
# Loop back through the calendar X number of months
# each iteration lands at the last day of the previous month
while [ $i -gt 0 ]; do
d=$(date -D %s -d $(( $(date -d $d +%s)-( $(date -d $d +%d)*86400))) +%Y.%m.%d-%H:%M)
@iarp
iarp / logoff.bat
Created July 2, 2017 00:00
Disconnect RDP from a Windows machine, sending the system back to console so that LogMeIn Hamachi doesn't go offline.
# This script locks the server, disconnects you from the servers RDP session
# sending the session back to console so hamachi does not get disconnected
tscon 0 /dest:console
tscon 1 /dest:console
tscon 2 /dest:console
Rundll32.exe User32.dll,LockWorkStation
@iarp
iarp / CustomDjangoJSONSerializer.py
Last active June 21, 2017 22:13
I needed requests.session to store various datatypes int, float, and datetime. JSON by default does not do that, it converts everything to string and during load it leaves them as strings. This class takes the data and converts the various datatypes into strings (prepended by another string defining its type). During load, it reconverts the data…
import json
from django.contrib.sessions.serializers import BaseJSONSerializer
import traceback
import datetime
class CustomJSONSerializer:
"""
value type to string format
@iarp
iarp / gist:9a07561a3b79ed2c7c2e
Last active August 29, 2015 14:06
Backup all USER mysql databases into separate folders, file names are timestamped to the second. Tar the www directory for said database if it exists.
#! /bin/bash
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
BACKUP_DIR="/home/dev/backups"
MYSQL_USER="root"
MYSQL=/usr/bin/mysql
MYSQL_PASSWORD="password"
MYSQLDUMP=/usr/bin/mysqldump
mkdir -p "$BACKUP_DIR"
@iarp
iarp / mw-excel-mwtable.py
Created March 5, 2014 01:25
Convert Excel tables into MediaWiki formatted tables.
import os
# Open pasted-data.txt file, read the contents.
# You could potentially change this to reading the clipboard, and then writing the clipboard with the table.
with open('pasted-data.txt', 'r') as text:
data = text.readlines()
# If the first line is blank, remove it and set blank to True.<br /># If data[0] throws an error, we were passed nothing. Exit.
blank = None
try:
@iarp
iarp / QuoteCommaExport.vb
Last active June 29, 2016 15:56
Proper Excel CSV Export Macro
Sub QuoteCommaExport()
' Dimension all variables.
Dim DestFile As String
Dim FileNum As Integer
Dim ColumnCount As Long
Dim RowCount As Long
' Prompt user for destination file name.
DestFile = InputBox("Enter the destination filename" _
& Chr(10) & "(with complete path):", "Quote-Comma Exporter", "C:\temp\")