Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jkao
jkao / s2-type-checking.ts
Last active September 9, 2019 16:29
Demo-ing TypeScript checks for S2
import s2 = require('@radarlabs/s2');
// an arbitrary point in the East Village in New York City
const cell = s2.CellId.fromToken('89c25977e5d62c4b')
cell.id().charAt(0); // compilation error - bigint doesn't have charAt method
@jkao
jkao / s2-type-checking.ts
Created September 9, 2019 16:29
Demo-ing TypeScript checks for S2
import s2 = require('@radarlabs/s2');
// an arbitrary point in the East Village in New York City
const cell = s2.CellId.fromToken('89c25977e5d62c4b')
cell.id().charAt(0); // compilation error - bigint doesn't have charAt method
@jkao
jkao / s2bigint.js
Last active September 9, 2019 16:15
Example of BigInt usage in the Radar S2 Cell lib
const s2 = require('@radarlabs/s2');
// an arbitrary point in the East Village in New York City
const cell = s2.CellId.fromToken('89c25977e5d62c4b')
console.log(cell.id()); // -> 9926594900169993291n
@jkao
jkao / s2_cell_id_wrapper.cc
Last active September 12, 2019 02:08
A wrapper for a C++ class exposed in JavaScript
/* s2cellid.h */
#include <napi.h>
#include "s2/s2latlng.h"
class LatLng : public Napi::ObjectWrap<LatLng> {
public:
LatLng(const Napi::CallbackInfo& info);
static Napi::FunctionReference constructor;
static Napi::Object Init(Napi::Env env, Napi::Object exports);
@jkao
jkao / s2_clustering.js
Created August 13, 2019 17:52
Clustering Users by S2 Cells
const s2 = require('@radarlabs/s2');
const user1LongLat = [-73.95772933959961, 40.71623280185081];
const user2LongLat = [-73.95927429199219, 40.71629785715124];
const user3LongLat = [-73.99206161499023, 40.688708709249646];
const user1S2 = ["user1", new s2.CellId(new s2.LatLng(user1LongLat[1], user1LongLat[0])).parent(13)];
const user2S2 = ["user2", new s2.CellId(new s2.LatLng(user2LongLat[1], user2LongLat[0])).parent(13)];
const user3S2 = ["user3", new s2.CellId(new s2.LatLng(user3LongLat[1], user3LongLat[0])).parent(13)];
const s2 = require('@radarlabs/s2');
const williamsburgLongLats = [
[-73.95841598510742, 40.72423412682422],
[-73.96957397460938, 40.71226430831242],
[-73.9683723449707, 40.70497727808752],
[-73.96184921264648, 40.69951148213175],
[-73.95923137664795, 40.70852329864894],
[-73.94775152206421, 40.70391994183744],
[-73.94163608551025, 40.71145106322093],
@jkao
jkao / gist.md
Created September 19, 2018 03:25

Keybase proof

I hereby claim:

  • I am jkao on github.
  • I am jkao (https://keybase.io/jkao) on keybase.
  • I have a public key ASBaHNpGhQe-cdjmFE77Zrwjh1n9Cd3UqjPsl7jLgLoIyAo

To claim this, I am signing this object:

@jkao
jkao / .tmux.conf
Last active June 21, 2021 20:46
.tmux.conf
# colors
set -g default-terminal 'screen-256color'
# rebind
bind-key R source-file ~/.tmux.conf \; display-message "tmux.conf reloaded."
bind-key ` copy-mode
bind-key p paste-buffer
# admin debris
@jkao
jkao / gist:3780603
Created September 25, 2012 08:18
Get all Unique Sequences
def getAllUniqueSequences(currentList: List[Int]) : List[List[Int]] = {
if (currentList.length == 0) // Base case
List()
else // General case
(List(List(currentList.head))
++ getAllUniqueSequences(currentList.tail).map(s => currentList.head :: s)
++ getAllUniqueSequences(currentList.tail))
}