Skip to content

Instantly share code, notes, and snippets.

View belden's full-sized avatar

Belden Lyman belden

View GitHub Profile
@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 */
var logLines []string
type logMock struct{}
func (l *logMock) Write(p []byte) (int, error) {
logLines = append(logLines, string(p))
return 0, nil
}
//CaptureLogOutput A utility to capture the log output of a function and pass it along
function simulate(element, eventName)
{
var options = extend(defaultOptions, arguments[2] || {});
var oEvent, eventType = null;
for (var name in eventMatchers)
{
if (eventMatchers[name].test(eventName)) { eventType = name; break; }
}

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

@crazed
crazed / http-proxy.go
Last active August 29, 2015 13:57
simple http proxy in go, with a chaos monkey twist
package main
import (
"fmt"
"net/http"
"net/http/httputil"
"strconv"
"time"
)
@colinrymer
colinrymer / MIT License
Created November 21, 2012 18:05 — forked from jcf/MIT License
RSpec matcher for parsing `response.headers['Content-Type']`
Copyright (c) 2012 James Conroy-Finn, Colin Rymer
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTW
@rakhmad
rakhmad / clojure.md
Created April 17, 2012 15:55
Setting Up Clojure on OS X

Setting Up Clojure on OS X

I spent a lot of time trying to find a pretty optimal (for me) setup for Clojure… at the same time I was trying to dive in and learn it. This is never optimal; you shouldn't be fighting the environment while trying to learn something.

I feel like I went through a lot of pain searching Google, StackOverflow, blogs, and other sites for random tidbits of information and instructions.

This is a comprehensive "what I learned and what I ended up doing" that will hopefully be of use to others and act as a journal for myself if I ever have to do it again. I want to be very step-by-step and explain what's happening (and why) at each step.

Step 1: Getting Clojure (1.3)

@atomizer
atomizer / bezier.js
Created June 27, 2011 20:23
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];
}
}