Skip to content

Instantly share code, notes, and snippets.

Adrian Holovaty adrianholovaty

Block or report user

Report or block adrianholovaty

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@adrianholovaty
adrianholovaty / service-worker-cache-example.js
Last active Aug 18, 2019
Better example of custom service worker cache keys
View service-worker-cache-example.js
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]);
@adrianholovaty
adrianholovaty / serviceworker-cache-wrapper-example.js
Created Dec 27, 2015
Example usage of serviceworker-cache-wrapper.js
View serviceworker-cache-wrapper-example.js
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 cacheKey = match[1];
@adrianholovaty
adrianholovaty / serviceworker-cache-wrapper.js
Created Dec 27, 2015
Service worker cache wrapper that lets you use arbitrary cache keys
View serviceworker-cache-wrapper.js
function cachePut(key, request, response) {
caches.open(key).then(function(cache) {
cache.put(request, response);
});
}
function cacheGet(key) {
return new Promise(function(resolve, reject) {
caches.open(key).then(function(cache) {
cache.keys().then(function(keyArray) {
if (keyArray.length) {
@adrianholovaty
adrianholovaty / retina_help.txt
Last active Aug 29, 2015
Soundslice retina test
View retina_help.txt
Hey, I'm trying to test this page on as many hi-DPI (aka "retina") devices
as possible:
http://www.soundslice.com/scores/auld-lang-syne/?retina
Can you take a look and let me know whether everything looks good and whether
it's any more sluggish than the non-retina version? Also let me know your
devicePixelRatio, which you can get from http://www.devicepixelratio.com/ --
if your ratio is something other than 1 or 2 (e.g., 1.5), I'm particularly
interested.
@adrianholovaty
adrianholovaty / stuff.py
Created Sep 5, 2013
Django two-phased template rendering
View stuff.py
# Two-phased template rendering.
# See http://www.holovaty.com/writing/django-two-phased-rendering/
# LICENSE: Public domain.
################
# TEMPLATE TAG #
################
from django import template
register = template.Library()
View gist:5898161
// Copyright 2013 Soundslice LLC. License: BSD.
/* HTML example: ****************
<figure class="vid">
<video preload>
<source src="/videos/help/playhead.mp4" type="video/mp4">
<source src="/videos/help/playhead.webm" type="video/webm">
</video>
<p>To move the playhead, click in the timeline or drag the playhead’s diamond.</p>
@adrianholovaty
adrianholovaty / gist:4444825
Created Jan 3, 2013
Heroku deployment error
View gist:4444825
$ git push heroku master
Counting objects: 146, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (120/120), done.
Writing objects: 100% (120/120), 12.64 KiB, done.
Total 120 (delta 98), reused 0 (delta 0)
-----> Python app detected
-----> No runtime.txt provided; assuming python-2.7.3.
-----> Preparing Python runtime (python-2.7.3)
-----> Installing Distribute (0.6.34)
@adrianholovaty
adrianholovaty / gist:2878410
Created Jun 5, 2012
Userless Django admin
View gist:2878410
# Does not fully work, but gets you partially there.
class UserlessAdminSite(admin.sites.AdminSite):
def check_dependencies(self):
pass
def has_permission(self, *args, **kwargs):
return True
class UserlessModelAdmin(admin.ModelAdmin):
You can’t perform that action at this time.