This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GO STRUCTS FROM OAK SCHEMA https://scoop.stg.nyt.net/oak/v1/spec/# | |
// OakAsset schema: https://scoop.stg.nyt.net/oak/v1/spec/#/schemas/OakAsset | |
type OakAsset struct { | |
ID string `json:"id"` | |
URI string `json:"uri"` | |
EditorLink string `json:"editorLink"` | |
Documents Documents `json:"documents"` | |
Metadata OakMetadata `json:"metadata"` | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/nytimes/nodetools/blob/main/scoop/auth.js#L15C1-L37C3 | |
func getToken() (string, error) { | |
conf := &oauth2.Config{ | |
ClientID: "interactive", | |
Endpoint: oauth2.Endpoint{ | |
TokenURL: tokenURL, | |
AuthURL: authURL, | |
}, | |
} | |
token, err := conf.PasswordCredentialsToken(context.Background(), username, password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Golang implementation of Evan Miller's algorithm for ranking stuff based on upvotes: | |
// http://www.evanmiller.org/how-not-to-sort-by-average-rating.html | |
// playground link: https://play.golang.org/p/dV6yk6pBY5y | |
func lowerBound(upvotes, n int, confidence float64) (float64, error) { | |
if n == 0 { | |
return 0, errors.New("n can't be 0") | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server.route({ | |
method: 'GET', | |
path: '/api/endpoint', | |
handler: (request, h) => { | |
return (async () => { | |
try { | |
const { payload } = await Wreck.get('URL') | |
return h.response(payload && payload.toString()) | |
} | |
catch (ex) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Node.js implementation of Evan Miller's algorithm for ranking stuff based on upvotes: | |
// http://www.evanmiller.org/how-not-to-sort-by-average-rating.html | |
const stats = require('simple-statistics') | |
const lower_bound = (upvotes, n = 0, confidence = 0.95) => { | |
if (n === 0) return 0 | |
// for performance purposes you might consider memoize the calcuation for z | |
const z = stats.probit(1-(1-confidence)/2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
My routing starter template for api endpoints when using Express.js | |
app.use('/api/endpoint', require('./endpoint.js')) | |
*/ | |
const express = require('express') | |
const router = express.Router() | |
router.use((req, res, next) => next()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var once = function(func) { | |
var alreadyCalled = false; | |
return function() { | |
if (!alreadyCalled) { | |
func.apply(this, arguments); | |
alreadyCalled = true; | |
} | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { createRenderer } from 'react-addons-test-utils'; | |
import createComponent from 'react-unit'; | |
import tape from 'tape'; | |
import addAssertions from 'extend-tape'; | |
import jsxEquals from 'tape-jsx-equals'; | |
const test = addAssertions(tape, {jsxEquals}); | |
// Component to test | |
import Button from '../components/Button'; |
NewerOlder