This file contains 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 copy to clipboard from IPython! | |
To install, just copy it to your profile/startup directory, typically: | |
~/.ipython/profile_default/startup/ | |
Example usage: | |
%clip hello world | |
# will store "hello world" |
This file contains 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 json | |
import requests | |
## `pip install tweepy` | |
import tweepy | |
auth = tweepy.OAuthHandler('consumer_key', 'consumer_secret') | |
auth.set_access_token('access_token_key', 'access_token_secret') | |
api = tweepy.API(auth, parser=tweepy.parsers.JSONParser()) |
This file contains 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
function getHightlightCoords() { | |
var pageIndex = PDFViewerApplication.pdfViewer.currentPageNumber - 1; | |
var page = PDFViewerApplication.pdfViewer.getPageView(pageIndex); | |
var pageRect = page.canvas.getClientRects()[0]; | |
var selectionRects = Array.apply(this, window.getSelection().getRangeAt(0).getClientRects()); | |
var viewport = page.viewport; | |
var selected = selectionRects.map(function (r) { | |
return viewport.convertToPdfPoint(r.left - pageRect.left, r.top - pageRect.top).concat( | |
viewport.convertToPdfPoint(r.right - pageRect.left, r.bottom - pageRect.top)); | |
}); |
This file contains 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 .. import app | |
from celery.utils.log import get_task_logger | |
logger = get_task_logger(__name__) | |
# logger.setLevel(logging.DEBUG) | |
@app.task(name='test.noop', bind=True) | |
def noop(self): | |
logger.info("Completing NOOP task") |
This file contains 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 functools | |
from flask import Flask, request | |
app = Flask(__name__) | |
def authenticate_mashape(func): | |
''' | |
Decorator to authenticate request with Mashape. | |
''' |
This file contains 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 redis | |
# Number of records to move at once | |
N = 10000 | |
# DB number and key | |
DB = 3 | |
KEY = 'deletion_notices' | |
source = redis.StrictRedis('<source host>', db=DB) |
This file contains 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
''' | |
Run multiple commands in parallel. | |
Run from CLI like | |
$ python purr.py commands.txt | |
where `commands.txt` is a text file containing one command per line. | |
''' | |
import subprocess |
This file contains 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 compute_p(G, weight='weight', p='p'): | |
# Undirected | |
for node in G: | |
k_n = len(G[node]) | |
if k_n > 1: | |
sum_w = sum( G[node][neighbor][weight] for neighbor in G[node] ) | |
for neighbor in G[node]: | |
edge_weight = G[node][neighbor][weight] | |
p_ij = float(edge_weight)/sum_w | |
G[node][neighbor][p] = (1-p_ij)**(k_n-1) |
This file contains 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
''' | |
(c)2016 Clayton A Davis | |
''' | |
import itertools | |
import random | |
import time | |
from html.parser import HTMLParser | |
from urllib.parse import urlparse, urljoin, unquote |
This file contains 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 math | |
from collections import namedtuple | |
def haversine_distance(origin, destination): | |
""" Haversine formula to calculate the distance between two lat/long points on a sphere """ | |
radius = 6371 # FAA approved globe radius in km | |
dlat = math.radians(destination.lat-origin.lat) | |
dlon = math.radians(destination.lng-origin.lng) |