Skip to content

Instantly share code, notes, and snippets.

@andrewconnell
andrewconnell / build.ts
Created August 10, 2016 17:09
Gulp Task for Building Project & Application TypeScript Code
import * as gulp from 'gulp';
import * as yargs from 'yargs';
import * as merge from 'merge2';
import { BaseGulpTask } from '../BaseGulpTask';
import { BuildConfig, ProjectArtifact, ProjectPaths, Utils } from '../buildBarrel';
import { gulpIf, gulpPlumber, gulpPrint, gulpSourcemaps, gulpTypeScript } from '../gulpPlugins';
/**
* Builds the project, then the application.
*
@askd
askd / test-preserve-3d.js
Last active May 19, 2017 08:01
Test transform-style: preserve-3d support
function testPreserve3DSupport() {
const element = document.createElement('p');
document.body.insertBefore(element, null);
const propName = 'transform-style';
element.style[propName] = 'preserve-3d';
const propValue = window.getComputedStyle(element, null).getPropertyValue(propName);
document.body.removeChild(element);
return (propValue === 'preserve-3d');
}
const server = http2.createSecureServer(options);
const commonCSS = fs.readFileSync('common.css');
server.on('stream', (stream, headers) => {
console.log(`${headers[':method']} ${headers[':path']}`);
const parsedUrl = url.parse(headers[':path']);
let pathname = `.${parsedUrl.pathname}`;
const ext = path.parse(pathname).ext;
if (headers[':path'] === '/index.html') {
stream.pushStream({ ':path': 'common.css' },
const http2 = require('http2');
const fs = require('fs');
const url = require('url');
const path = require('path');
const options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};
const mimeType = {
'.ico': 'image/x-icon',
const cacheName = 'v1';
this.addEventListener('install', function(event) {
event.waitUntil(
caches.open(cacheName).then(function(cache) {
return cache.addAll([
'index.html',
'common.css'
].map(u => new Request(u, { credentials: 'include' })))
}).then(()=> console.log('done'))
);
@Lakret
Lakret / gist:3825333
Created October 3, 2012 06:08
Quaternions
// Кватернионы — это гиперкомплексные числа, предложенные Гамильтоном в 1843 году.
// Кватернионы с операциями на них образуют алгебраическую структуру, называемую "телом" или "кольцом с делением" (division ring) ℍ.
// Такие алгебраические структуры отличаются от привычных нам полей (например, поля действительных чисел ℝ) тем,
// что умножение в них некоммутативно, т.е. для кватернионов справедливо a * b =/= b * a.
// Кватернионы очень удобны для записи вращений в трёхмерном пространстве, поэтому они нашли широкое применение в механике,
// 3D-графике и компьютерном зрении.
// В этом упражнении вы должны будете создать тип, представляющий кватернионы.
// Этот тип будет размеченным объединением, т.к. мы можем по-разному определить кватернионы.
@surma
surma / importPolyfill.js
Created May 6, 2017 17:17
Polyfill for dynamic module loading
_registry = {};
importPolyfill = path => {
if(!(path in _registry)) {
const entry = _registry[path] = {};
entry.promise = new Promise(resolve => entry.resolve = resolve);
document.head.appendChild(Object.assign(
document.createElement('script'),
{
type: 'module',
innerText: `import * as X from '${path}'; _registry['${path}'].resolve(X);`,
@bendc
bendc / personal-raf-boilerplate.js
Last active January 21, 2018 17:19
requestAnimationFrame boilerplate code
"use strict";
// animation utils
// ===============
const trackTime = timing => {
const now = performance.now();
if (!timing.startTime) timing.startTime = now;
const elapsed = now - timing.startTime;
@DimitryDushkin
DimitryDushkin / update-size-while-dragging.js
Last active March 4, 2018 17:48
Code from Yandex Zen narrative editor
type DraggerPosition = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
const computeGeometryWhileDragging = (
position: DraggerPosition,
preserveAspectRatio: boolean,
initialGeometry: SlideElementGeometry,
currentGeometry: SlideElementGeometry,
dx: number,
dy: number
): SlideElementGeometry => {
@obenjiro
obenjiro / css-methodologies-from-o-to-b.md
Last active February 5, 2019 11:36
CSS Методологии, от О до Б