Skip to content

Instantly share code, notes, and snippets.

@adamhooper
adamhooper / README.md
Created January 22, 2016 16:59 — forked from eweitnauer/README.md
Dominant Baseline Style

Demonstrates the effect of dominant baseline for each of its possible values on text positioning in an SVG.

Each browser/ mobile browser seems to handle these a bit differently. Here are some issues:

  • Retrieving bounding boxes only works correctly after the font is loaded (and there is no easy way to find out when this happens)
  • The bounding box width does not reflect the actual extent of a text, but how far it advances the cursor. That means that in an italic letter 'f' in many fonts, part of the f will actually lie outside of the bounding box
  • The baseline-shift style does not work in FF
  • dominant-baseline values are interpreted different among browsers

All in all its best just use 'alphabetical' (which is consistent across browsers) and do any further vertical positioning by manually by using the x,y or dx,dy or the transform attributes. Also, if one needs to find out about the actual bounds of a text, one cannot rely on the getBBox() or the getBoundingClientRect() DOM methods, but has to use

@adamhooper
adamhooper / README.md
Last active September 5, 2018 22:56
Loading a PST into Overview
  1. Download a bunch of PSTs into a directory
  2. Download psts-to-files.sh and fiddle-with-rtf-bodies.rb to the same directory
  3. Install readpst
  4. chmod +x psts-to-files.sh fiddle-with-rtf-bodies.rb
  5. Run ./psts-to-files.sh
  6. Upload the files directory to www.overviewdocs.com

This works best for <20,000 emails. The scripts convert email messages to RTF to preserve formatting, and Overview can take a while to import all those files.

If you want to handle even more emails, you can upload a CSV. This takes away all attachments -- and occasionally some body text. Here's what to do:

@adamhooper
adamhooper / README.md
Created March 24, 2016 20:15
PSTs to Overview-ready CSV

To upload 1M+ emails from Outlook ".pst" files to Overview, you'll need to be comfortable on the command-line.

  1. Install LibPFF. On ubuntu, sudo apt-get install pff-tools. On anything else, you'll need to Comple from source.
  2. Download this gist's files somewhere
  3. cd to the directory where you have a bunch of .pst files
  4. Run /path/to/gist/psts-to-pffexports.sh. This will create a bunch of subfolders and files.
  5. Run /path/to/gists/pffexports-to-emails-csv.rb. This will create emails.csv.
  6. Rename emails.csv to whatever name you want to see in Overview
  7. Upload the CSV to Overview
@adamhooper
adamhooper / app__models__account.rb
Last active April 1, 2016 15:05
Active Record has_one is usually bad
class Account < ActiveRecord::Base
belongs_to :supplier
end
class Supplier < ActiveRecord::Base
end
@adamhooper
adamhooper / buggy_code.rb
Last active July 31, 2016 17:29
2016-07-31 Timeout::timeout() buggy code
require 'net/http'
require 'timeout'
require 'mysql2' # https://github.com/brianmario/mysql2
def download_to_database(url, sql_statement)
Timeout::timeout(5) do # BUG. Never do this.
res = Net::HTTP.get_response(url)
sql_statement.execute(url.to_s, res.code, res.body)
end
end
@adamhooper
adamhooper / fixed_code.rb
Last active July 31, 2020 14:01
2016-07-31 Code that avoids Timeout::timeout()
require 'net/http'
#require 'timeout'
require 'mysql2' # https://github.com/brianmario/mysql2
def download_to_database(url, sql_statement)
res = Net::HTTP.start(
url.host,
url.port,
use_ssl: url.scheme == 'https',
open_timeout: 5,
@adamhooper
adamhooper / mbox_to_overview_folder.py
Last active September 10, 2023 21:13
Convert an mbox file into a folder full of .txt and attachments. Good for uploading ~1,000 messages to Overview.
#!/usr/bin/env python3
import email.message
import mailbox
# Just ignore these lines.
# Python's mbox reader finds a way to return Messages that don't
# have these super-important methods. This hack adds them.
setattr(email.message.Message, '_find_body', email.message.MIMEPart._find_body)
setattr(email.message.Message, '_body_types', email.message.MIMEPart._body_types)
@adamhooper
adamhooper / micro-benchmark.js
Last active September 6, 2018 21:49
fs.readFileSync() reads hot tiny files much faster than fs.readFile()
#!/usr/bin/env node
'use strict'
const fs = require('fs')
const util = require('util')
const paths = []
for (let i = 1; i <= 20000; i++) {
paths.push(`small-files/${i}.txt`)
}
@adamhooper
adamhooper / fonts.conf
Last active August 6, 2018 14:12
Using font files directly within node-canvas
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir prefix="default">.</dir>
</fontconfig>