Skip to content

Instantly share code, notes, and snippets.

View klaasman's full-sized avatar

Klaas Landsman klaasman

View GitHub Profile
@klaasman
klaasman / algolia-nextjs-history-router.ts
Last active August 28, 2023 10:57
algolia instantsearch history clone, adapted to the next.js router.
import { Router, UiState } from "instantsearch.js";
import NextRouter from "next/router";
import qs from "qs";
/**
* This file is a copy of the InstantSearch.js router middleware:
* https://github.com/algolia/instantsearch.js/blob/5d79d92b30e188e5206dcb5fe86fcac058c3f09b/src/lib/routers/history.ts
*
* It's internals have been adapted to use the NextJS Router (singleton) instead
* of native browser history.
@klaasman
klaasman / nextPushId.js
Created December 8, 2017 12:42
Firebase unique ID generator
function nextPushId () {
// Modeled after base64 web-safe chars, but ordered by ASCII.
var PUSH_CHARS = '-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz'
// Timestamp of last push, used to prevent local collisions if you push twice
// in one ms.
var lastPushTime = 0
// We generate 72-bits of randomness which get turned into 12 characters and
// appended to the timestamp to prevent collisions with other clients. We
// store the last characters we generated because in the event of a collision,
// we'll use those same characters except "incremented" by one.
@klaasman
klaasman / json-stable-stringify.js
Created March 10, 2015 14:19
Json stable stringify - amd ready
define(function () {
'use strict';
return function (obj, opts) {
if (!opts) {
opts = {};
}
if (typeof opts === 'function') {
@klaasman
klaasman / gist:3db53291dff89dc70ba3
Last active November 22, 2017 12:53
Google analytics localStorage
var analyticsId = '';
if (window.localStorage && window.localStorage.setItem) {
window.ga('create', analyticsId, {
'storage': 'none',
'clientId': window.localStorage.getItem('clientId')
});
window.ga(function(tracker) {