Skip to content

Instantly share code, notes, and snippets.

View nackjicholson's full-sized avatar

Will Vaughn nackjicholson

View GitHub Profile
@nackjicholson
nackjicholson / app.py
Created September 21, 2018 18:16
Helpers for using pymongo and BSON types with flask server.
from flask import Flask
from .mongoflask import MongoJSONEncoder, ObjectIdConverter
from .db import get_db
def create_app():
app = Flask(__name__)
app.json_encoder = MongoJSONEncoder
app.url_map.converters['objectid'] = ObjectIdConverter
# Client sends their string, we interpret it as an ObjectId
@nackjicholson
nackjicholson / venv_activate_this.py
Created August 16, 2018 19:02
A script for loading the activate_this.py into a non `virtualenv` virtual env like `poetry` or `python -m venv`.
import argparse
import base64
import os
import zlib
from pathlib import Path
def convert(s):
b = base64.b64decode(s.encode('ascii'))
return zlib.decompress(b).decode('utf-8')
@nackjicholson
nackjicholson / commands.md
Last active October 4, 2020 06:54
Vim, tmux, things I learned

Vim

Commands

Search and replace ' with " from the current cursor postion to the end of the file.

:,$s/'/"/gc

TMUX

@nackjicholson
nackjicholson / create_cfn_stack.sh
Last active March 7, 2022 20:01
Create and cloudformation stack and wait for it to complete.
#!/usr/bin/env bash
STACK_NAME=$1
STACK_PATH=$2
if [ -z "$1" ]
then
echo "No STACK_NAME argument supplied"
exit 1
fi
@nackjicholson
nackjicholson / create_example_stack.sh
Created February 8, 2018 16:43
awscli shell script to create a cloudformation stack
#!/usr/bin/env bash
STACK_NAME=$1
if [ -z "$1" ]
then
echo "No STACK_NAME argument supplied"
exit 1
fi
@nackjicholson
nackjicholson / policy.yml
Created February 8, 2018 16:39
awscli s3 sync IAM Policy permissions
- PolicyName: "s3SyncTaskPolicy"
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- s3:DeleteObject
- s3:ListBucket
- s3:GetObject
- s3:GetBucketLocation
@nackjicholson
nackjicholson / cli.py
Created May 23, 2017 23:01
Python argparse subparser command functions with kwargs
import argparse
parser = argparse.ArgumentParser(prog='cl')
subparsers = parser.add_subparsers()
def foo(beep, boop):
print beep, boop
def bar(baz):
print baz
import yaml
import json
import pandas as pd
df = pd.DataFrame({'one': [1.0, 2.1, 3.2], 'two': [4.3, 5.4, 6.5]})
with open('df.yml', 'w') as file:
yaml.dump({'result': json.loads(df.to_json(orient='records'))}, file, default_flow_style=False)
@nackjicholson
nackjicholson / one_liners.sh
Last active August 1, 2017 17:05
docker one liners to remove all stuff
# Stop all docker process
docker stop $(docker ps -a -q)
# rm all docker containers
docker rm $(docker ps -a -q)
# rm all docker images with some selection logic
docker rmi $(docker images --format "{{.Repository}}:{{.Tag}}")
# or
@nackjicholson
nackjicholson / search-term-parse.js
Last active September 7, 2016 05:26
search term regex from the gods
// Beautiful regex patterns that parse and validate complex querystring parameter of search terms
const searchSyntaxValidationRegex = /^([^:]+:[^:]+(?:,|$))+$/;
const searchSyntaxParseRegex = /([^:]+):\(([^(]+)\)(?:,|$)/g;
/**
* Parses comma separated list of key values into an object.
*
* IN:
* title:(bar bar),content_stripped:(baz, and qux),other:(beep boop)
*