Skip to content

Instantly share code, notes, and snippets.

@kunanit
kunanit / trial_component_search.py
Created December 20, 2019 21:09
Get unassigned trial components in sagemaker experiments
# sm = boto3.Session().client('sagemaker')
response = sm.search(
Resource='ExperimentTrialComponent',
SearchExpression={
'Filters': [
{
'Name': 'Parents.ExperimentName',
'Operator': 'NotExists',
}
@kunanit
kunanit / bucket_policy.json
Created November 20, 2019 17:26
S3 bucket policy example for cross-account access
{
"Version": "2008-10-17",
"Id": "CrossAccountAccessExample",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789123:user/admin"
},
"Action": [
import datetime
import luigi
import hashlib
from collections import defaultdict
import json
from os.path import join
# luigi --module tasks ReportStep --local-scheduler
# clean up: rm data/output_*
@kunanit
kunanit / gist:6ac27276e6ccc10e34e02309ab39303a
Created August 2, 2018 18:50
Generate slice for every 100th revision
gdoc = gdocrevisions.GoogleDoc(...)
slices = [] # save things here
gdoc.content.reset() # reset document
for i, revision in enumerate(gdoc.revisions):
gdoc.content.apply(revision) # apply revision
if i%100==1: # every 100th revision
slices.append(gdoc.content.render()) # save document state to slices
from google.oauth2 import service_account
from google_auth_oauthlib.flow import InstalledAppFlow
def get_oauth2_credentials(client_secrets_file, port=5555, scopes=SCOPES):
"""
Get google credentials via oauth flow
Opens up a browser for user to sign in
Requires client secrets file (select application type = 'other' when creating client in google console)
Sets default local web server port to 5555, since 8080 not usually available locally, but port can be specified as
@kunanit
kunanit / gist:7538f6f584d1813601933401851daa70
Last active April 19, 2018 18:53
Generate google credentials
from google.oauth2 import service_account
from google_auth_oauthlib.flow import InstalledAppFlow
SCOPE = ['https://www.googleapis.com/auth/drive'] # example scope
def get_google_credentials_oauth2(client_secrets_file, port=5555):
"""
get credentials via oauth flow
@kunanit
kunanit / ecs.py
Last active February 7, 2020 16:39
Django settings for ECS (awsvpc network mode)
"""
AWS ECS django settings
"""
import requests
from .settings import * # may look different for your project
def get_ecs_task_ips():
"""
@kunanit
kunanit / delete_awslogs_agent_state
Created February 6, 2018 17:18
Elastic Beanstalk .ebextensions config file that ensures awslogs agent monitors newest log file created on deploy
# 99_delete_awslogs_agent_state.sh: deletes awslogs agent state file so that
# agent starts monitoring logs for the most recently created container
files:
/opt/elasticbeanstalk/hooks/appdeploy/post/99_delete_awslogs_agent_state.sh:
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
@kunanit
kunanit / .gitignore
Created December 6, 2017 18:18
Example gitignore file that ignores all contents of containing folder
# stick this file inside a folder whose contents you want to git ignore
[^.]*
import pandas as pd
from sqlalchemy import create_engine
from datetime import date
from s3fs import S3FileSystem
def create_db_engine(database=None,user=None,password=None,host=None,port=5432):
"""
Create sqlalchemy postgres engine from settings
"""