Skip to content

Instantly share code, notes, and snippets.

monochromer

Block or report user

Report or block monochromer

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
@monochromer
monochromer / raf-queue.js
Last active Sep 19, 2019
Очередь задач с ограничением их числа выполнения
View raf-queue.js
class TaskQueue {
constructor() {
this.queue = [];
this.requestId = null;
}
addTask(task) {
this.queue.unshift(task);
}
@monochromer
monochromer / responsive-email-image.html
Last active Aug 16, 2019
responsive email html image
View responsive-email-image.html
<!--[if gte MSO 9]>
<table width="200"><tr><td>
<![endif]-->
<table align="center" width="100%" style="max-width: 200px;">
<tr>
<td align="center" style="text-align: center">
<img src="//link.com" alt="" width="200" height="140" style="display: block; border: 0; width: 100%; height: auto;">
</td>
</tr>
</table>
@monochromer
monochromer / createSplitStream.js
Last active Sep 19, 2019
node.js line number stream
View createSplitStream.js
// https://github.com/deanhume/streams
function createSplitStream(splitter) {
let buffer = '';
return new stream.Transform({
transform(chunk, encoding, next) {
buffer += chunk;
const parts = buffer.split(splitter);
parts.slice(0, -1).forEach(part => this.push(part));
@monochromer
monochromer / es6-proxy.md
Created Jun 19, 2019
A practical guide to Javascript Proxy (ES6 Proxy)
View es6-proxy.md
@monochromer
monochromer / future.js
Created May 16, 2019
Future: Асинхронность на фьючерах без состояния
View future.js
// © Timur Shemsedinov
// https://www.youtube.com/watch?v=22ONv3AGXdk
// https://github.com/HowProgrammingWorks/Future
class Future {
constructor(executor) {
this.executor = executor;
}
static of(value) {
@monochromer
monochromer / cluster.js
Created May 13, 2019
Node.js cluster demo
View cluster.js
const cluster = require('cluster');
const os = require('os');
const pid = process.pid;
const cpusCount = os.cpus().length;
if (cluster.isMaster) {
console.log(`CPUs: ${cpusCount}`);
console.log(`Master started. Pid: ${pid}`);
for (let i = 0; i < cpusCount - 1; i++) {
View html-include.html
<!-- HTML Includes That Work Today -->
<!-- https://www.filamentgroup.com/lab/html-includes/ -->
<iframe
src="signal.svg"
loading="lazy"
onload="this.before((this.contentDocument.body||this.contentDocument).children[0]);this.remove()"
></iframe>
View lazy-load-module.js
// https://habr.com/ru/post/443124/
const loadableModule = (loaderFunction) =>
class AsyncComponent extends React.Component {
state = {
ResultComponent: null,
error: false,
};
componentWillMount() {
loaderFunction
@monochromer
monochromer / css-network-performance.md
Created Feb 5, 2019
CSS и производительность сети
View css-network-performance.md

CSS и производительность

  1. Сritical Path CSS style в head

  2. Разделяйте свои медиавыражения по типам

<link rel="stylesheet" href="all.css"         media="all"                />
<link rel="stylesheet" href="small.css"       media="(min-width: 20em)"  />
<link rel="stylesheet" href="medium.css"      media="(min-width: 64em)"  />
View protect-nodejs-app.js
// https://blog.logrocket.com/how-to-protect-your-node-js-applications-from-malicious-dependencies-5f2e60ea08f9
const fs = require('fs')
const path = require('path')
const wrap = (module, name, wrapper) => {
const original = module[name]
module[name] = wrapper(original)
}
wrap(fs, 'readFileSync', (readFileSync) => (...args) => {
const [filepath] = args
You can’t perform that action at this time.