Skip to content

Instantly share code, notes, and snippets.

View ajosanchez's full-sized avatar

Alex Sanchez ajosanchez

  • Walla Walla, WA
View GitHub Profile
@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
@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 / 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 / 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 / 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))
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']
def valid_word? word
letters = {
'e' => 12,
'a' => 9,
'i' => 9,
'o' => 8,
'n' => 6,
'r' => 6,
't' => 6,
'l' => 4,
@ajosanchez
ajosanchez / dr.html
Created June 14, 2016 19:10
dynamic html with react
<div>
<form className="ui-filterable" id="searchbar">
<input id="inset-autocomplete-input" data-type="search" placeholder="Search foods..."></input>
</form>
<ul data-role="listview" data-inset="true" data-filter="true" data-filter-reveal="true" data-input="#inset-autocomplete-input">
{Object.keys(this.state.foods).forEach((food) => {
return (
<li><a href="#">food</a></li>
);
})}
<div>
<form className="ui-filterable" id="searchbar">
<input id="inset-autocomplete-input" data-type="search" placeholder="Search foods..."></input>
</form>
<ul data-role="listview" data-inset="true" data-filter="true" data-filter-reveal="true" data-input="#inset-autocomplete-input">
{Object.keys(this.state.foods).forEach((food) => {
return (
<li><a href="#">food</a></li>
);
})}
@ajosanchez
ajosanchez / dr.html
Created June 14, 2016 19:07
dynamic html in react
<div>
<form className="ui-filterable" id="searchbar">
<input id="inset-autocomplete-input" data-type="search" placeholder="Search foods..."></input>
</form>
<ul data-role="listview" data-inset="true" data-filter="true" data-filter-reveal="true" data-input="#inset-autocomplete-input">
{Object.keys(this.state.foods).forEach((food) => {
return (
<li><a href="#">food</a></li>
);
})}