Skip to content

Instantly share code, notes, and snippets.

View boutell's full-sized avatar

Tom Boutell boutell

View GitHub Profile
@boutell
boutell / parse-integers.ts
Created December 1, 2021 12:35
Parse out nonempty lines from a file and convert them to integers
import { readFileSync as read } from 'fs';
const input:Array<number> = read('day-1.txt', { encoding: 'utf8' })
.split('\n')
.map(line => line.trim())
.filter(line => line.length > 0)
.map(line => parseInt(line));
@boutell
boutell / index.js
Created February 7, 2021 19:23
Example of an Apostrophe migration
// in lib/modules/pet-owners/index.js
module.exports = {
extend: 'apostrophe-pieces',
name: 'pet-owner',
addFields: [
{
name: 'cat',
label: 'Cat',
type: 'string'
@boutell
boutell / static.js
Created December 31, 2012 22:39
express.static middleware must be added before any routes are added to the project, which is potentially confusing when constructing reusable modules to be added to projects as needed. I wish app.use() behaved as just another route for precedence purposes
// HOPED-FOR BEHAVIOR: both /cats.txt AND /cats/cats.txt say: Cats Static
// ACTUAL BEHAVIOR: /cats.txt says Cats Static, but /cats/cats.txt says: Main Wildcard
var express = require('express');
var fs = require('fs');
var app = express();
// Adding the static middleware at the beginning means it wins out over any routes present
// (but only interferes if the file exists)
@boutell
boutell / Dockerfile
Created January 14, 2021 15:12
PoC release asset id generation in a dockerfile
FROM node:current
WORKDIR /app
COPY myasset.js /app
RUN echo `date` > identifier
RUN cat identifier
CMD cat identifier
@boutell
boutell / crop-and-overlay-videos.js
Created December 20, 2020 05:41
Crop and overlay videos using ffmpeg, to copy and paste in space rather than time
const exec = require('child_process').execSync;
// I got coordinates using the screenshot picker in quicktime player,
// but those are scaled to my screen, not the real video. Do some
// corrective fakery
const realDimensions = [ 1920, 1080 ];
const fakeWidth = 1680;
const fakeTom = [ 1400, 0, 280, 156 ];
const fakeVideo = [ 0, 100, 1470, 760 ];
@boutell
boutell / nestedapps.js
Created December 31, 2012 22:41
Nested Express apps. The "Main Wildcard" route always beats all routes in catsApp even though it is added first with app.use. I wish app.use() had the same precedence as adding a route.
// HOPED-FOR BEHAVIOR: /cats says: Cats Home
// ACTUAL BEHAVIOR: /cats says: Main Wildcard
var express = require('express');
var app = express();
app.get('/', function(req, res) {
res.send('Main Home');
})
const fs = require('fs');
const content = fs.readFileSync('court-docket.txt', 'utf8').split(/\s*\n\s*/);
const data = {};
data.origin = readOrigin();
data.type = readType();
data.docketNumber = readDocketNumber();
data.subtype = readSubtype();
data.case = readCase();
console.log(data);
self.getCollection = function(callback) {
return self.apos.db.collection('aposCache', function(err, collection) {
if (err) {
return callback(err);
}
self.cacheCollection = collection;
return async.series({
keyIndex: function(callback) {
return self.cacheCollection.ensureIndex({ key: 1, cache: 1 }, { unique: true }, callback);
},
{
"body": [
{
"_index": "testaposdocsdefault",
"_type": "aposDoc",
"_id": "cjnyogcfp0001n3uktsbndy6m"
},
{
"type": "apostrophe-global",
"typeESExact": "apostrophe-global",
import ApostropheFieldMixin from '../mixins/ApostropheFieldMixin.js';
export default {
mixins: [ ApostropheFieldMixin ],
name: 'ApostropheStringField',
methods: {
validate(value) {
if (this.field.required) {
if (!value.length) {
return 'required';