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 */
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

@belden
belden / one-bear-in-the-kitchen.md
Created August 17, 2015 13:40
Conversation with my 4.5 year old son

A conversation with Harris, who was whining on the ground

Me: What would you do if a bear knocked on the door and said, "Feed me, or I'll eat you!"

Harris: Umm... [looks around kitchen] I would give him the bananas!

Me: "I'm a bear! I don eat bananas!"

Harris: I would feed him... beef stew!

@belden
belden / resub-open3.pl
Last active August 29, 2015 14:22
resub IPC::Open3::open3
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin qw($Bin);
use lib "$Bin/../lib";
use Test::More tests => 3;
use Test::Resub qw(resub);