Skip to content

Instantly share code, notes, and snippets.

View ajosanchez's full-sized avatar

Alex Sanchez ajosanchez

  • Walla Walla, WA
View GitHub Profile
from multiprocessing import dummy
import requests
import pymongo
import time
# install mongo db via url below
# https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
mc = pymongo.MongoClient()
db = mc['db_name_here']
items = db['collection_name_here']
@ajosanchez
ajosanchez / load_json.py
Created November 5, 2017 19:57
load json into python
import json
articles = []
with open('people.json', 'rb') as f:
for item in f:
articles.append(json.loads(item))
@ajosanchez
ajosanchez / nlp.py
Last active November 5, 2017 20:59
extract all links which are people
from bs4 import BeautifulSoup as bs
import spacy
def hash_text(text, digits=8):
return hash(text) % (10 ** digits)
def make_edge_dict(unique_edges):
edge_dict = {}
for edge in unique_edges:
try:
@ajosanchez
ajosanchez / adjacency_list.py
Last active November 5, 2017 21:00
this makes an adjacency list and decoding dictionary
import csv
import json
def make_adjacency_list(adj_list):
graph_list = []
people = {}
for person in adj_list:
for k,v in person[1].items():
person_id = person[0].keys()[0]
graph_list.append((person_id, k))
@ajosanchez
ajosanchez / Dockerfile
Created August 20, 2020 18:38
.NET 3.1 running on Ubuntu 18.04
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install wget -y
RUN wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb && \
dpkg -i packages-microsoft-prod.deb
RUN apt-get install -y apt-transport-https && \
apt-get update && \
@ajosanchez
ajosanchez / pymongo.py
Created May 19, 2022 03:59
Pymongo Refresher
# start the mongodb with the CLI command "mongod"
# you may get an error that the data path folder doesn't exist
# use mongod --dbpath /usr/local/mongodb-data to set the new directory for your data. dir must exist before command can be run
from pymongo import MongoClient
client = MongoClient()
db = client['test-database']
# create a collection called posts