Skip to content

Instantly share code, notes, and snippets.

View lerouxb's full-sized avatar

Le Roux Bodenstein lerouxb

View GitHub Profile
@lerouxb
lerouxb / geartrain.scad
Created December 10, 2015 20:22
A 256:1 gearbox
include <MCAD/involute_gears.scad>
$fn = 100;
gear_module = 0.75;
pressure_angle = 20;
gear_thickness = 5/2;
shaft_radius = 1.5;
small_teeth = 11;
function a(input) {
var index = [];
var item;
for (var i=0; i<input.length; i++) {
item = input[i];
if (index.indexOf(item) === -1) {
index.push(item);
}
}
return index;
@lerouxb
lerouxb / url.js
Last active November 4, 2015 10:42
I made this for parsing and manipulating avatar urls. (The document.createElement('a') hack just about everyone recommends can be bad for performance in some cases.)
'use strict';
// loosey goosey first order approximation
var protocol = '([^:]+:)';
var host = '([^/]+)';
var pathname = '(\/[^?#]+)';
var search = '((\\?[^#]*)?)';
var hash = '((#.*)?)';
var URL_PARSE_EXPRESSION = protocol+'\/\/'+host+pathname+search+hash;
@lerouxb
lerouxb / build.log
Last active August 29, 2015 14:23
sudo perl Build.PL
cpanm (App::cpanminus) 1.7039 on perl 5.016002 built for darwin-thread-multi-2level
Work directory is /Users/leroux/.cpanm/work/1435579722.51305
You have make /usr/bin/make
You have LWP 6.04
You have /usr/bin/tar: bsdtar 2.8.3 - libarchive 2.8.3
You have /usr/bin/unzip
--> Working on ./xs
Entering /Users/leroux/src/Slic3r/xs
Checking if you have Module::Build 0.38 ... Yes (0.4211)
Checking if you have ExtUtils::Install 1.46 ... Yes (1.58)
@lerouxb
lerouxb / connections.coffee
Last active August 29, 2015 14:22
node-postgres weirdness
async = require 'async'
pg = require 'pg'
executeSQL = (sql, params, callback) ->
console.log params, "connecting..."
pg.connect process.env.DATABASE_URL, (err, client, done) ->
console.log params, "...ok"
return callback(err) if err
client.query sql, params, (err, result) ->
done(client)
parseURL = (url, parseQuery) ->
parser = document.createElement('a')
parser.href = url
parsed =
protocol: parser.protocol
host: parser.host
hostname: parser.hostname
port: parser.port
pathname: parser.pathname
@lerouxb
lerouxb / gist:0329d9c6c8d9f50fcf43
Last active August 29, 2015 14:16
Don't use :hover to show/hide content
  • Touch devices don't have a way to hover over an item.
  • Many keyboard+mouse devices have touchscreens too.
  • You cannot detect if a device supports :hover or is a touch device in CSS.
  • This isn't even solvable in theory because how a device gets used changes from one second to the next. (ie. move your hand from the mouse to the screen or back.)
  • Eventually all browsers and devices will be touch-capable which won't tell you anything about how the user will be using the device later at any particular moment.
  • Consider that whether the tap or click that is still going to occur in future is going to support a :hover effect or not might affect your decision to show that extra information that would be revealed by the effect ahead of time or not.
  • A touch device might sometimes show :hover on the first tap.
  • Subsequent taps on different elements might trigger the :hover, it might also follow the link.
  • Either way the :hover effect doesn't clear, because there's no corresponding "mouse out" action.
  • Unless
@lerouxb
lerouxb / gist:e3719764b2b4c6ae990e
Created December 4, 2014 09:16
best vagrant performance I've managed to get so far

This is with an Ubuntu guest on a OSX host. I noticed that some tools just notice changed files faster than others and generally you have to enable "compatibility" flags so it uses the slowest, most reliable method. But often then it might notice multiple changes in a loop, so make sure your system date/time is synced very accurately on both the guest and the host and you still might have to throttle or debounce those reloads. Watcher processes/tools typically support that sort of thing through command-line options.

To speed up syncing and I/O in general

Somewhere in Vagrantfile:

config.vm.synced_folder ".", "/vagrant", type: "nfs", mount_options: ['actimeo=2', 'rw', 'vers=3', 'tcp', 'fsc']

Install cachefilesd:

@lerouxb
lerouxb / 20_shades_of_grey.coffee
Last active August 29, 2015 14:05
Calculate hex values for 20 shades of gray starting at exactly #ffffff and ending at #000000
for i in [19..0]
xx = Math.round(255/19*i).toString(16)
xx = '0'+xx if xx.length == 1
console.log "##{xx}#{xx}#{xx}"