Skip to content

Instantly share code, notes, and snippets.

View chris--young's full-sized avatar

Chris Young chris--young

  • Beverly Hills, California
View GitHub Profile
@chris--young
chris--young / n-api.html
Last active September 15, 2017 17:08
pre
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>N-API | Node.js v4.6.0 Documentation</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic">
<link rel="stylesheet" href="assets/style.css">
<link rel="stylesheet" href="assets/sh.css">
<link rel="canonical" href="https://nodejs.org/api/n-api.html">
</head>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>N-API | Node.js v4.6.0 Documentation</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic">
<link rel="stylesheet" href="assets/style.css">
<link rel="stylesheet" href="assets/sh.css">
<link rel="canonical" href="https://nodejs.org/api/n-api.html">
</head>
const _3d = {};
_3d.vector = (x = 0, y = 0, z = 0) => [x, y, z];
_3d.matrix = (v0, v1, v2) => _3d.vector(v0, v1, v2);
_3d.identity = _3d.matrix([1, 0, 0], [0, 1, 0], [0, 0, 1]);
_3d.scale = (v, s) => _3d.vector(v[0] * s, v[1] * s, v[2] * s);
_3d.sum = (v0, v1, v2) => _3d.vector(v0[0] + v1[0] + v2[0], v0[1] + v1[1] + v2[1], v0[2] + v1[2] + v2[2]);
_3d.transform = (v, m) => _3d.sum(_3d.scale(m[0], v[0]), _3d.scale(m[1], v[1]), _3d.scale(m[2], v[2]));
_3d.multiply = (m0, m1) => _3d.matrix(_3d.transform(m1[0], m0), _3d.transform(m1[1], m0), _3d.transform(m1[2], m0));
'use strict'
const blocks = {
symbols: '[\u2000-\u2bff]',
cjk: '[\u2e80-\u9fff]',
surrogates: '[\ud800-\udbff]',
selectors: '[\ufe00-\ufe0f]'
};
const valid = new RegExp(`^${Object.keys(blocks).map(key => blocks[key]).join('|')}$`);
'use strict'
const a = [{ id: 1 }, { id: 2 }, { id: 1 }, { id: 3 }]; // guaranteed to have a length less than 25
function unique1(a) {
const r = [];
o: for (let o of a) {
for (let i of r)
if (o.id === i.id)
@chris--young
chris--young / gist:9630b7ac54e6e1adaa7f
Last active August 29, 2015 14:21
reorders an array of objects based on a given key
var test_data = [
{ id: 'a', order_by: 1 },
{ id: 'b', order_by: 2 },
{ id: 'c', order_by: 3 },
{ id: 'd', order_by: 4 },
{ id: 'e', order_by: 5 },
{ id: 'f', order_by: 6 },
{ id: 'g', order_by: 7 },
{ id: 'h', order_by: 8 },
{ id: 'i', order_by: 9 }
require 'test_helper'
class IndependentMatcheesControllerTest < ActionController::TestCase
# Without this method I get...
# RuntimeError: @controller is nil: make sure you set it in your test's setup method.
# test/controllers/independent_matchees_controller_test.rb:15:in `block in <class:IndependentMatcheesControllerTest>'
# With it I get...
# NameError: uninitialized constant IndependentMatcheesControllerTest::IndependentMatcheesController
# test/controllers/independent_matchees_controller_test.rb:11:in `setup'
def setup
function linkGiftCards(giftCards, customerId, callback) {
function linkCard(card, id, callback2) {
// do some stuff
callback2();
}
async.each(giftCards, function (card, callback2) {
linkCard(card, customerId, callback2);
}, function (err) {
@chris--young
chris--young / gist:4d3027eb00751ee18abf
Created March 25, 2015 23:50
Mob Crypto Challenge
function decrypt(cipherText, key) {
var keyInt = key.codePointAt(0),
plainText = '';
for (var char = 0; char < cipherText.length; char += 2)
plainText += String.fromCharCode(parseInt(cipherText.substr(char, 2), 16) ^ keyInt);
return plainText;
}