This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import boto3 | |
client = boto3.client('batch') | |
i = 0 | |
for job in client.list_jobs(jobQueue="HighPriority", jobStatus="RUNNABLE")["jobS | |
ummaryList"]: | |
i+=1 | |
print(job["jobId"]) | |
client.terminate_job(jobId=job["jobId"], reason="Too slow") | |
time.sleep(0.2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def chunks(whole, n_chunks): | |
'''Randomly chunk up an iterable''' | |
# Make sure that it makes sense to chunk up the object | |
if n_chunks > len(whole) or n_chunks <= 0: | |
yield whole | |
return | |
# Copy the iterable (we'll delete it later anyway) and shuffle it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Note: THIS IS NOT A SHELL SCRIPT | |
cd /dev/shm | |
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh | |
bash Miniconda3-latest-Linux-x86_64.sh | |
<LOG OUT AND IN> | |
conda create --name py36 python=3.6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from sqlalchemy import create_engine | |
from sqlalchemy.sql import text as sql_text | |
from collections import defaultdict | |
with open('/Users/jklinger/Nesta-AWS/AWS-RDS-config/open-academic-graph.config') as f: | |
host, port, database, user, password = f.read().split(':') | |
database_uri = 'postgresql://{}:{}@{}/{}'.format(user, password, host, "microsoft_academic_graph") | |
con = create_engine(database_uri) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<!-- The search bar --> | |
<input type='text' id="query_data"/> | |
<button onclick="hitAPI()"> Submit </button> | |
<br> | |
<!-- Where the response will end up --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import chain, combinations | |
def all_subsets(n): | |
return chain(*map(lambda x: combinations(range(0,n), x), range(2, n+1))) | |
def subset_matrix(n): | |
rows = [] | |
for subset in all_subsets(n): | |
new_row = [0]*n | |
for i in subset: | |
new_row[i] = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''Getting all documents from an Elasticsearch database. | |
Note this method doesn't rank results in any way. For that, you should | |
use the search API, and accept that you will get the top N results.''' | |
from elasticsearch.helpers import scan | |
from elasticsearch import Elasticsearch | |
ENDPOINT = "" # <=== Enter an endpoint URI here | |
es = Elasticsearch(ENDPOINT, index="rwjf", doc_type="world_reporter") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
import pandas as pd | |
from io import BytesIO | |
bucket, filename = "bucket_name", "filename.csv" | |
s3 = boto3.resource('s3') | |
obj = s3.Object(bucket, filename) | |
with BytesIO(obj.get()['Body'].read()) as bio: | |
df = pd.read_csv(bio) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
import json | |
from io import StringIO | |
s3 = boto3.resource("s3") | |
data = [{"a":1, "c":3},{"b":2}] | |
s3_obj = s3.Object(<BUCKET NAME>, <FILE MAME>) | |
s3_obj.put(Body=json.dumps(data)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
import pandas as pd | |
from io import BytesIO | |
bucket = "innovation-mapping-general" | |
directory = "nih_all_processed_data/" | |
s3 = boto3.resource('s3') | |
dfs = [] | |
for key in s3.Bucket(bucket).objects.all(): | |
if not key.key.startswith(directory): |