Skip to content

Instantly share code, notes, and snippets.

View codyromano's full-sized avatar

Cody Romano codyromano

  • Facebook
View GitHub Profile
@alexhawkins
alexhawkins / HashTable.js
Last active August 7, 2021 23:33
Correct Implementation of a Hash Table in JavaScript
var HashTable = function() {
this._storage = [];
this._count = 0;
this._limit = 8;
}
HashTable.prototype.insert = function(key, value) {
//create an index for our storage location by passing it through our hashing function
var index = this.hashFunc(key, this._limit);
@adrianholovaty
adrianholovaty / service-worker-cache-example.js
Last active May 5, 2020 21:25
Better example of custom service worker cache keys
var jsonDataRe = /example\.com\/(.*\.json)/;
self.addEventListener('fetch', function(event) {
var request = event.request,
match = jsonDataRe.exec(request.url);
if (match) {
// Use regex capturing to grab only the bit of the URL
// that we care about, ignoring query string, etc.
var cacheRequest = new Request(match[1]);