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 datetime | |
from googleapiclient.discovery import build | |
from httplib2 import Http | |
from oauth2client import file, client, tools | |
from collections import defaultdict | |
import json | |
from googleapiclient.errors import HttpError | |
# If modifying these scopes, delete the file token.json. | |
SCOPES = 'https://www.googleapis.com/auth/calendar.readonly' |
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 alphabet_detector import AlphabetDetector | |
ALPHABET_DETECTOR = AlphabetDetector() | |
def prepare_title(title): | |
# Replace non-alphanums (allowing foreign characters) | |
result = "".join([x | |
if len(ALPHABET_DETECTOR.detect_alphabet(x)) > 0 | |
or x.isnumeric() | |
else " " for x in title.lower()]) |
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 requests | |
import json | |
def make_query(url, q, alg, field, shard_size=1000, size=25): | |
"""Get keywords relating to the input query, directly from Elasticsearch | |
Args: | |
url (str): The Elasticsearch endpoint you want to query | |
q (str): The query you want to retrieve keywords for | |
alg (str): An algorithm from https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html#_parameters |
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 sqlalchemy import create_engine | |
from sqlalchemy.engine.url import URL | |
from configparser import ConfigParser | |
import pandas as pd | |
def get_engine(config_path, database="production", **engine_kwargs): | |
'''Get a SQL alchemy engine from config''' | |
cp = ConfigParser() | |
cp.read(config_path) | |
cp = cp["client"] |
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 | |
import os | |
import json | |
TOPDIR = "path/to/opname_csv_gb/" | |
HEADER_PATH = os.path.join(TOPDIR,'DOC','OS_Open_Names_Header.csv') | |
def extract_tree(df, levels, ilvl=0): | |
lvl = levels[ilvl] | |
entities = [] |
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 pymongo | |
from pymongo import MongoClient | |
import pandas as pd | |
def mongo_to_files(usr_name, pwd, address, db_name, collection, | |
out_path='out{}-{}.json', chunk_size=10000, port=27017): | |
client = MongoClient(f'mongodb://{usr_name}:{pwd}@{address}', port) | |
db = client[db_name] | |
collection = db[collection] | |
total = collection.count() |
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
ALL_USERS="jklinger sgarasto jdjumali csleeman rleung" | |
TOPDIR=$PWD | |
for USERNAME in $ALL_USERS; | |
do | |
cd $TOPDIR | |
sudo useradd --create-home $USERNAME | |
echo "$USERNAME" | sudo passwd --stdin $USERNAME | |
sudo usermod -aG ec2-user $USERNAME | |
sudo usermod -aG wheel $USERNAME | |
sudo cp -rp $HOME/* /home/$USERNAME/ |
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
CREATE TEMPORARY TABLE tmp_skills_a | |
PRIMARY key doc_id | |
SELECT doc_id, skill_id | |
FROM skills_link_table | |
GROUP BY doc_id, skill_id; | |
CREATE TEMPORARY TABLE tmp_skills_b | |
PRIMARY key doc_id | |
SELECT doc_id, skill_id | |
FROM skills_link_table |
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 numpy as np | |
def assym(a): | |
return 1 - (np.linalg.det(0.5*(a + a.T)) / np.linalg.det(a)) | |
for a in ([[10,123,0],[123,10,0],[0,0,10]], [[10,123,0],[121,10,0],[0,0,10]], | |
[[10,123,0],[50,10,0],[0,0,10]], [[10,123,0],[0,10,0],[23,0,10]], | |
[[10,123,0],[-123,10,0],[5422,0,10]]): | |
a = np.matrix(a) | |
print(a) |
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
def do_the_other_thing(run, output): | |
def wrap(self): | |
run(self) | |
output(self) | |
return wrap | |
class A: | |
name='a' | |
def run(self): | |
pass |