Skip to content

Instantly share code, notes, and snippets.

@bakoushin
bakoushin / tweak.html
Last active October 3, 2018 04:55
Tweak to make InVision prototype work with Google Analytics
<!-- Tweak for Google Analytics to catch SPA navigation -->
<script>
var currentPage = window.location.href;
window.onload = function() {
setInterval(function() {
if (currentPage !== window.location.href) {
currentPage = window.location.href;
var newPage = window.location.pathname + window.location.hash
ga('set', 'page', newPage);
ga('send', 'pageview');
@bakoushin
bakoushin / sw-await.js
Created February 1, 2018 08:12
Service Worker: Promises vs Async/Await
const version = 1;
const appPrefix = 'myApp-';
const staticCacheName = appPrefix + 'static-v' + version;
const imagesCacheName = appPrefix + 'content-imgs';
var allCaches = [
staticCacheName,
imagesCacheName
];
self.addEventListener('message', event => {
@bakoushin
bakoushin / sw.js
Created February 1, 2018 08:14
ServiceWorker Fetch Examples — Hijacking Requests
self.addEventListener('fetch', event => {
/*
HIJACKING RESPONSE EXAMPLES
Uncomment examples one by one to see how it works.
Don't forget to enable 'Update on reload' in Application - Service Workers.
*/
// Example 1: respond with arbitrary HTML
@bakoushin
bakoushin / webpack.config.js
Last active February 12, 2018 17:24
Service Worker webpack config
const path = require('path');
const BabiliPlugin = require('babili-webpack-plugin');
module.exports {
entry: {
'bundle.min': './src/index.js',
'sw': './src/sw.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
const hasOwnProperty = Object.prototype.hasOwnProperty;
const toString = Object.prototype.toString;
/**
* Проверяет, что переданный объект является "плоским" (т.е. созданным с помощью "{}"
* или "new Object").
*
* @param {Object} obj
* @returns {Boolean}
*/
@bakoushin
bakoushin / task.md
Created April 7, 2018 16:52 — forked from dima117/task.md

Упражнения

  1. Сортировка пузырьком
  2. Сортировка выбором
  3. Сортировка вставками
  4. Развернуть односвязный список
  5. Обход дерева в глубину
  6. Обход дерева в ширину
  7. Найти все простые числа от 1 до N
  8. Бинарный поиск в отсортированном массиве
const streets = [
'Абельмановская улица',
'площадь Абельмановская Застава',
'Абрамцевская просека',
'Абрамцевская улица',
'Абрикосовский переулок',
'Авангардная улица',
'улица Авиаконструктора Микояна',
'улица Авиаконструктора Миля',
'улица Авиаконструктора Сухого',
@bakoushin
bakoushin / index.js
Last active April 11, 2018 08:19
Request
'use strict';
class Request {
constructor() {
this._history = [];
this._promiseChain = Promise.resolve();
}
get(url, resolve, reject) {
this._promiseChain = this._promiseChain
.then(() => __fetch(url))
@bakoushin
bakoushin / 90-monitor-hotplug.rules
Last active May 30, 2023 02:51
Lubuntu 18.04 external HDMI display hotplug
ACTION=="change", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/USER/.Xauthority", RUN+="/bin/bash /home/USER/bin/monitorhotplug.sh"
@bakoushin
bakoushin / @ SimpleDB.md
Created November 13, 2018 14:30
Simple DB

SimpleDB - Like Indexed DB, but Simple

A simple asynchronous data store.

STATUS: This is a thought experiment, not a serious proposal. Would basic async storage like this be useful? With this plus some locking primitive, could you build Indexed DB?

Like Indexed DB:

  • rich value types - store anything you can structured clone
  • rich key types - Number, String, Date, Array (of other key types)