Skip to content

Instantly share code, notes, and snippets.

View IanMulvany's full-sized avatar
💭
yak shaving.

Ian Mulvany IanMulvany

💭
yak shaving.
View GitHub Profile
set now to (current date)
-- midnight this morning
set today to now - (time of now)
-- midnight tomorrow morning
set future to (today) + (336 * 60 * 60)
tell application "Calendar"
-- delete existing events in Sage Copy calendar
import requests as r
import responses # type: ignore
from requests import Response
"""
This sample code provides two test functions, one using responses, the other does not.
If you run this code whilst online, both test functions will pass, but if you attempt
to run this script whilst offline, only the test function using responses will succeed,
demonstrating that we have managed to mock the API call successfully.
function respondToFormSubmit(e) {
var settings = PropertiesService.getDocumentProperties();
var authInfo = ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL);
// Check if the actions of the trigger require authorizations that have not
// been supplied yet -- if so, warn the active user via email (if possible).
// This check is required when using triggers with add-ons to maintain
// functional triggers.
if (authInfo.getAuthorizationStatus() ==
ScriptApp.AuthorizationStatus.REQUIRED) {
from glob import glob
def get_note_title(filename):
title = filename.split(".")[0]
return title
files = glob("nv-bear-import/*")
for f in files:
title = get_note_title(f.replace("nv-bear-import/",""))
with file(f, 'r') as original: data = original.read()
import random
from collections import defaultdict
attendees = ["nathan", "chris"]
run_number = 1000
attendees_result = defaultdict(int)
for i in range(run_number):
attendees_result[random.choice(attendees)] +=1
import requests
import credentials as creds
customer_endpoint = "https://api.dlcs.io/customers/12"
r = requests.get(customer_endpoint, auth = (creds.KEY, creds.SECRET))
print r.status_code
print r.text
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
<channel>
<title>eLife</title>
<link>http://elifesciences.org/rss/recent.xml</link>
<atom:link rel="self" type="application/rss+xml" href="http://elifesciences.org/rss/recent.xml"/>
<description>Articles published in eLife</description>
<pubDate/>
<language>en</language>
<item>
mkdir test_data_extraction
cd test_data_extraction
git clone https://github.com/elifesciences/elife-articles.git
sudo STATIC_DEPS=true pip install lxml==3.4.1
pip install elifetools
git clone https://gist.github.com/a47afc60d30d22bed33d.git
cp a47afc60d30d22bed33d/demo-data-extraction.py .
from elifetools import parseJATS as parser
import glob
articles = glob.glob("elife-articles/*.xml")
def data_components(articles):
for article in articles:
soup = parser.parse_document(article)
print parser.media(soup)
def titles(articles):
...
[]
[{'mimetype': u'application', 'parent_ordinal': 1, 'sibling_ordinal': 1, 'parent_type': 'supplementary-material', 'mime-subtype': u'pdf', 'xlink_href': u'elife00067s001.pdf', 'ordinal': 1, 'position': 1, 'parent_component_doi': u'10.7554/eLife.00067.017', 'parent_sibling_ordinal': 1, 'type': 'media', 'parent_asset': 'supp'}]
[{'mimetype': u'application', 'parent_ordinal': 1, 'sibling_ordinal': 1, 'parent_type': 'supplementary-material', 'mime-subtype': u'xls', 'xlink_href': u'elife00068s001.xls', 'ordinal': 1, 'position': 1, 'parent_component_doi': u'10.7554/eLife.00068.026', 'parent_sibling_ordinal': 1, 'type': 'media', 'parent_asset': 'supp'}]
[{'mimetype': u'application', 'parent_ordinal': 1, 'sibling_ordinal': 1, 'ordinal': 1, 'p_parent_type': 'fig', 'parent_type': 'supplementary-material', 'mime-subtype': u'xlsx', 'p_parent_ordinal': 4, 'xlink_href': u'elife00070s001.xlsx', 'p_parent_component_doi': u'10.7554/eLife.00070.006', 'position': 1, 'p_parent_sibling_ordinal': 4, 'parent_component_doi': u