Skip to content

Instantly share code, notes, and snippets.

View belden's full-sized avatar

Belden Lyman belden

View GitHub Profile

Keybase proof

I hereby claim:

  • I am belden on github.
  • I am belden (https://keybase.io/belden) on keybase.
  • I have a public key ASAE48U4Ji0fEI1OdMdqIUt-bLzpHmse1YHjs8ZIjdfpogo

To claim this, I am signing this object:

@belden
belden / dump-alias.md
Last active August 18, 2023 23:43
A git alias to make sharing git aliases easier

git dump-alias

A git alias which makes it easy to dump the shell command used to create any arbitrary git alias.

Installing git dump-alias

Run this in your terminal:

git config --global alias.dump-alias $'!g(){ if [ -z $1 ]; then git config --list | grep "alias\."; else g|grep "alias\.$1="|perl -lpe \'($q,$d,$b)=map{chr}0x27,0x24,0x5c;($N,$B)=$_=~/(alias\.[^=]+)=(.+)/;$B=~s,$q,$b$q,g;$_=qq,git config --global $N $d$q$B$q,;\';fi;};g $1'
@belden
belden / overEach.js
Last active July 20, 2021 18:56
overEach - apply a function over each key of an object, or just get all its keys safely
var pojo = {
foo: 'bar',
baz: 'qux'
};
var ownKeys = function () {
return Object.keys(this).filter(function(k) {
return this.hasOwnProperty(k);
}, this);
};
@belden
belden / -
Created December 19, 2016 23:24
Ember.RSVP.defer = function(promiseLabel) {
var re = new RegExp(str);
if (promiseLabel.match(re)) {
var doom = Ember.RSVP.reject({
errors: JSON.stringify([{
'token':'^error_duplicate_store_name^',
'args': ['luciferase-tiddley-store', 'Organization > ramson-gent-region']
}])
});
var deferred = origRSVPDefer.apply(this, arguments);
@belden
belden / bezier.js
Created November 22, 2016 19:18 — forked from atomizer/bezier.js
de Casteljau's algorithm in javascript
function bezier(pts) {
return function (t) {
for (var a = pts; a.length > 1; a = b) // do..while loop in disguise
for (var i = 0, b = [], j; i < a.length - 1; i++) // cycle over control points
for (b[i] = [], j = 0; j < a[i].length; j++) // cycle over dimensions
b[i][j] = a[i][j] * (1 - t) + a[i+1][j] * t; // interpolation
return a[0];
}
}
@belden
belden / js: cross browser mouse event coordinates
Created September 30, 2016 16:55 — forked from pixelhijack/js: cross browser mouse event coordinates
get exact cross browser mouse event coordinates workarounds
/*
get exact cross browser mouse event coordinates workarounds (relative to offset parent)
*/
/* with jquery */
var x = event.offsetX || event.clientX - $(event.target).offset().left,
y = event.offsetY || event.clientY - $(event.target).offset().top;
/* on svg raphael paper */
@belden
belden / tail-factorial.pl
Created December 2, 2013 23:03
Tail recursion pattern in Perl - for some reason people say Perl doesn't have tail recursion; you just need to do a little extra work.
#!/usr/bin/env perl
use strict;
use warnings;
use bigrat;
my $n = shift || 100;
print "$n! = " . tail_factorial($n) . "\n";
Inhalation of crystalline silica is harmful to the lungs, causing
silicosis. Amorphous silica is considered to be low toxicity, but prolonged
inhalation cause changes to the lungs.[24] Diatomaceous earth is mostly
amorphous silica, but contains some crystalline silica, especially in the
saltwater forms.[25] In a study of workers, those exposed to natural DE for
over 5 years had no significant lung changes, while 40% of those exposed
to the calcined form had developed pneumoconiosis.[26] Today's common
D.E. formulations are safer to use as they are predominantly made up of
amorphous silica and contain little or no crystalline silica.[27]
use strict;
use warnings;
package Functional::ForkManager;
use base qw(Exporter);
use Scalar::Util qw(blessed);
use Parallel::ForkManager;
use Functional::Iterator;
our @EXPORT = qw(fork_over these_things);

A colleague asked for code review, so I had a look. It was a small branch: a single commit affecting two files. Looking over the branch, I saw a common data extraction pattern emerging in unit tests, so suggested that a function would be easier to read and maintain than copied code. A variable name was a bit misleading, and I suggested a different name would be better. And I noted a spot where a class name was repeatedly hard-coded in the file.

I did all this through the Github UI from my phone, because mobile-first.

So, I requested three small changes, and after some small amount of time my colleague updated their branch. Rather than pushing the code review changes as a second commit to their branch, though, they instead squashed the second commit to the first one and did a force push. That's fine, I like a clean history too.

"Please have a second look," came the request. Since I was already up to speed on the initial delta, I figured it woudl be faster to read the difference between the two deltas using