Skip to content

Instantly share code, notes, and snippets.

View egardner's full-sized avatar

Eric Gardner egardner

View GitHub Profile
@egardner
egardner / Dockerfile
Last active January 28, 2021 17:39
Basic MW dev environment with Docker
# Put this in web/Dockerfile
# Adapted from https://github.com/wikimedia/mediawiki-docker/blob/master/1.32/Dockerfile
FROM php:7.2-apache
# System Dependencies.
RUN apt-get update && apt-get install -y \
git \
imagemagick \
libicu-dev \
@egardner
egardner / epub.rake
Last active October 22, 2018 22:05
Work in progress Epub Parser in Ruby
# lib/tasks/epub.rake
require "pathname"
namespace :epub do
desc "Import data from a target epub file"
task import: :environment do
path = Pathname.new(ARGV.last)
raise ArgumentError, "Please provide a path to a valid EPUB file." unless path.exist?
EpubParser.parse(path)
@egardner
egardner / README.md
Created August 10, 2018 19:26
HTML Unroller

HTML Unroller

This script is a basic "proof-of-concept" implementation of a parsing tool that can "unroll" or flatten an HTML document into a simple JSON representation. Inspired by the Prosemirror document model.

There are two things which allow for the simplified output:

  1. We don't care about every HTML element, just a limited "whitelist"
  2. Text-level elements are represented as a linear sequence (in a real-world version, each text item would need some kind of attributes or properties field to indicate
@egardner
egardner / README.md
Last active March 17, 2018 17:07
Vuex action test examples

Testing actions in Vuex

In Vuex, Actions are analagous to Reducers in Redux. They are functions which can contain asynchronous operations, but they do not manipulate any state in the store directly. Instead, they can only commit mutations, which are synchronous functions that replace an existing store value with a new one.

Since Actions can potentially contain some complicated logic (like deciding which mutation or series of mutations should be committed), they are a good candidate for unit tests. Here is an example of how to do this following the suggestions in the Vuex docs.

@egardner
egardner / manifest.rb
Last active September 18, 2017 23:14
Quick and dirty IIIF Manifest generator (WIP)
require 'json'
require 'fastimage'
# Quick and dirty IIIF Manifest Generator
# Initial values
# ==============================================================================
work_title = 'Concert for Piano and Orchestra: Solo for Piano'
work_author = 'John Cage'
work_publisher = 'Stony Point, N.Y.: Herman Press, c1960'
@egardner
egardner / titles.txt
Created August 15, 2017 22:09
Pubs Repo: Editions with diverging catalog_copy and jacket_copy
A Confederacy of Heretics -- 1st English Paperback Edition
A King Seen from the Sky -- 1st English Hardcover Edition
A Kingdom of Images -- 1st English Hardcover Edition
A Pocket Dictionary of Aztec and Mayan Gods and Goddesses -- 1st English Hardcover Edition
A Royal Passion -- 1st English Hardcover Edition
AD410 -- 1st English Hardcover Edition
Adolph Menzel -- 1st English Hardcover Edition
Amber and the Ancient World -- 1st English Hardcover Edition
American Painters on Technique -- 1st English Hardcover Edition
An ABC of What Art Can Be -- 1st English Hardcover Edition
@egardner
egardner / .babelrc
Created June 1, 2017 14:18
ESLint Files
{
"presets": ["babel-preset-expo"],
"env": {
"development": {
"plugins": ["transform-react-jsx-source"]
}
}
}
@egardner
egardner / App.js
Created June 1, 2017 00:02
Simple React Native app
import React from 'react';
import { StyleSheet, Text, View, WebView } from 'react-native';
import { TabNavigator } from 'react-navigation';
import Icon from 'react-native-vector-icons/SimpleLineIcons';
// Icons & styles
//
const homeIcon = (<Icon name="home" size={24} />);
const globeIcon = (<Icon name="globe-alt" size={24} />);
const recentIcon = (<Icon name="rocket" size={24} />);
@egardner
egardner / deepequal.js
Created May 22, 2017 00:21
Simple deep equality comparison in Javascript (ES5+)
// Deep Equality comparison example
//
// This is an example of how to implement an object-comparison function in
// JavaScript (ES5+). A few points of interest here:
//
// * You can get an array of all an object's properties in ES5+ by calling
// the class method Object.keys(obj).
// * The function recursively calls itself in the for / in loop when it
// compares the contents of each property
// * You can hide a "private" function inside a function of this kind by
@egardner
egardner / app.js
Created January 17, 2017 04:06
Feedr AJAX request example
//
// URLs: let's stash these here and access later
//
var breitbartUrl = 'https://api.rss2json.com/v1/api.json?rss_url=http%3A%2F%2Ffeeds.feedburner.com%2Fbreitbart';
var foxUrl = 'https://api.rss2json.com/v1/api.json?rss_url=http%3A%2F%2Ffeeds.foxnews.com%2Ffoxnews%2Fpolitics';
var nytUrl = 'https://newsapi.org/v1/articles?source=the-new-york-times&sortBy=top&apiKey=08d58f2f94b0426e856bb17cb5a7657b'
$(document).ready(function(){
//
// Let's stash our container div as a variable here so we can access it