Skip to content

Instantly share code, notes, and snippets.

View jridgewell's full-sized avatar
😬

Justin Ridgewell jridgewell

😬
  • New York, NY
  • 20:26 (UTC -04:00)
View GitHub Profile
@jridgewell
jridgewell / mapReduce.rb
Last active December 18, 2015 16:09
mapReduce geoSpacial in Mongo
require 'mongo_mapper'
map = %Q(function() {
lat_long = Math.floor(this.lat) + Math.floor(this.lon);
emit(lat_long, this.id);
})
reduce = %Q(function(id, values) {
return vals;
})
output_collection = "database.1by1"
@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 / 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.
}
@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 / _private-fields-faq.md
Last active February 20, 2018 21:54 — forked from rauschma/_private-fields-faq.md
Fields with arbitrarily scoped privacy

Fields with arbitrarily scoped privacy

Info on private fields: http://2ality.com/2017/07/class-fields.html

Q&A

  • Why the prefix #?
    • You define keys and these keys additionally work completely differently from property keys.
  • Is the keyword private necessary?
  • It could be omitted (first mention declares), but I like the distinction between declaration and mention.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Setting class inheritance</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>