Skip to content

Instantly share code, notes, and snippets.

@cdrini
cdrini / README.md
Last active May 28, 2024 09:30
OL Component Docs Maybe

We have three types of components on Open Library:

  1. CSS Components: Components which only require a little bit of CSS. These could have a separate HTML template file in openlibrary/templates if it makes sense to have one, and will usually have a separate .less file in static/css/components. Note the .less file must then be imported from the corresponding page's .less file, E.g. static/css/page-user.less.
  2. JavaScript/JQuery components: These are components which require a small amount of functionality, or are legacy implementations. E.g. the multi-input-autocomplete. These will have a JS file in openlibrary/plugins/openlibrary/js, and an import line in openlibrary/plugins/openlibrary/js/index.js.
  3. Vue components: For new, more interactive components, we prefer to use Vue.js. These components will have a .vue file in openlibrary/components. For more info on Vue, read the README in that directory. E.g: LibraryExplorer.vue

All these components make use of BEM class notation to define the c

from dataclasses import dataclass
import web
@dataclass
class ImportRecord:
title: str
subtitle: str
...
def from_web_data(data: bytes) -> 'ImportRecord':
"""
Examples:
# Get first 20 pages
python djvu_to_single_line.py ~/Downloads/isbn_9781531610494_djvu.xml -- :20
# Get first 20 pages and last 5 pages
python djvu_to_single_line.py ~/Downloads/isbn_9781531610494_djvu.xml -- :20 -5:
"""
import xml.etree.ElementTree as ET
from typing import List
@cdrini
cdrini / index.md
Last active October 2, 2021 14:47
GIMP Python-Fu Examples

Turn on/off all layers

img = gimp.image_list()[0]  # Not sure if this gets the last image or the active image
for layer in img.layers:
    layer.visible = False
@cdrini
cdrini / Thoughts on OL server-side options.md
Created June 9, 2021 23:51
Thoughts on OL server-side options

Thoughts on OL server-side options from 2021-06-09 call with @jdlrobson

Executing vue template from the python

This is apparently an option! @jdlrobson exploring with PyMiniRacer.

Custom webpack loader to import jsdef function from python files

This is one possibility; it would allow us to keep some of the rendering logic in python, and pull it in from the JavaScript.

Node-based call-out

@cdrini
cdrini / TS Things I Like and Dislike.md
Last active January 15, 2021 23:19
TypeScript Things I Like and Dislike [DRAFT]

Note: This is a draft and not well proofread. Likely contains errors.

Things I like:

instanceof type guards

class Book { id: string }
class Film { imdbId: string }
@cdrini
cdrini / index.md
Last active September 21, 2024 06:29
Adding lodash type hinting to monaco using addExtraLib

Well that was a headache! This is certainly not an elegant solution, but it works. Hopefully someone can use these notes to save themselves a bunch of time.

Known issues:

  • This does not scale easily to any other library
  • Requires some internal knowledge of lodash's types library which might break on a lodash update

Add raw-loader and @types/lodash

npm install --save-dev @types/lodash raw-loader
const packageJson = require('./package.json');
const shrinkwrapJson = require('./npm-shrinkwrap.json');
const fetch = require('node-fetch');
const fs = require('fs');
const { execSync } = require('child_process');
const GH_API_ROOT = 'https://api.github.com';
const REPO = "internetarchive/bookreader";
async function main() {
// Make sure branching off of latest master