Skip to content

Instantly share code, notes, and snippets.

View jridgewell's full-sized avatar
😬

Justin Ridgewell jridgewell

😬
  • New York, NY
  • 04:24 (UTC -04:00)
View GitHub Profile
@jridgewell
jridgewell / gist:0a8cc627e65b3d24a8b9
Last active August 29, 2015 14:16 — forked from danapplegate/gist:98209b1eb2721ca7365c
The `$userVote` Problem

The userVote Problem

We are struggling to find a way to efficiently and cleanly implement the following common use case in our code base:

  • There is an object that can be voted on
    • Project
    • Discussion
    • Comment
  • We have an array of these objects
  • We would like to know if a user has voted on each of these objects
@jridgewell
jridgewell / view.patch
Last active August 29, 2015 14:24
Defining root Backbone element in template
diff --git a/backbone.js b/backbone.js
index b16499a..f484f19 100644
--- a/backbone.js
+++ b/backbone.js
@@ -1170,7 +1170,7 @@
var View = Backbone.View = function(options) {
this.cid = _.uniqueId('view');
_.extend(this, _.pick(options, viewOptions));
- this._ensureElement();
+ if (!this.templateEl) this._ensureElement();
@jridgewell
jridgewell / Box.js
Last active February 4, 2018 23:13
Backbone + Incremental DOM
var Box = Backbone.Model.extend({
defaults: {
top: 0,
left: 0,
color: 0,
content: 0
},
initialize: function() {
@jridgewell
jridgewell / bench.js
Created December 17, 2016 21:24
isObject bench
'use strict';
function log(message) {
document.getElementById('status').textContent += message + '\n';
}
log('running...');
const tests = [
null, undefined, 0, 1, true, false, '', 'adsfasf', new String('test'), {}, Object.create(null), Object.prototype, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {},
null, undefined, 0, 1, true, false, '', 'adsfasf', new String('test'), {}, Object.create(null), Object.prototype, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {},
@jridgewell
jridgewell / get-old-chromium-binary.md
Created June 7, 2017 21:27 — forked from cletusw/get-old-chromium-binary.md
Download an old Chromium binary

(source)

Taking [denilson-sá's answer][2] further...

You need revision numbers to grab downloads. So first lookup the full version string from the following URL, adjusting parameters as needed:

https://omahaproxy.appspot.com/history.json?channel=stable&os=mac

For Chrome version 28 the full version string is 28.0.1500.71. Now go to https://omahaproxy.appspot.com and enter the full version string ("28.0.1500.71") into the Position Lookup box. Copy the Base Position number ("209842" in this case).

@jridgewell
jridgewell / git-pr
Created September 11, 2017 19:18
Checkout a git pr
#!/usr/bin/env ruby
# Based on https://gist.github.com/gnarf/5406589
pr, branch = ARGV
remote = 'origin'
if pr.nil?
puts "USAGE: git pr [REMOTE/]PR [BRANCH]"
puts "\tgit pr 123"
@jridgewell
jridgewell / escapes.js
Created October 27, 2017 22:37
A Unicode compliant percent encoding regex
const percentUnicode = new RegExp(`%(?:
[0-7][0-9a-f]|
(?:
c[2-9a-f]|
d[0-9a-f]|
e0 %[ab][0-9a-f]|
ed %[89][0-9a-f]|
(?:
e[1-9abcef]|
f0 %[9ab][0-9a-f]|
@jridgewell
jridgewell / index.html
Last active December 14, 2019 05:58
Native TreeWalker vs Handwritten TreeWalker (https://jsbench.github.io/#af1e1c40916b9144ffa1c62cc262d4b1) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Native TreeWalker vs Handwritten TreeWalker</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@jridgewell
jridgewell / utf8-dfa-decoder.c
Last active December 5, 2017 00:18
A reworked version of Bjoern Hoehrmann's DFA decoder, skipping the ternary.
#define UTF8_ACCEPT 12
#define UTF8_REJECT 0
// See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
// Reworked table, justification at https://docs.google.com/spreadsheets/d/1AZcQwuEL93HmNCljJWUwFMGqf7JAQ0puawZaUgP0E14
static const uint8_t utf8d[] = {
// The first part of the table maps bytes to character to a transition.
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00-0F
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 10-1F
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20-2F
@jridgewell
jridgewell / overloading.js
Created January 24, 2018 22:39
"Operator Overloading"
// Well-known Symbol
Symbol.operator = Symbol('operator');
// Install operator to catch operators
class Point {
//...
[Symbol.operator](op, other) {
// op = "+", or "-", or "!", or "<", etc.
// other is either undefined (arguments.length === 1), or the value of the binary operator's other side.
}