Skip to content

Instantly share code, notes, and snippets.

View mhjb's full-sized avatar

Matthew Bartlett mhjb

View GitHub Profile
@mhjb
mhjb / gist:5411520
Last active December 16, 2015 09:18
Combine ranges in book index
def combine_nums(line)
line.gsub!(/(\d+), (?=(\d+))/) { # combine consecutive & identical numbers
if $2.to_i - $1.to_i == 1 # (looks-ahead so as to check
"#{$1}-" # every set of two numbers)
elsif $2.to_i == $1.to_i
""
else
"#{$1}, "
end
}
@mhjb
mhjb / library.coffee
Created February 7, 2018 00:32
clmbot library module incl Messenger list template builder
_ = require 'underscore'
stars = (n) ->
num_stars = Math.round ((n - 1) * -5) # 0 = perfect score; 1 = total mismatch
if num_stars
Array(num_stars + 1).join '★'
else
''
truncate_to_word = (string, maxLength) ->
@mhjb
mhjb / clmserver.coffee
Created February 7, 2018 00:34
webview server
http = require 'http'
_ = require 'underscore'
clm = require './clm.json'
requestHandler = (request, response) ->
id = request.url.match /\/(\d+)/
message = 'No record found'
if id and id[1]
cheerio = require 'cheerio'
fs = require 'fs'
acts_and_links = require './acts-and-links'
template = fs.readFileSync 'templates/template.html'
intro = fs.readFileSync 'templates/intro.html'
path = '../www/problems-at-school/'
error_handler = (err) -> console.log err if err
IncomingMessage {
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
@mhjb
mhjb / free-anchored-texts.js
Created January 30, 2020 23:08
Indesign script: Frees & styles all anchored texts in a document, replacing anchors with the contained text
// Modified from https://community.adobe.com/t5/indesign/release-all-anchored-objects-at-once/td-p/3807944?page=1
var items = app.activeDocument.allPageItems, count = 0
if(confirm("Okay to attempt to free the contents of ~roughly~ " + items.length + " anchored text boxes, styling them as 'Reference'?")) {
while(item = items.pop()) {
if(item.isValid &&
item.hasOwnProperty('anchoredObjectSettings') &&
item.parent instanceof Character &&
// Modified from https://community.adobe.com/t5/indesign/release-all-anchored-objects-at-once/td-p/3807944?page=1
var items = app.activeDocument.allPageItems, count = 0
if(confirm("Okay to attempt to free the contents of ~roughly~ " + items.length + " anchored text boxes, styling them as 'Reference'?")) {
if(app.activeDocument.paragraphStyles.item('Reference') == null) {
app.activeDocument.paragraphStyles.add({ name: 'Reference' });
}