Skip to content

Instantly share code, notes, and snippets.

View paulkaplan's full-sized avatar

Paul Kaplan paulkaplan

View GitHub Profile
@paulkaplan
paulkaplan / README.md
Created January 10, 2018 19:43 — 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

@paulkaplan
paulkaplan / bookmarklet.js
Created October 23, 2015 14:25
Customized stats.js bookmarklet
javascript:(function() {
var script = document.createElement('script');
script.onload = function() {
/* Remove existing stats if it exists */
var existingStatsElement = document.getElementById('stats');
if (existingStatsElement) {
existingStatsElement.parentNode.removeChild(existingStatsElement);
@paulkaplan
paulkaplan / ascii_stl_writer.js
Last active November 17, 2021 17:32
ascii_stl_writer.js
// Written by Paul Kaplan
var AsciiStlWriter = (function() {
// ASCI STL files
function stringifyVector(vec){
return ""+vec.x+" "+vec.y+" "+vec.z;
}
function stringifyVertex(vec){
@paulkaplan
paulkaplan / binary_stl_writer.js
Last active November 17, 2021 17:32
Writing binary and ascii STL files in Javascript
// Written by Paul Kaplan
var BinaryStlWriter = (function() {
var that = {};
var writeVector = function(dataview, offset, vector, isLittleEndian) {
offset = writeFloat(dataview, offset, vector.x, isLittleEndian);
offset = writeFloat(dataview, offset, vector.y, isLittleEndian);
return writeFloat(dataview, offset, vector.z, isLittleEndian);
};
@paulkaplan
paulkaplan / yosemite_fixes.sh
Created October 18, 2014 15:50
Fixing dev environment on Yosemite
# xcode command line tools are gone
# reinstall them
xcode-select --install
# Pow is broken, update to 0.5.0
curl get.pow.cx | sh
# PG is broken, Yosemite removes needed dirs
# http://stackoverflow.com/questions/25970132/pg-tblspc-missing-after-installation-of-os-x-yosemite-beta
mkdir /usr/local/var/postgres/pg_tblspc
@paulkaplan
paulkaplan / text_input.coffee
Last active August 29, 2015 14:05
React input component in Coffeescript
TextInput = React.createClass
propTypes:
className: React.PropTypes.string,
id: React.PropTypes.string,
placeholder: React.PropTypes.string,
onSave: React.PropTypes.func.isRequired,
value: React.PropTypes.string
getInitialState: ->
value: @props.value or ''
@paulkaplan
paulkaplan / arduino_ir_receiver.ino
Last active August 29, 2015 14:04
Record incoming IR pulses with an IR Receiver on an Arduino
/* Raw IR decoder sketch!
This sketch/program uses the Arduno and a PNA4602 to
decode IR received. This can be used to make a IR receiver
(by looking for a particular code)
or transmitter (by pulsing an IR LED at ~38KHz for the
durations detected
Code is public domain, check out www.ladyada.net and adafruit.com
for more tutorials!
@paulkaplan
paulkaplan / spark-request.m
Last active August 29, 2015 14:03
Getting started with remote function calls on Spark Core
- (void) makeSparkRequest {
NSString *sparkApi = @"https://api.spark.io/v1/devices";
NSString *deviceId = @"<YOUR_DEVICE_ID>";
NSString *functionName = @"<YOUR_FUNCTION_NAME>"; // registered to cloud using Spark.function("FUNCTION_NAME", FUNCTION);
NSString *accessToken = @"<YOUR_ACCESS_TOKEN>";
NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:@"%@/%@/%@\?access_token=%@",
sparkApi,
deviceId,
@paulkaplan
paulkaplan / demo.html
Last active August 29, 2015 13:56
Tiny jQuery plugin to make walkthroughs
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="walkthrough.js"></script>
<link rel="stylesheet" href="walkthrough.css" />
<body>
<div class='walkthrough-container'>
<div class="walkthrough-steps">
<div
@paulkaplan
paulkaplan / Shapeoko_inch.pp
Created January 10, 2014 18:29
Vectric configuration file for Shapeoko (inch, with arcs)
+================================================
+
+ Vectric machine output configuration file
+
+================================================
+
+ History
+
+ Who When What
+ ======== ========== ===========================