Skip to content

Instantly share code, notes, and snippets.

@squarepegsys
squarepegsys / to_csv.py
Created Aug 4, 2021
Generic pydemic object to CSV export
View to_csv.py
# assumptions:
# mappings is a list of pydentic objects extending BaseModel - https://pydantic-docs.helpmanual.io
# filename is the filename you want to export to
import csv
from pathlib import Path
def out_mapping(filename: str, mappings: List):
out_csv = Path(filename)
@squarepegsys
squarepegsys / 002_auto.py
Last active Aug 20, 2020
creating a large data insert in a django migration
View 002_auto.py
# Generated by Django 3.1 on 2020-08-19 15:28
from django.db import migrations
from pathlib import Path
import csv
from django.db import transaction
def parse_file(apps, schema_editor):
@squarepegsys
squarepegsys / s3ctl.py
Created Sep 20, 2019
wrapper around s3cmd
View s3ctl.py
#!/usr/bin/env python
import sys
import subprocess
def get_profile_credentials(profile_name):
# stolen from https://gist.github.com/wjimenez5271/defeede8eb4a63afc9d8
from configparser import ConfigParser
View gist:1297b630c7e547c6f253c7498552e43a
### Keybase proof
I hereby claim:
* I am squarepegsys on github.
* I am nerddad42 (https://keybase.io/nerddad42) on keybase.
* I have a public key ASBJ0AeDZngh0-lXLOLZL9gK0n9trGUjef7PqD4MCp0A_Qo
To claim this, I am signing this object:
View keybase.md

nerddad42

Keybase proof

I hereby claim:

  • I am squarepegsys on github.
  • I am nerddad42 (https://keybase.io/nerddad42) on keybase.
  • I have a public key ASDy96rNpiGAp0TOkSZqQocGDZA7aE5XT-yDDzHFqiC_Kgo

To claim this, I am signing this object:

@squarepegsys
squarepegsys / get_aws_log
Created May 17, 2019
search and show wrapper around awslogs
View get_aws_log
#!/bin/bash
# Quick and dirty script to find the log and show it via https://github.com/rpgreen/apilogs
# basically this automates the work I would do 90% of the time
if [ -z "$1" ]
then
echo "no stream supplied!"
exit 13
fi
group=`awslogs groups|grep $1`
@squarepegsys
squarepegsys / some_report.py
Last active Feb 24, 2019
Dynamic Header in ReportLab
View some_report.py
from functools import partial
# lots of other imports, esp for reportlab
# this function is ran for each page.
def some_header(canvas,doc,content):
canvas.saveState()
P = Paragraph(content,style=some_style)
@squarepegsys
squarepegsys / pick_thread_user.py
Created Jan 25, 2019
Quick and dirty script to randomly choose a user from a forum thread at BGG
View pick_thread_user.py
#!/usr/bin/env python
import xml.etree.ElementTree as ET
from urllib.request import urlopen
import random
import time
def seed():
t = int( time.time() * 1000.0 )
@squarepegsys
squarepegsys / mvn2gradle.py
Created Jul 5, 2018
Convert maven deps to gradle format
View mvn2gradle.py
#!/usr/bin/env python
import xml.etree.ElementTree as ET
ns = {'pom': "http://maven.apache.org/POM/4.0.0" , }
def find_exclusions(exclusions):
@squarepegsys
squarepegsys / build.gradle
Last active Jul 5, 2018
snapshots and gradle
View build.gradle
// shamelessly stolen from https://discuss.gradle.org/t/preferred-way-to-publish-snapshots-releases-to-artifactory/20246/2
// all I need to do it set -PreleaseVersion in the build
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'java'
apply plugin: 'maven-publish'
//..
if (project.properties.containsKey("releaseVersion")) {
version = version.split(/-/)[0]