Skip to content

Instantly share code, notes, and snippets.

View matallo's full-sized avatar

Carlos Matallín matallo

View GitHub Profile
javascript:(function()%7Btry%20%7Bvar%20vizID%20%3D%20window.location.href.match(%2F%5C%2Fbuilder%5C%2F(%5B%5Cda-zA-Z-%5D%2B)%2F)%5B1%5D%3Bvar%20prefix%20%3D%20window.location.href.match(%2F(.*)%5C%2Fbuilder%2F)%5B1%5D%3Bvar%20newURL%20%3D%20prefix%20%2B%20'%2Fapi%2Fv3%2Fviz%2F'%20%2B%20vizID%20%2B%20'%2Fviz.json'%3Bwindow.open(newURL)%3B%7D%20catch(error)%20%7Balert(%22URL%20couldn't%20be%20parsed%22)%7D%7D)()
const fs = require('fs');
const licenses = (dirpath, acc, depth = -1) => {
const hasPackage = fs.existsSync(`${dirpath}/package.json`);
if (!hasPackage) {
return;
}
const pkg = require(`${dirpath}/package.json`);
let license = (pkg.licenses && pkg.licenses) ? pkg.licenses : pkg.license;
acc[pkg.name] = `${pkg.description}\t${JSON.stringify(license)}`;
{
"color_scheme": "Packages/Theme - Spacegray/base16-ocean.dark.tmTheme",
"draw_white_space": "all",
"file_exclude_patterns":
[
".DS_Store",
".grunt/*",
".log",
".tmp/*",
".sass-cache/*",
// license: BSD3
const WEBMERCATOR_R = 6378137.0;
const DIAMETER = WEBMERCATOR_R * 2 * Math.PI;
class Mercator {
static project(lon, lat) {
var x = DIAMETER * lon/360.0;
var sinlat = Math.sin(lat * Math.PI/180.0);
var y = DIAMETER *Math.log((1+sinlat)/(1-sinlat)) / (4*Math.PI);
return { x, y };
}
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@matallo
matallo / latency.txt
Created January 31, 2017 15:14 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
<!doctype><html><head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Odyssey.js Slides</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="http://cartodb.github.io/odyssey.js/sandbox/favicon.png">
git submodule init && git submodule update
cd lib/sql/ && sudo make all install && bundle exec rake cartodb:db:load_functions
cd ../.. && make check
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>Carlos subscriptions in feedly Cloud</title>
</head>
<body>
<outline text="travel" title="travel">
<outline type="rss" text="randomwire.com" title="randomwire.com" xmlUrl="http://www.randomwire.com/feed" htmlUrl="https://henro.co"/>
<outline type="rss" text="Craig Mod - The Sputnik Journal" title="Craig Mod - The Sputnik Journal" xmlUrl="http://craigmod.com/rss/" htmlUrl="http://craigmod.com/"/>