Skip to content

Instantly share code, notes, and snippets.

@x1unix
x1unix / libslack.sh
Last active October 23, 2017 12:26
Slack bash library
#!/usr/bin/env bash
#
# Slack Support Library (v1.0.0)
# System colors
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
RED='\033[0;31m'
NC='\033[0m'
@pomber
pomber / scheduler.js
Last active March 15, 2018 19:03
Using requestIdleFrame to schedule tasks
const ENOUGH_TIME = 1; // milliseconds
let workQueue = [];
let nextUnitOfWork = null;
function schedule(task) {
workQueue.push(task);
requestIdleCallback(performWork);
}
@treyhuffine
treyhuffine / PromiseSimple.js
Last active November 2, 2022 13:21
A simple JavaScript Promise implementation for education purposes
class PromiseSimple {
constructor(executionFunction) {
this.promiseChain = [];
this.handleError = () => {};
this.onResolve = this.onResolve.bind(this);
this.onReject = this.onReject.bind(this);
executionFunction(this.onResolve, this.onReject);
}
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'))
);
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',
@LeaVerou
LeaVerou / log-traps.js
Last active January 28, 2018 12:22
Log all proxy traps
function createLoggedProxy(obj) {
var traps = {};
for (let trap of Object.getOwnPropertyNames(Reflect)) {
traps[trap] = (...args) => {
console.log(trap, ...args.slice(0, -1)); // Last arg is always the proxy, no need to log it
return Reflect[trap](...args);
}
}
@akella
akella / setup.md
Last active December 26, 2025 12:03
Мой сетап

То что я использую в работе и стримах

Софт для разработки

@A-gambit
A-gambit / ReactiveConf2017.md
Last active June 19, 2021 16:57
Proposal for lightning talk at ReactiveConf 2017: How do you make friends with React and FRP? 🤔 Start to develop your application using Focal.

How do you make friends with React and FRP? 🤔 Start to develop your application using Focal.

This is a CFP for the ⚡️Lightning⚡️ talk at awesome ReactiveConf 2017. If you'd like to see this talk, please 🌟 star🌟 this summary and retweet my tweet 🙂 #ReactiveConf

image

Functional reactive programming (FRP) is very popular nowadays. The JavaScript community provides us with excellent tools like RxJS, Bacon, and Kefir. But, as we know, they have nothing to do with React. So how we can use the power of FRP in our React application? Using the correct state management, we can make friends with FRP and React and make our application truly reactive. In my lightning talk, I will talk about Focal

@twitchard
twitchard / loggingMw.js
Created June 8, 2017 04:44
Middleware that logs a request
app.use((req, res, next) => {
const begin = Date.now()
res.on('finish', () => console.log(
"method", req.method,
"url", req.url,
"took", Date.now() - begin
))
return next()
})