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 fire | |
import requests | |
from bs4 import BeautifulSoup | |
# Web scrape example using python and BeautifulSoup | |
# Setup: pip install requests beautifulsoup4 fire | |
# Run: python webscrape.py scrape | |
class WebScrape(object): | |
url = "https://www.themuse.com/advice/43-simple-habits-thatll-improve-your-life-even-if-you-just-pick-one" |
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
// Add employee.badge_number to matching person in another database collection | |
db.getSiblingDB('databaseA').getCollection('employees').find({}).forEach(function(employee1) { | |
db.getSiblingDB('databaseB').getCollection('people').update( | |
{"_id": employee1._id}, | |
{ | |
"$set": { | |
"badge_number": employee1.badge_number | |
} | |
} | |
) |
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 string | |
def is_word(match): | |
for word in open('/usr/share/dict/words', 'r'): | |
if str(word.strip().lower()) == str(match.lower()): | |
return True | |
return False |
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
x = {'a': 1, 'b': 2} | |
y = {'b': 3, 'c': 4} | |
def merge_two_dicts_python3(): | |
z = {**x, **y} | |
print(z) # {'c': 4, 'a': 1, 'b': 3} | |
def merge_two_dicts_python2(): | |
z = dict(x, **y) | |
print(z) # {'a': 1, 'c': 4, 'b': 3} |
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 unittest.mock import patch, Mock | |
from requests import Response | |
import requests | |
import unittest | |
def health_check(endpoint): | |
return requests.get(endpoint).status_code | |
class TestHealthCheck(unittest.TestCase): |
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 flask import Flask, g, request | |
from flask import render_template, redirect | |
app = Flask(__name__) | |
def after_this_request(f): | |
if not hasattr(g, 'after_request_callbacks'): | |
g.after_request_callbacks = [] | |
g.after_request_callbacks.append(f) | |
return f |
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 os | |
from pathlib import Path | |
current_dir = os.path.dirname(__file__) | |
version_file_full_path = os.path.join(current_dir, "VERSION.txt") | |
""" | |
Create and obtain version information based on environment variables: | |
* APP_MAJOR_VERSION |
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 ssl | |
from flask import json | |
from ldap3 import Server, \ | |
Connection, \ | |
SUBTREE, \ | |
ALL_ATTRIBUTES, \ | |
Tls, MODIFY_REPLACE | |
OBJECT_CLASS = ['top', 'person', 'organizationalPerson', 'user'] |
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
package main | |
import ( | |
"os" | |
"fmt" | |
"log" | |
"crypto/sha512" | |
"io/ioutil" | |
"path/filepath" | |
) |