Skip to content

Instantly share code, notes, and snippets.

Avatar

Konstantin Vyatkin tinovyatkin

View GitHub Profile
@tinovyatkin
tinovyatkin / loadFont.js
Last active Mar 15, 2017
My function to async load web fonts (real WOFF and WOFF2, not base64 behemots), cache them to localStorage and reuse on next visits
View loadFont.js
/**
* This function load font from web, stores it in localStorage and reuses on next page loads
* Different to everything I found on the internet due to following facts
* 1. Checks if the font is installed in the system and spend no time if it is
* 2. Loads actual WOFF or WOFF2 fonts (if supported) and not bit base64 encoded version - so it faster
* 3. Uses fetch API and FontFace API if available - it's cool!
* 4. Return promises and uses jQuery for cases where native promises probably not available
*
* @param fontName (Field for font-face)
* @param fontUrl (full URL but without .woff nor .woff2 extensions - format will be selected automatically)
@tinovyatkin
tinovyatkin / installRollbar.js
Last active Sep 28, 2016
Use navigator.sendBeacon with Rollbar
View installRollbar.js
// This function will be used as transorm call and actually sends the payload
function beaconRollbar(payload) {
// create blob to set content type to JSON - needed for correct HTTP header
const blob = new Blob([JSON.stringify(payload)], { type: 'application/json; charset=UTF-8' });
navigator.sendBeacon(`${window.Rollbar.options.endpoint}item/?post_client_item=${window.Rollbar.options.accessToken}`, blob);
}
/**
* Rollbar normal init code goes here
* const rollbarConfig = { .. }
@tinovyatkin
tinovyatkin / rollbarFetch.js
Last active Sep 22, 2016
Using fetch API as transport for Rollbar
View rollbarFetch.js
function fetchTransport(payload) {
fetch(`${window.Rollbar.options.endpoint}item/`, {
method: 'POST',
body: JSON.stringify(payload),
redirect: 'follow',
headers: new Headers({ 'Content-Type': 'application/json; charset=UTF-8',
'X-Rollbar-Access-Token': window.Rollbar.options.accessToken,
}),
})
.catch(err => console.error('Rollbar fetch transport failed', err));
@tinovyatkin
tinovyatkin / promisify-readline-question.js
Created Oct 29, 2017
`util.promisify` for `readline.question`
View promisify-readline-question.js
'use strict';
// Promisifies readline.question function using node native `util.promisify`
// readline.question takes one callback that returns the answer, so it need custom promisifying
const readline = require('readline');
const { promisify } = require('util');
readline.Interface.prototype.question[promisify.custom] = function(prompt) {
return new Promise(resolve =>
@tinovyatkin
tinovyatkin / rx-server.js
Created Sep 21, 2019 — forked from Gooseus/rx-server.js
RxJS HTTP Server
View rx-server.js
// Rx HTTP Server
// first attempt at creating a minimal reactive nodejs HTTP server
//
// has:
// * url/querystring parsing
// * body parsing
// * some kind of routing
// * some kind of error handling
// * minimalist request logging
//
@tinovyatkin
tinovyatkin / action.yml
Created Sep 27, 2019
Install Node.JS version pinned at `engines` in `package.json` on GitHub Actions Workflow
View action.yml
on:
push:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
steps:
@tinovyatkin
tinovyatkin / passkit-webservice-swagger.json
Created Dec 9, 2019 — forked from ckrack/passkit-webservice-swagger.json
Passkit Webservice Swagger for Apple Wallet Webservice
View passkit-webservice-swagger.json
{
"swagger": "2.0",
"info": {
"title": "Passkit Web Service",
"contact": {
"name": "Clemens Krack",
"email": "info@clemenskrack.com"
},
"version": "1.0.0"
},
View fibonacci-generator.js
function *fibonacci(n) {
const infinite = !n && n !== 0;
let current = 0;
let next = 1;
while (infinite || n--) {
yield current;
[current, next] = [next, current + next];
}
}
View keybase.md

Keybase proof

I hereby claim:

  • I am tinovyatkin on github.
  • I am tinovyatkin (https://keybase.io/tinovyatkin) on keybase.
  • I have a public key ASDz9s6IUsFRXMeL_pu1O83qQurHxM0mI8vUt2ahCIpZlQo

To claim this, I am signing this object:

View parse-headers.ts
const headers = `
Date: Sun, 17 Aug 2014 16:24:52 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Set-Cookie: Foo2
set-Cookie: bar
set-cookie: bong
`;
const s = headers.trim().split(/\s*\n\s*/g).map((v) => {
const [header, value] = v.split(/:\s*/, 2);
You can’t perform that action at this time.