Skip to content

Instantly share code, notes, and snippets.

💻
Guess what

Arthur Stolyar NekR

💻
Guess what
Block or report user

Report or block NekR

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
@NekR
NekR / standalone.md
Last active Oct 2, 2015
How to detect if app was run in standalone mode in Chromium (with manifest.json)
View standalone.md

Hacky way to detect if app was launched in standalone mode in Chromium (with manifest.json) without problems with AppCache (and possibly ServiceWorker).

As suggested on one of the Google Developers sites, one may use search params in start_url of the manifest.json to notify page about that it was launched in standalone mode: start_url: '/?standalone'.

This works well unless your page uses AppCache (or ServiceWorker). In case of AppCache, every url with different search params is treated as separate entry in cache. So if you have listed / path in AppCache and naively used start_url: '/?standalone' in your manifest.json, then your Web App won't work offline from the Home Screen.
_With ServiceWorker, however, there is few ways to fix this directly in its code, like ignoreSearch option for match() method (currently not supported in Chromium) or just traversing cache entries manually and comparing new URL(event.request.url).pathname with stored request `new URL(...).path

@NekR
NekR / promises.md
Last active Aug 29, 2015
Promises with |end| capability
View promises.md

#Promises with |end| capability

Maybe it's better to think about cancellation as a finishing? Actually just use finishing as cancellation for promises which do not just store data, but rather makes some request.

This is not a secret what browsers do some tricky thing to determine if promise chain ended so Promise and its value might by GCed. It also does not work for stored promises like window.p = new Promise(...). So promises needs not only cancellation, but finishing ability too. It might be combined.

Let's for example introduce .end() (just example of name) method on the Promise.prototype which by default lock current promise and tells to GC what no one can anymore access value of this promise. It's just becomes no-op completely (all the methods) so GC might collects its value or stop referencing it with promise. Potentially, this also should work with chain of the promise, so once .end() called it also tries to end chain. Of course it should use ref-counts, etc. Few exampl

@NekR
NekR / fetch.md
Created Mar 25, 2015
Why so fetch?
View fetch.md

Why so fetch?

This is answer to this Jake's post http://jakearchibald.com/2015/thats-so-fetch/

First, I would begin with commenting this shining phrase:

Bit of a rant: it bothers me that as developers, we preach iterative development and release, but when we're the customers of that approach the reaction is all too often "HOW DARE YOU PRESENT ME WITH SUCH INCOMPLETE IMPERFECTION".

As a developer, when I provide incomplete, incremental product to my client, I always says sorry to them until it's fully done. But as you mentioned, you want hear from clients "SHUTUP AND TAKE MY MONEY". This does not seems like apology.

Okay, here I am going to agree what "final" abilities of fetch are cool, really, very usable. What is wrong with it is that it misses basic API from the beginning, it's like that your skate but without wheels, only suspension and nice colors.

View gist:5748541
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script>
(function() {
var disabled = (function() {
var button = document.createElement('button'),
fieldset,
handlesEvents,
View viewport.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no,initial-scale=1.0, maximum-scale=1">
</head>
<body>
</body>
@NekR
NekR / flowbug.html
Created Aug 18, 2012
X-tags flow bug
View flowbug.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script src="../x-tag/x-tag.js"></script>
<script>
xtag.register('x-test');
</script>
<style>
@NekR
NekR / swipe.js
Created Apr 15, 2012
Small swipe API provides use swipes like plain events.
View swipe.js
const
SWIPE_OFFSET = 50,
SWIPE_ANIMATION = 400,
SWIPE_HORIZONTAL = 1,
SWIPE_VERTICAL = 2,
SWIPE_BOTH = 3,
TAP_DELAY = 100,
LONG_TAP_DELAY = 500;
document.addEventListener('mousedown', function(e){
You can’t perform that action at this time.