Skip to content

Instantly share code, notes, and snippets.

Avatar

Cody Kochmann CodyKochmann

  • Severn, MD
View GitHub Profile
@CodyKochmann
CodyKochmann / gitlab_project_variables.py
Created Jun 14, 2021
api for accessing gitlab project environment variables as a python dictionary
View gitlab_project_variables.py
#!/usr/bin/env python
# author: Cody Kochmann
# created: 2021-06-13
# license: MIT
from functools import partial
import json, logging
import requests
@CodyKochmann
CodyKochmann / sqlite_essentials.py
Last active Jun 13, 2021
My essentials for interactively working with sqlite in python.
View sqlite_essentials.py
#!/usr/bin/env python
# by: Cody Kochmann
# license: MIT
# created: 2021-06-13
import sqlite3, sys
from sqlite3 import Cursor
''' My essentials for interactively working with sqlite in python. '''
@CodyKochmann
CodyKochmann / sqlite_scraper.py
Last active May 16, 2021
sqlite scraper in python
View sqlite_scraper.py
import sqlite3, requests, sys
db = sqlite3.connect(':memory:')
cur = db.cursor()
def run(*sql):
print('running:', *sql, file=sys.stderr)
for i, row in enumerate(cur.execute(*sql)):
if i == 0:
print('result:', file=sys.stderr)
@CodyKochmann
CodyKochmann / log-views.sql
Created May 13, 2021
log parsing with sqlite
View log-views.sql
CREATE TABLE log_ingest (
id INTEGER PRIMARY KEY AUTOINCREMENT,
log TEXT UNIQUE NOT NULL,
CHECK ( instr(log, " ") )
);
-- find entry
CREATE VIEW _logs_0 AS
View sqlite-stdin-csv-processing.sh
# by: Cody Kochmann
/t/u/1/tmp.1LQUz9KguH $ echo "CREATE TABLE test(col1 TEXT, col2 INTEGER);" | tee schema.sql
CREATE TABLE test(col1 TEXT, col2 INTEGER);
/t/u/1/tmp.1LQUz9KguH $ cat schema.sql | sqlite3 test.db
/t/u/1/tmp.1LQUz9KguH $ sqlite3 test.db '.tables'
test
/t/u/1/tmp.1LQUz9KguH $ printf "col1,col2\na,1\nb,2\n" | sqlite3 test.db ".import --csv /dev/stdin test"
/t/u/1/tmp.1LQUz9KguH $ sqlite3 test.db 'select * from test'
col1|col2
a|1
@CodyKochmann
CodyKochmann / sqlite_json_demo.py
Created May 10, 2021
This script demonstrates querying json data in sqlite.
View sqlite_json_demo.py
#!/usr/bin/env python3
# by: Cody Kochmann
# created: 2021-05-10
# license: MIT
import sqlite3, json, random, string, sys, functools
''' This script demonstrates basic querying of json
@CodyKochmann
CodyKochmann / TestSqliteIPValidation.py
Last active Mar 31, 2021
This demonstrates how you can use custom functions in python to embed data validation for data types that are not currently supported by sqlite natively like ip addresses.
View TestSqliteIPValidation.py
#/usr/bin/env python3
# by: Cody Kochmann
# license: MIT
# last modified: 2021-03-31T5:39
import ipaddress, sqlite3, sys, unittest
''' This demonstrates how you can use custom
functions in python to embed data validation
for data types that are not currently supported
@CodyKochmann
CodyKochmann / coreos-install-kvm.sh
Created Mar 11, 2021
install virsh and kvm for vm management on a fedora coreos host
View coreos-install-kvm.sh
#!/bin/bash
# installs virsh and tools for kvm on fedora coreos
# by: Cody Kochmann
# license: MIT
function remove-nfs-client(){
# this is needed if install has an issue
# with mount.nfs already existing
rpm-ostree override remove nfs-utils-coreos
}
View Makefile
# makefile for a directory based work queue
# by: Cody Kochmann
SHELL := /bin/bash
QUEUE_SERVICE_WORKDIR := ${HOME}
MKDIR := mkdir -v
# service io
View ugrep-every-commit-of
#!/bin/bash
# opens a ugrep interface to search every commit of a git repo
# by: Cody Kochmann
set -euxo pipefail
REPO="$@"
TMP_WORK_DIR=$(mktemp -d)
pushd "$TMP_WORK_DIR"
git clone "$REPO" .repo
pushd .repo