Skip to content

Instantly share code, notes, and snippets.

View mekarpeles's full-sized avatar
📚
Universal Access to All Knowledge

Mek mekarpeles

📚
Universal Access to All Knowledge
View GitHub Profile
@mekarpeles
mekarpeles / ol_api_header_example.py
Created May 22, 2024 15:59
python example of adding app identification headers to openlibrary.org API calls
import requests
url = "https://openlibrary.org/search.json?q=test"
headers = {
"User-Agent": "MyAppName/1.0 (myemail@example.com)"
}
response = requests.get(url, headers=headers)
@mekarpeles
mekarpeles / ol_api_header_example.js
Created May 22, 2024 15:58
js example of adding app identification headers to openlibrary.org API calls
const url = "https://openlibrary.org/search.json?q=test";
const headers = new Headers({
"User-Agent": "MyAppName/1.0 (myemail@example.com)"
});
const options = {
method: 'GET',
headers: headers
};
fetch(url, options)
.then(response => response.json())
@mekarpeles
mekarpeles / git-walkthrough.md
Last active April 22, 2024 17:40
Git aWalkthrough: The ins-and-outs of git

Git Walkthrough

This guide provides a walkthrough of a basic git workflow and attempts to describe what is happening under the hood as commands are run.

  1. We can create a new git repository using git init which creates a hidden directory called .git/
  • The init process fills .git/ with a special file called HEAD that contains the name of the branch or the commit we're on
  • If the contents of the HEAD file is the name of a branch, then we can look in .git/refs/heads/<branchname> e.g. .git/refs/heads/main to figure out the specific commit the branch is on: e.g. ba012fe642b796af4e5735a7e6c83e4e90f9e62b
  • When we first start out, HEAD is likely the main branch which maps to a nil (non-existant) commit
  1. We can stage files to be committed to a checkpoint by using the command: git add and then commit them using git commit -"message".
@mekarpeles
mekarpeles / gutenberg-api.md
Last active October 13, 2023 00:38
Project Gutenberg API
@dataclass
class ImportRecordSchema:
...
class ImportRecord:
def __init__(self, **data):
self.data = ImportRecordSchema(data)
self.validate() # include promise item check, or raise exceptions
self.edition_key = self.find_matching_edition()
self.edition = self.edition_key and web.ctx.site.get(self.edition_key)
@mekarpeles
mekarpeles / goodreads-rss-to-ol-query
Created January 23, 2023 22:29
goodreads rss to ol query
var isbnList = []
fetch("https://www.goodreads.com/review/list_rss/118293813?shelf=%23ALL%23")
.then(response => response.text())
.then(data => {
let parser = new DOMParser();
let xmlDoc = parser.parseFromString(data, "application/xml");
let isbnTags = xmlDoc.getElementsByTagName("isbn");
for (let i = 0; i < isbnTags.length; i++) {
if (isbnTags[i].innerHTML !== "") {
isbnList.push(isbnTags[i].innerHTML);
import requests
"""
- ✅ Show English editions of each
- ✅ Show IA editions of each
- ✅ Show most readable edition
- ❌ They should be in order of publication
- ✅ searching for "chambre des secrets" should
- ✅ Show HP2 somewhere
- ✅ Show French HP2 edition/title
function getBooks(container) {
const reISBN = /((978)?[0-9][0-9]{10}[0-9xX])|((978)?[0-9]{9}[0-9Xx])/;
const elements = document.getElementsByClassName(container);
let isbnElementMap = {};
for (let i=0; i<elements.length; i++) {
let e = elements.item(i);
let match = e.innerHTML.match(reISBN);
if (match) {
isbnElementMap[match[0]] = e;
}
@mekarpeles
mekarpeles / mostrecommendedbooks.js
Created July 20, 2021 23:38
Example of adding Open Library borrow buttons to mostrecommendedbooks.com
function getBooks(container) {
const reISBN = /((978)?[0-9][0-9]{10}[0-9xX])|((978)?[0-9]{9}[0-9Xx])/;
const elements = document.getElementsByClassName(container);
let isbnElementMap = {};
for (let i=0; i<elements.length; i++) {
let e = elements.item(i);
let match = e.innerHTML.match(reISBN);
if (match) {
isbnElementMap[match[0]] = e;
}
@mekarpeles
mekarpeles / book-tags-schema.json
Last active June 27, 2021 18:03
Community Book Tags Schema
{
"categories": [
"pace", "length", "accuracy", "clarity", "enjoyability",
"difficulty", "structure", "type", "impact"
],
"observations": [
{
"label": "pace",
"description": "What is the pace of this book?",